批量处理 — API 参考
单个请求,批量交付多个接收地址。
| 方法 | 路径 | 概览 |
|---|---|---|
GET | /v1/batches | 列出批次任务 |
POST | /v1/batches | 单次调用为多个接收方批量下单 |
GET | /v1/batches/{batchId} | 查询批次执行进度 |
POST | /v1/batches/{batchId}/cancel | 取消批次中尚未开始的项 |
基于 openapi.yaml 在构建时生成。基准 URL 为 https://api.tenergy.me/v1,Nile 测试网环境为 https://api-nile.tenergy.me/v1(详见环境说明)。下述每个请求均遵循身份鉴权规范进行签名,除非鉴权行另有说明。
列出批次任务
GET /v1/batches · listBatches
鉴权: API 密钥 (HMAC)。
请求参数
| 参数名 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
limit | query | integer | ||
cursor | query | string | 上次响应中 next_cursor 返回的不透明游标。 |
响应
| 状态码 | 含义 |
|---|---|
200 | OK |
401 | 缺少、格式错误或已被拒绝的凭据。 |
429 | 请求过于频繁。 |
500 | 服务端内部错误。 |
响应字段
| 字段 | 类型 | 必选 | 说明 |
|---|---|---|---|
data | array of object (Batch) | 是 | |
data[].id | string | 是 | |
data[].client_batch_id | string | null | ||
data[].status | enum: queued, processing, completed, partial, failed, cancelled | 是 | 批次状态。partial 表示部分接收地址成功交付而部分失败 —— 请检查 items,切勿假定全部成功或全部失败。 |
data[].items_accepted | integer | 是 | |
data[].summary | object | 是 | 各状态明细项统计。比拉取全部 items 更轻量。 |
data[].summary.total | integer | ||
data[].summary.queued | integer | ||
data[].summary.processing | integer | ||
data[].summary.completed | integer | ||
data[].summary.partial | integer | ||
data[].summary.failed | integer | ||
data[].summary.insufficient_funds | integer | ||
data[].summary.cancelled | integer | ||
data[].items | array of object (BatchItem) | 是 | |
data[].items[].receiver | string | 是 | Base58Check 编码的 TRON 地址(以 T 开头,34 个字符)。 |
data[].items[].tracking_id | string | 是 | <client_batch_id>:<receiver> —— 批次中每个接收方的唯一跟踪 ID。 |
data[].items[].status | enum: queued, processing, completed, partial, failed, insufficient_funds, cancelled | 是 | |
data[].items[].resource | enum: energy, bandwidth, activation | energy —— TRON 能量。· bandwidth —— TRON 带宽。· activation —— 账户激活。 | |
data[].items[].amount | integer | ||
data[].items[].tier | enum: 5m, 15m, 1h, 1d, 3d, 30d | 租赁周期。请通过 GET /v1/prices 实时获取。 | |
data[].items[].delivered_amount | integer | 实际完成质押交付的数量。 | |
data[].items[].order_ids | array of string | 为该接收方创建的底层订单 ID 列表。属于普通独立订单,可单独查询和提前回收。 | |
data[].items[].delegate_hashes | array of string | 链上质押交易哈希列表。 | |
data[].items[].charged_amount_sun | integer (int64) | 扣费金额(以 SUN 为单位,1 TRX = 1,000,000 SUN)。始终为整数。 | |
data[].items[].activation | object | ||
data[].items[].bandwidth | object | ||
data[].items[].attempts | integer | ||
data[].items[].started_at | string (date-time) | null | ||
data[].items[].finished_at | string (date-time) | null | ||
data[].items[].failure | null | object | ||
data[].created_at | string (date-time) | 是 | |
data[].finished_at | string (date-time) | null | ||
next_cursor | string | null | 是 |
单次调用为多个接收方批量下单
POST /v1/batches · createBatch
鉴权: API 密钥 (HMAC)。
单个请求支持最多 100 个接收地址。对于每个地址,平台会自动串联完整交付流程 —— 若地址未激活则自动激活,若带宽不足则补充带宽,随后执行资源交付(大额自动分笔切片)。
接口返回 202 Accepted:批次已入队排队,此时尚未扣款且未完成质押交付。可通过 GET /v1/batches/{id} 或各订单的 Webhook 回调获取执行结果。
单个接收方失败不会影响其他接收方,激活或带宽补充步骤失败也不会阻断能量订单的主交付。
每个接收方按其实际执行时刻的实时价格进行计费结算。可通过设置每项的 max_price_sun 控制单价上限。
每个接收方会生成对应的独立订单 ID。client_batch_id 作为整批任务的幂等键:相同 ID 和请求体将返回原始批次;相同 ID 但不同请求体将拒绝并返回 3010 idempotency_conflict。
请求参数
| 参数名 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
Idempotency-Key | header | string | 客户端指定的安全重试幂等键(8–128 个字符 A-Z a-z 0-9 . _ : -)。记录保留 24 小时。 |
请求体
JSON (BatchRequest),必填。
| 字段 | 类型 | 必选 | 说明 |
|---|---|---|---|
client_batch_id | string | 批次的自定义业务 ID 兼幂等键。若未提供 Idempotency-Key 请求头则此字段必填。 | |
defaults | object (BatchItemOptions) | 适用于批次中所有未单独覆盖对应字段的条目的默认配置。 | |
defaults.resource | enum: energy, bandwidth, activation | energy, bandwidth 或 activation。 | |
defaults.amount | integer | ||
defaults.tier | enum: 5m, 15m, 1h, 1d, 3d, 30d | 租赁周期。 | |
defaults.activate | boolean | ||
defaults.bandwidth | boolean | 在交付能量前,若接收方带宽不足则自动补充。 | |
defaults.bandwidth_amount | integer | 补充的带宽数量。 | |
defaults.max_price_sun | integer (int64) | 最高可接受单价(SUN)。 | |
defaults.client_order_id_prefix | string | 订单 ID 前缀,生成的订单 ID 为 "<prefix>-<receiver>",便于业务端对账。 | |
items | array of object | 是 | 接收方明细列表。同一批次中出现重复接收地址将返回 2006 duplicate_receiver。 |
items[].receiver | string | 是 | Base58Check 编码的 TRON 地址(以 T 开头,34 个字符)。 |
items[].resource | enum: energy, bandwidth, activation | ||
items[].amount | integer | ||
items[].tier | enum: 5m, 15m, 1h, 1d, 3d, 30d | ||
items[].activate | boolean | ||
items[].bandwidth | boolean | ||
items[].bandwidth_amount | integer | ||
items[].max_price_sun | integer (int64) | ||
items[].client_order_id_prefix | string |
来自规范的请求体示例(示意数值):
{
"client_batch_id": "acme-payout-2026-09-11-01",
"defaults": {
"resource": "energy",
"tier": "1h",
"amount": 65000,
"activate": true,
"bandwidth": true,
"bandwidth_amount": 400
},
"items": [
{"receiver":"TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE"},
{"receiver":"TXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","amount":131000},
{"receiver":"TYYyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy","bandwidth":false}
]
}
响应
| 状态码 | 含义 |
|---|---|
200 | 相同的 client_batch_id 与请求体 —— 返回已有的原批次。 |
202 | 批次已受理入队排队。尚未产生扣费。 |
400 | 格式错误的请求 —— 无效 JSON、未知字段或字段类型错误。 |
401 | 缺少、格式错误或已被拒绝的凭据。 |
402 | 账户余额不足以支付批次订单。 |
409 | 幂等冲突或对象状态冲突。 |
422 | 语法合法但逻辑上无法满足操作要求。 |
429 | 请求过于频繁。 |
500 | 服务端内部错误。 |
503 | 服务暂时不可用。 |
响应字段 (Batch)
| 字段 | 类型 | 必选 | 说明 |
|---|---|---|---|
id | string | 是 | |
client_batch_id | string | null | ||
status | enum: queued, processing, completed, partial, failed, cancelled | 是 | 批次执行状态。 |
items_accepted | integer | 是 | |
summary | object | 是 | 汇总统计信息。 |
summary.total | integer | ||
summary.queued | integer | ||
summary.processing | integer | ||
summary.completed | integer | ||
summary.partial | integer | ||
summary.failed | integer | ||
summary.insufficient_funds | integer | ||
summary.cancelled | integer | ||
items | array of object (BatchItem) | 是 | |
items[].receiver | string | 是 | Base58Check 编码的 TRON 地址(以 T 开头,34 个字符)。 |
items[].tracking_id | string | 是 | <client_batch_id>:<receiver>。 |
items[].status | enum: queued, processing, completed, partial, failed, insufficient_funds, cancelled | 是 | |
items[].resource | enum: energy, bandwidth, activation | ||
items[].amount | integer | ||
items[].tier | enum: 5m, 15m, 1h, 1d, 3d, 30d | ||
items[].delivered_amount | integer | ||
items[].order_ids | array of string | 生成的底层订单 ID 列表。 | |
items[].delegate_hashes | array of string | 链上质押交易哈希。 | |
items[].charged_amount_sun | integer (int64) | 实际扣费金额(SUN)。 | |
items[].activation | object | ||
items[].activation.status | enum: planned, not_needed, done, failed, skipped | ||
items[].activation.hash | string | null | ||
items[].bandwidth | object | ||
items[].bandwidth.status | enum: planned, enough, done, failed, skipped | ||
items[].bandwidth.order_id | string | null | ||
items[].bandwidth.skip_reason | enum: option_off, amount_large | null | ||
items[].attempts | integer | ||
items[].started_at | string (date-time) | null | ||
items[].finished_at | string (date-time) | null | ||
items[].failure | null | object | ||
items[].failure.code | integer | ||
items[].failure.slug | string | ||
items[].failure.message | string | ||
created_at | string (date-time) | 是 | |
finished_at | string (date-time) | null |
查询批次执行进度
GET /v1/batches/{batchId} · getBatch
鉴权: API 密钥 (HMAC)。
请求参数
| 参数名 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
batchId | path | string | 是 | 平台批次 ID (bat_…) 或 cid:<client_batch_id>。 |
receiver | query | string | 可选过滤条件,仅返回指定地址的单项状态而非整个批次。 |
响应
| 状态码 | 含义 |
|---|---|
200 | OK |
401 | 缺少、格式错误或已被拒绝的凭据。 |
404 | 目标对象不存在或属于其他账户。 |
429 | 请求过于频繁。 |
500 | 服务端内部错误。 |
响应字段 (Batch)
字段结构与 POST /v1/batches 响应中的字段相同。
取消批次中尚未开始的项
POST /v1/batches/{batchId}/cancel · cancelBatch
鉴权: API 密钥 (HMAC)。
从排队队列中移除所有尚未开始处理的接收项。不会中断已经在处理中的项。
请求参数
| 参数名 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
batchId | path | string | 是 |
响应
| 状态码 | 含义 |
|---|---|
200 | OK |
401 | 缺少、格式错误或已被拒绝的凭据。 |
404 | 目标对象不存在或属于其他账户。 |
429 | 请求过于频繁。 |
500 | 服务端内部错误。 |
响应字段
| 字段 | 类型 | 必选 | 说明 |
|---|---|---|---|
id | string | 是 | |
cancelled | integer | 是 | 从队列中成功移除的条目数量。 |