Buy Energy

To using this feature you must have API key. Read at here to know how to get our API key

Buy with API Key (Postman)

Create new buy energy order by API key

POST https://api.tronsave.io/v0/internal-buy-energy

Create new buy energy order by api-key

Rate limit: 1 request per 2 seconds

Headers

NameTypeDescription

apikey*

String

Tronsave api key that present for internal account

Request Body

NameTypeDescription

resource_type*

String

"ENERGY"

buy_energy_type*

String

-"FAST" : If market ready to fill = 100%, FAST = MEDIUM. If market 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 ready to fill = 0%, MEDIUM = SLOW + 10.

-"SLOW": The lowest price that can be set for this order.

-If price is number, price unit is equal to sun.

amount*

Number

Amount of resource want to buy

allow_partial_fill*

Boolean

if this value is true, order is able to filling from many delegator. Order can filling easier than if this value is false. Amount greater than 200k energy can set this params

target_address*

String

The address that received resource

duration_millisec

Number

order duration in milli sec. Default: 259200000 (3 days)

sponsor

String

sponsor code

only_create_when_fulfilled

Boolean

[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

Number

Only create order when the estimate price less than this value.

add_order_incomplete

Boolean

[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

return order id if success

{
    "order_id": string,
    "requester": string, // the address represent for order owner
    "target": string, // the address that is received resource 
    "resource_amount": number, // the amount of resource
    "resource_type": string, // the amount type is "ENERGY"
    "remain_amount": number, // the remain amount can matching by system
    "price": number, // price unit is equal to sun
    "duration": number, // rent duration, duration unit is equal to second
    "allow_partial_fill": boolean, //Allow the order to be filled partially or not
    "payout_amount": number, // Total payout of this order
    "fulfilled_percent": number, //The percent that show filling processing. 0-100
}

Example

{
    "resource_type": "ENERGY",
    "buy_energy_type": "FAST",
    "amount": 100000,
    "allow_partial_fill": true,
    "target_address": "TKVSaJQDWeKFSEXmA44pjxduGTxy999999",
    "duration_millisec":86400000, //Optional
    "sponsor": <YOUR SPONSOR REF CODE> //Optional
    "only_create_when_fulfilled": false,
    "max_price_accepted": 100,
    "add_order_incomplete": false
}

Example Code

const BuyEnergy = async (api_key, target_address, amount, duration_ms) => {
    const url = `https://api.tronsave.io/v0/internal-buy-energy`
    //see more at https://docs.tronsave.io/buy-energy-on-telegram/using-api-key-to/buy-energy
    const body = {
        "resource_type": "ENERGY",
        "buy_energy_type": "MEDIUM", //price in sun or "SLOW"|"MEDIUM"|"FAST"
        "amount": amount, //Amount of resource want to buy
        "allow_partial_fill": true,
        "target_address": target_address,
        "duration_millisec": duration_ms, //order duration in milli sec. Default: 259200000 (3 days)
        "only_create_when_fulfilled": false,
        "max_price_accepted": 100,
        "add_order_incomplete": false
    }
    const data = await fetch(url, {
        method: "POST",
        headers: {
            'apikey': api_key,
            "content-type": "application/json",
        },
        body: JSON.stringify(body)
    })
    const response = await data.json()
    /**
     * Example response 
     * @link  https://docs.tronsave.io/buy-energy-on-telegram/using-api-key-to/buy-energy
   {
      "order_id": "651d2306e55c073f6ca0992e",
      "requester": "TKVSaJQDWeKFSEXmA44pjxduGTxy999999",
      "target": "TKVSaJQDWeKFSEXmA44pjxduGTxy999999",
      "resource_amount": 100000,
      "resource_type": "ENERGY",
      "remain_amount": 0,
      "price": 67.5,
      "duration": 3600,
      "allow_partial_fill": true,
      "payout_amount": 6750000,
      "fulfilled_percent": 100
}
     */
    return response
}

Last updated