跳到主要内容
版本:0.1.0

TRONAgg API

什么是 TRONAgg API?​

TRONAgg API 让你以 TRONAgg 的价格自动购买波场(TRON)能量。你的应用可以通过一个简单的 REST API 获取报价、购买能量并跟踪订单。带宽也可以用同样的方式租用:在 GET /estimate 和 POST /buy 中设置 resource_type=BANDWIDTH。

基础 URL​

https://tronagg.ai/api/v1

所有端点都以此基础 URL 为前缀。

认证​

每个请求都需要在 X-API-Key 请求头中携带 API 密钥——标记为 public-api 的端点(价格与能量估算)除外,它们无需密钥。可在 TRONAgg 工作台 的 API 密钥 中创建。

curl -H "X-API-Key: ta_your_key_here" https://tronagg.ai/api/v1/account

关于密钥管理、安全最佳实践和错误处理,请参阅身份验证指南。

端点概览​

核心购买流程及其历史记录:

端点方法说明
/accountGET查看你的 TRX 与 USDT 余额、充值地址和绑定的钱包
/estimateGET在购买前获取价格报价
/buyPOST为接收地址购买能量
/order/{id}GET跟踪订单状态并获取委托交易 ID
/ordersGET列出你的订单,最新的在前
/transactionsGET你的余额账本:购买、充值、退款、手续费
/depositsGET转入你的 TRONAgg 充值地址的 TRX 与 USDT(TRC-20)转账

该 API 还涵盖 Webhook(以推送代替轮询)、AutoEnergy 订阅、Energy Agent 以及 TRONAgg Radar 地址监控;所有端点请见侧边栏。

准备好发出第一个调用了吗?请按照快速开始逐步操作,或前往代码示例获取可直接复制的 Python 和 JavaScript 代码片段。

为账户充值​

购买从你的 TRX 余额中支付。向 GET /account 返回的 deposit_address 发送 TRX 或 USDT(TRC-20) 即可充值——同一个地址两者都能接收。只认官方 USDT 合约;发送到该地址的其他代币不会入账。

  • USDT 会计入独立的 USDT 余额(usdt_balance)。USDT 最低充值为 5 USDT;低于此金额的转账会在 GET /deposits 中记录为 below_minimum,不会入账。
  • USDT 默认到账后自动兑换为 TRX,收取 1% 手续费,汇率在兑换时锁定。你可以关闭自动兑换,在工作台 → 充值中手动兑换。
  • 开启 TRX 不足时用 USDT 支付(默认开启)时,如果 TRX 余额不足以支付一笔购买,会先兑换恰好够用的 USDT。
  • API 可以读取 USDT 余额和这两项设置(usdt_auto_convert、usdt_cover_shortfall)。API 密钥不能兑换 USDT,也不能更改 USDT 设置;账户开启相应设置时,用该密钥发起的购买会用 USDT 补足 TRX 差额。

错误代码​

代码说明
400请求错误——请检查你的参数。包括 insufficient_balance:请用 TRX 或 USDT 为你的账户充值
401未授权——API 密钥无效或缺失
403禁止访问——账户已被封禁,或请求的来源 IP 不在该密钥的白名单内(ip_not_allowed)
404资源不存在
409冲突——例如 duplicate_request:具有相同 Idempotency-Key 的购买仍在处理中
422校验错误——具体信息见 detail 字段
429超出速率限制——请等待 Retry-After 响应头给出的秒数
500服务器错误——请重试或联系客服
502依赖的操作失败(例如能量估算模拟)——请稍后重试
503暂时不可用——请稍后重试

所有 error 代码、响应结构和幂等性规则,请见错误与约定。

速率限制​

每个账户每分钟最多可发出 1,000 个请求,由该账户的所有 API 密钥与已登录的工作台会话共用。超出后你会收到 429 Too Many Requests 以及 Retry-After 响应头——等待该秒数后再重试。公开端点则按 IP 限流;详见各端点说明。

用 AI 编程助手集成​

与其手写客户端,不如把整个集成交给 AI 编程助手。把下面的提示词粘贴到 Claude、Cursor 或 ChatGPT——它包含了助手构建可用集成所需的一切(基础 URL、X-API-Key 认证、SUN 单位以及各端点)。

You are integrating the TRONAgg REST API to buy TRON Energy programmatically.

- Base URL: https://tronagg.ai/api/v1
- Auth: send my API key in an `X-API-Key` header on every request (keep it in an env var, never hardcode).
- Units: integer amounts are in SUN (1 TRX = 1,000,000 SUN); `*_trx` amounts and `unit_price_sun` are JSON strings — parse with a decimal type.

Core flow:
- GET /account — my TRX balance, deposit address (accepts TRX and USDT TRC-20) and separate USDT balance. Purchases are paid in TRX; USDT converts to TRX automatically by default (1% fee).
- GET /estimate?resource_amount=<energy>&receiver_address=<T...> — a price quote incl. any one-time activation fee for the receiver, plus min_amount/max_amount order limits (null = no limit).
- POST /buy — JSON body {"receiver_address": "T...", "resource_amount": <energy>}. Always send a unique Idempotency-Key header; on timeout retry with the SAME key — it returns the original order instead of charging twice. If the same key keeps returning 409 duplicate_request, check GET /orders before retrying with a NEW key.
- GET /order/{id} — poll every 2-3s until status is "COMPLETED" or "FAILED" (statuses are UPPERCASE). FAILED orders are auto-refunded.

History & webhooks (optional):
- GET /orders, GET /transactions, GET /deposits — order history, balance ledger, deposit history (deposits: TRX and USDT transfers to your deposit address — asset + amount per row, USDT rows have amount_sun 0; credited_at = spendable, verified_at = reorg-safe).
- POST /webhooks {"name", "url"} — push instead of polling; store the signing_secret from the response (shown once) and verify HMAC-SHA256 over "{timestamp}.{raw_body}" from the X-TronAgg-Signature header.

Errors arrive as {"detail": {"error": "<code>", ...}} — handle insufficient_balance and duplicate_request (409) gracefully. Exceptions: order-amount limits use detail.code (with min/max); 401, 429 and the order 404 have a plain-string detail; request-validation 422s have a detail array.

Build a small typed client that estimates the cost, buys Energy for a receiver, then polls the order until it reaches a terminal status.

完全不想写代码?同样的操作也以 MCP 服务器的形式提供——直接连接你的助手,让它把 TRONAgg 当作工具调用,无需编写集成。参见从 AI 智能体使用 TRONAgg(MCP)。

认证​

从你的 TRONAgg 工作台 的 API 密钥 中获取 API 密钥。密钥格式为 ta_...,每个请求都必须在 X-API-Key 请求头中携带。请妥善保管你的密钥——一旦泄露,请立即撤销并创建一个新密钥。

安全方案类型:

apiKey

请求头参数名:

X-API-Key