Buy on Rest API
Step 1: Get estimate TRX
API Method: Post
Request params
amount
body
number
true
The number of resources
buy_energy_type
body
string, number
true
"FAST", "MEDIUM", "SLOW" or number
duration_millisec
body
number
true
The duration of the bought resource, time unit is equal to millisecond.
request_address
body
string
false
The address of requester.
target_address
body
string
false
The address of receiver resource.
is_partial
body
boolean
false
Allow the order to be filled partially or not.
Request params example
Responses
unit_price
number
true
price in SUN of energy that fit with your buy_energy_type
duration_millisec
number
true
available_energy
number
true
total amount available ernery on Tronsave market that match with unit_price
estimate_trx
number
true
estimate total trx value will pay for buy all available_energy
with price is unit_price
in duration_millisec
Step 2: Get Signed Transaction
After Step 1 you will get a estimate_trx
is the cost of buy order. Then you will using transactionBuilder
to create a transfer transaction with amount transfer equal estimate_trx
from buyer's address to fund of Tronsave market:
change
BUYER_ADDRESS
is the buyer's public addresschange
PRIVATE_KEY
is buyer's private keychange
TRONSAVE_FUND_ADDRESS
is our Tronsave fund address on mainnet
Our Tronsave fund address is
Step 3: Create order
API Method: Post
Request params
resource_type
body
string
true
"ENERGY"
unit_price
body
number
true
Price unit is equal to sun.
allow_partial_fill
body
boolean
true
Allow the order to be filled partially or not
target_address
body
string
true
Resource receiving address
duration_millisec
body
number
true
The duration of the bought resource, time unit is equal to millisec.
tx_id
body
string
true
Transaction ID
signed_tx
body
SignedTransaction
true
Signed transaction, Note that it is a json object (signed_tx in Step 2)
only_create_when_fulfilled
body
Boolean
false
[true]=> order only create when it can be fulfilled
[false] => order will create even it can not be fulfilled
Default value: false
max_price_accepted
body
Number
false
Only create order when the estimate price less than this value.
add_order_incomplete
body
Boolean
false
[true]=> order only create when there has no same parameters order is not complete in order list
[false] => order will create even there has no same parameters order is not complete in order list
Default value: false
Request params example
Responses
Code demo
Last updated