Tronsave
🇬🇧 English
🇬🇧 English
  • 📗INTRODUCTION
    • What is Tronsave ?
    • Why Tronsave?
  • Buyer
    • How to buy Energy ?
      • Buy on the Website
      • Buy on Telegram
        • 1. Create a Tronsave telegram account
        • 2. How To Deposit TRX
        • 3. Get the Tronsave API Key
        • 4. How to buy on Telegram
    • Extend
      • Quick extend
      • Advance
  • 🏬Seller
    • Get Energy by Staking 2.0
    • Permission
    • Sell Energy
      • Manual Sell
      • Auto Sell
      • Sell Suggestion
  • DEVELOPER
    • Get API key
      • On the Website
      • On Telegram
    • Buy Resources (v2)
      • Use Signed Transaction
        • Estimate TRX
        • Get Signed Transaction
        • Create order
      • Use API Key
        • Get Internal Account Info
        • Get Order Book
        • Estimate TRX
        • Create order
        • Get one order details
        • Get Internal Account Order History
    • Extend Orders (v2)
      • Step 1: Get Extendable Delegates
      • Step 2: Extend Request
    • Rest API v0
      • Buy on Rest API
        • Use Signed Transaction
          • Estimate TRX
          • Get Signed Transaction
          • Create order
          • Demo
        • Use API Key
          • Get Internal Account Info
          • Get Order Book
          • Estimate of TRX
          • Create order
          • Get one order details
          • Get Internal Account Order History
      • Extend with Rest API
  • 🤝Referrer
    • Referrals
  • 💡FAQ
    • Questions for Energy market
    • Calculate APY in TronSave
    • How to connect wallet in Tronsave?
    • Team of Service
  • 👨‍💻Full Code Example
    • Code Example (v2)
      • Buy Resource by API using private key
      • Buy Resources by API using api key
      • Extend order by API using api key
      • Extend order by API using private key
    • Code Example (v0)
      • Buy energy by API using private key
      • Buy energy by API using api key
      • Extend order by API using api key
Powered by GitBook
On this page
  1. DEVELOPER
  2. Rest API v0
  3. Buy on Rest API
  4. Use API Key

Create order

PreviousEstimate of TRXNextGet one order details

Last updated 1 day ago

To use this feature, you must have the API key. Read to view how to get our API key

Create a new buy energy order by API key

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

Create a new buy energy order by

Rate limit: 15 requests per 1 second

Headers

Name
Type
Description

apikey*

String

Tronsave api key that present for internal account

Request Body

Name
Type
Description

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 an order when the estimated price is 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 the order id if successful

{
    "order_id": string,
    "requester": string, // the address represents the order owner
    "target": string, // the address of the resource that is received 
    "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
}
{
    "MISSING_PARAMS": "Missing some params in body",
    "INVALID_PARAMS": "some params is invalid",
    "ORDER_BUY_ENERGY_AMOUNT_TOO_SMALL": "order amount too small. Cannot less than 40000",
    "CANNOT_SET_PARTIAL_FULFILLED":"order amount less than 100000 cannot set partial fulfilled",
    "INTERNAL_ACCOUNT_NOT_FOUND":"internal account not exists",
    "ORDER_BUY_ENERGY_CAN_NOT_CREATE":"Something error occurs when create order, cannot create, please try later",
    "INTERNAL_BALANCE_ACCOUNT_TOO_LOW":"Balance is not enough"
}
{
    "API_KEY_REQUIRED": "Missing api key in headers",
    "INVALID_API_KEY":"api key not correct"
}
{
    "RATE_LIMIT": "Rate limit reached",
}

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
}
{
  "apikey": <YOUR_API_KEY>
}
{
      "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
}

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
}
curl --location 'https://api.tronsave.io/v0/internal-buy-energy' \
--header 'apikey: {{apikey}}' \
--data '{
    "resource_type": "ENERGY",
    "amount": 40000,
    "buy_energy_type": "MEDIUM", 
    "duration_millisec": 3600000, 
    "target_address": "{{yourAddress}}", 
    "allow_partial_fill": false, 
    "only_create_when_fulfilled": false,
    "max_price_accepted": 100,
    "add_order_incomplete": false
}
'

Get detailed orders here

here
Buy with API Key (Postman)
API key