购买能源
要使用此功能,您必须拥有API密钥。请在此处了解如何获取我们的API密钥
通过API密钥创建新的购买能源订单
POST
https://api.tronsave.io/v0/internal-buy-energy
通过API密钥创建新的购买能源订单
速率限制 (Rate limit): 每2秒1个请求。
Headers
Request Body
如果成功,返回订单ID。
{
"order_id": string,
"requester": string, // 表示订单拥有者的地址
"target": string, // 接收资源的地址
"resource_amount": number, // 资源数量
"resource_type": string, // 资源类型是 "ENERGY"
"remain_amount": number, // 系统可匹配的剩余数量
"price": number, // 价格单位为 sun
"duration": number, // 租赁时长,时长单位为秒
"allow_partial_fill": boolean, // 是否允许部分完成订单
"payout_amount": number, // 该订单的总支付金额
"fulfilled_percent": number, // 显示订单完成进度的百分比,0-100
}
{
"MISSING_PARAMS": "在请求体中缺少一些参数",
"INVALID_PARAMS": "一些参数无效",
"ORDER_BUY_ENERGY_AMOUNT_TOO_SMALL": "订单金额太小,不得少于40000",
"CANNOT_SET_PARTIAL_FULFILLED": "订单金额小于100000时无法设置部分完成",
"INTERNAL_ACCOUNT_NOT_FOUND": "内部帐户不存在",
"ORDER_BUY_ENERGY_CAN_NOT_CREATE": "创建订单时出现错误,无法创建,请稍后再试",
"INTERNAL_BALANCE_ACCOUNT_TOO_LOW": "余额不足"
}
{
"API_KEY_REQUIRED": "请求头中缺少API密钥",
"INVALID_API_KEY": "API密钥不正确"
}
{
"RATE_LIMIT": "已达到速率限制"
}
例子 (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
}
'
Last updated