价格计算
POST /v1/orders/calculate
返回假设订单的精确 TRX 价格,不会实际创建订单。在用户确认充值前,可使用此接口向用户展示费用。
这是一个纯定价接口——不会与 TRON 网络交互。
请求体
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
duration | integer | 是 | 资源租用时长(小时)。必须为 1。 |
activation | boolean | 否 | 若为 true,在 total 中包含账户激活费用。默认为 false。 |
resources.energy | integer | 否* | 要交付的能量数量。 |
resources.bandwidth | integer | 否* | 要交付的带宽数量。 |
* resources.energy 和 resources.bandwidth 中至少有一个必须大于零。
示例
bash
curl -X POST https://api.tronzap.com/v1/orders/calculate \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"duration": 1,
"activation": false,
"resources": {
"energy": 65000,
"bandwidth": 345
}
}'javascript
const response = await fetch('https://api.tronzap.com/v1/orders/calculate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
duration: 1,
activation: false,
resources: { energy: 65000, bandwidth: 345 },
}),
})
const data = await response.json()
console.log(data.result.total, data.result.currency)php
$response = file_get_contents('https://api.tronzap.com/v1/orders/calculate', false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => "Content-Type: application/json\r\nAccept: application/json",
'content' => json_encode([
'duration' => 1,
'activation' => false,
'resources' => ['energy' => 65000, 'bandwidth' => 345],
]),
],
]));
$data = json_decode($response, true);
echo $data['result']['total'] . ' ' . $data['result']['currency'];python
import requests
resp = requests.post('https://api.tronzap.com/v1/orders/calculate', json={
'duration': 1,
'activation': False,
'resources': {'energy': 65000, 'bandwidth': 345},
})
result = resp.json()['result']
print(result['total'], result['currency'])响应
json
{
"code": 0,
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"result": {
"energy": { "amount": 65000, "price": 2.34 },
"bandwidth": { "amount": 345, "price": 0.35 },
"activation": { "required": false, "price": 0 },
"total": 2.69,
"currency": "TRX",
"duration": 1
}
}当 activation: true 时(激活新账户):
json
{
"code": 0,
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"result": {
"energy": { "amount": 65000, "price": 2.34 },
"bandwidth": { "amount": 345, "price": 0.35 },
"activation": { "required": true, "price": 1.40 },
"total": 4.09,
"currency": "TRX",
"duration": 1
}
}响应字段
| 字段 | 类型 | 描述 |
|---|---|---|
energy.amount | integer | 请求的能量数量的回显。 |
energy.price | number | 能量所需的 TRX 费用。 |
bandwidth.amount | integer | 请求的带宽数量的回显。 |
bandwidth.price | number | 带宽所需的 TRX 费用。 |
activation.required | boolean | 您发送的 activation 标志的回显。 |
activation.price | number | 激活所需的 TRX 费用。未请求激活时为 0。 |
total | number | 能量 + 带宽 + 激活费用的总和。 |
currency | string | 始终为 TRX。 |
duration | integer | 请求的时长的回显。 |
total 与创建订单的 amount 一致
在相同输入且 activation 结果匹配的情况下,本接口返回的 total 与 POST /v1/orders 所需的 amount 相等。
