Create order
To use this feature, you must have the API key. Read here to view how to get our API key
Create a new order by API key
POST
https://api.tronsave.io/v2/buy-resource
Create a new buy energy order by API key
Rate limit: 15 requests per 1 second
Headers
apikey*
String
Tronsave api key that present for internal account
Request Body
resourceType
String
"ENERGY" or "BANDWIDTH", default: ENERGY
unitPrice
Number, String
"FAST", "MEDIUM", "SLOW", or a number. Default: "MEDIUM"
-"FAST": If the market is ready to fill = 100%, FAST = MEDIUM. If the market is ready to fill < 100%, FAST = MEDIUM + 10. If market ready to fill = 0%, FAST = SLOW + 20.
-"MEDIUM": The lowest price for the maximum market fill for this order. If market is ready to fill = 0%, MEDIUM = SLOW + 10.
-"SLOW": The lowest price that can be set for this order.
-If the price is a number, the price unit is equal to SUN
resourceAmount*
Number
The number of resources.
receiver*
String
Resource receiving address
durationSec
Number
The duration of the bought resource, time unit, is in seconds. Default: 259200 (3 days).
sponsor
String
sponsor code
options
Object
optional
options.allowPartialFill
Boolean
Allow the order to be filled partially or not
options.onlyCreateWhenFulfilled
Boolean
[true]=> order only creates when it can be fulfilled
[false]=> order will create even if it can not be fulfilled
Default value: false
options.maxPriceAccepted
Number
Only create order when the estimate price less than this value.
options.preventDuplicateIncompleteOrders
Boolean
[true]=> Only create if no uncompleted order with the same parameters exists.
[false]=> Always create a new order, regardless of existing unfinished ones.
Default value: false
options.minResourceDelegateRequiredAmount
Number
The minimum resource amount delegated by a single provider.
Return the order ID if successful
{
"error": false,
"message": "Success",
"data": {
"orderId": "6818426a65fa8ea36d119d2c"
}
}
Example
{
"resourceType": "ENERGY",
"receiver": "TFFbwz3UpmgaPT4UudwsxbiJf63t777777",
"durationSec": 3600,
"resourceAmount": 32000,
"unitPrice": "MEDIUM",
"options": {
"allowPartialFill": true,
"onlyCreateWhenFulfilled": true,
"preventDuplicateIncompleteOrders": false,
"maxPriceAccepted": 100,
"minResourceDelegateRequiredAmount": 100000
}
}
Example Code
const BuyResource = async (apiKey, receiverAddress, resourceAmount, durationSec, maxPriceAccepted) => {
const url = `${TRONSAVE_API_URL}/v2/buy-resource`
const body = {
resourceType: RESOURCE_TYPE,
unitPrice: "MEDIUM", //price in sun or "SLOW"|"MEDIUM"|"FAST"
resourceAmount, //Amount of resource wanted to buy
receiver: receiverAddress,
durationSec, //order duration in sec. Default: 259200 (3 days)
options: {
allowPartialFill: true,
onlyCreateWhenFulfilled: false,
maxPriceAccepted,
}
}
const data = await fetch(url, {
method: "POST",
headers: {
'apikey': apiKey,
"content-type": "application/json",
},
body: JSON.stringify(body)
})
const response = await data.json()
/**
* Example response
* {
* "error": false,
* "message": "Success",
* "data": {
* "orderId": "6809fdb7b9...a41d726fd"
* }
* }
*/
return response
}
Get detailed orders here
Last updated