Skip to content

价格计算

POST /v1/orders/calculate

返回假设订单的精确 TRX 价格,不会实际创建订单。在用户确认充值前,可使用此接口向用户展示费用。

这是一个纯定价接口——不会与 TRON 网络交互。

请求体

字段类型必填描述
durationinteger资源租用时长(小时)。必须为 1
activationboolean若为 true,在 total 中包含账户激活费用。默认为 false
resources.energyinteger否*要交付的能量数量。
resources.bandwidthinteger否*要交付的带宽数量。

* resources.energyresources.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.amountinteger请求的能量数量的回显。
energy.pricenumber能量所需的 TRX 费用。
bandwidth.amountinteger请求的带宽数量的回显。
bandwidth.pricenumber带宽所需的 TRX 费用。
activation.requiredboolean您发送的 activation 标志的回显。
activation.pricenumber激活所需的 TRX 费用。未请求激活时为 0
totalnumber能量 + 带宽 + 激活费用的总和。
currencystring始终为 TRX
durationinteger请求的时长的回显。

total 与创建订单的 amount 一致

在相同输入且 activation 结果匹配的情况下,本接口返回的 totalPOST /v1/orders 所需的 amount 相等。

TronZap Partner Documentation