TRON 能量 API 参考文档
v6bdb00b5b213 · 2026-11-23GetGas Energy API
从您的 GetGas 余额为任意地址购买 TRON 能量和带宽(一次性或自动),让 USDT 转账的成本只占原本需要燃烧的 TRX 的一小部分。请求和响应均为 JSON;金额是以 sun 为单位的整数(1 TRX = 1,000,000 sun),每个金额旁附有精确的 TRX 字符串。Base URL
https://getgas.io/api/v1授权Bearer Token
创建账户,然后在后台的 API & Keys 页面创建密钥。 以 Authorization: Bearer <key> 的形式发送密钥,并将其保存在您的服务器上,切勿放在浏览器代码中。限制:每个密钥每分钟 120 个请求,每个账户每分钟 30 笔新订单。授权
Authorization: Bearer <您的 API 密钥>账户
GET 获取账户
GET
余额、用于充值的充值地址,以及该账户的价格。https://getgas.io/api/v1/account充值地址是固定的,归该账户所有:向其发送 TRX 或 USDT(TRC-20),付款确认后余额即入账,通常在几分钟内。轮询此接口或 GET /deposits 可查看到账情况。
授权Bearer Token · 您的 API 密钥
响应
200 OK —
{"data": Account}请求示例
curl "https://getgas.io/api/v1/account" \
-H "Authorization: Bearer $GETGAS_API_KEY"响应示例 · 200 OK
{
"data": {
"email": "you@example.com",
"balanceSun": 1275000,
"balanceTrx": "1.275",
"depositAddress": "TDeposit...address...",
"depositNetwork": "TRC20",
"depositCurrencies": [
"TRX",
"USDT-TRC20"
],
"rates": {}
}
}GET 充值列表
GET
充值地址收到的付款,按从新到旧排列。https://getgas.io/api/v1/deposits包括仍在确认中的付款(creditedAt 为 null)。
授权Bearer Token · 您的 API 密钥
查询参数
limit | 1–100,默认 25。 |
offset | 要跳过的条目数,默认 0。 |
响应
200 OK —
{"data": [Deposit, ...]}请求示例
curl "https://getgas.io/api/v1/deposits?limit=10" \
-H "Authorization: Bearer $GETGAS_API_KEY"响应示例 · 200 OK
{
"data": [
{
"id": 123,
"transactionId": "a3f1…9c2e",
"currency": "TRX",
"amount": "25",
"netAmount": "25",
"creditedSun": 1275000,
"status": "active",
"receivedAt": "2026-10-05T12:00:00.000Z",
"creditedAt": null
}
]
}价格
GET 获取价格
GET
当前价格和订单限制。https://getgas.io/api/v1/prices无需 API 密钥。价格跟随提供商的价格,每隔几分钟刷新一次,因此请在向用户报价前读取。费率以每单位 sun 计;订单费用为 volume × 费率 + orderFeeSun(每笔订单的固定费用)。拥有自己费率的账户可在 GET /account 中看到其费率。
授权无需授权
响应
200 OK —
{"data": {"currency": "TRX", "updatedAt", "energy": {"minVolume", "maxVolume", "terms": [{"term", "label", "sunPerUnit"}]}, "bandwidth": {"minVolume", "maxVolume", "sunPerUnit"}, "orderFeeSun", "smartDeliverySun", "activationSun", "usdtTransfer": {"energyToHolder", "energyToNewHolder"}}}请求示例
curl "https://getgas.io/api/v1/prices"响应示例 · 200 OK
{"data": {"currency": "TRX", "updatedAt", "energy": {"minVolume", "maxVolume", "terms": [{"term", "label", "sunPerUnit"}]}, "bandwidth": {"minVolume", "maxVolume", "sunPerUnit"}, "orderFeeSun", "smartDeliverySun", "activationSun", "usdtTransfer": {"energyToHolder", "energyToNewHolder"}}}GET GET /prices/history
GET
1 小时能量价格的历史走势。https://getgas.io/api/v1/prices/history无需 API 密钥。1 小时能量的通用价格,按从旧到新排列。默认(interval=1h)为后台价格图表所绘制的每小时序列:每小时开始时的价格,缺口沿用前值,一小时内的异常波动经过平滑。使用 interval=15m 时,为定价页面图表所绘制的、按记录原样返回的每 15 分钟数据点(不平滑,也不沿用前值填补缺口)。与 GET /prices 一样,价格包含任何加价。记录可追溯 30 天,因此更长的周期只返回现有的 30 天,较新的历史可能很短甚至为空。拥有自己费率的账户价格不同:见 GET /account。
授权无需授权
查询参数
days | 1–30,默认 7。 |
interval | 1h(默认)或 15m。 |
响应
200 OK —
{"data": {"term": "1h", "interval": "1h" | "15m", "days", "points": [{"at", "sunPerUnit"}]}}。at 是 ISO 8601 时间戳,sunPerUnit 是每单位能量的 sun 价格。请求示例
curl "https://getgas.io/api/v1/prices/history?days=7&interval=15m"响应示例 · 200 OK
{"data": {"term": "1h", "interval": "1h" | "15m", "days", "points": [{"at", "sunPerUnit"}]}}订单
POST 创建订单
POST
为任意 TRON 地址购买能量或带宽,从余额支付。https://getgas.io/api/v1/orders订单被接受时扣除价格。响应即为该订单:"submitted" 表示正在处理中,通常在一分钟内变为 filled;请轮询 GET /orders/{id},直到状态为终态。如果网络拒绝,订单会以 "refunded" 返回,款项已退回余额。使用同一个 Idempotency-Key 重试永远不会重复购买:它会返回第一笔订单。
授权Bearer Token · 您的 API 密钥
请求头
Idempotency-Key | 必填。每次购买一个唯一的字符串(8–64 个 A–Z a–z 0–9 - _ 字符),例如 UUID。重试同一次购买时复用它;新的购买请使用新的字符串。 |
请求体 · raw (json)
resourcestring | "energy"(默认)或 "bandwidth"。带宽:每笔订单 1,000–100,000;一笔普通转账大约需要 350。 |
addressstring · 必填 | 接收能量的 TRON 地址(以 T 开头,34 个字符)。不必是您自己的地址。 |
volumeinteger · 必填 | 资源数量。能量:65,000–5,000,000。向已持有 USDT 的地址进行一笔 USDT 转账大约需要 65,000;向未持有 USDT 的地址转账大约需要 131,000。 |
termstring · 必填 | 资源保持代理的时长:"15m" 或 "1h"。 |
响应
201 Created — 新订单返回
{"data": Order}。200 OK — 该 Idempotency-Key 已用于同一订单时返回 {"data": Order}。请求示例
curl -X POST "https://getgas.io/api/v1/orders" \
-H "Authorization: Bearer $GETGAS_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"address": "TXYZ...your-address...", "volume": 65000, "term": "1h"}'响应示例 · 201 Created
{
"data": {
"id": 123,
"status": "submitted",
"resource": "energy",
"address": "TXYZ...your-address...",
"volume": 65000,
"term": "1h",
"priceSun": 2730000,
"priceTrx": "2.73",
"txId": "5c1e...",
"createdAt": "2026-09-29T10:00:00.000Z",
"updatedAt": "2026-09-29T10:00:01.000Z"
}
}GET 订单列表
GET
该账户的订单,按从新到旧排列。https://getgas.io/api/v1/orders包括在网站上下的订单。
授权Bearer Token · 您的 API 密钥
查询参数
limit | 1–100,默认 25。 |
offset | 要跳过的条目数,默认 0。 |
响应
200 OK —
{"data": [Order, ...]}请求示例
curl "https://getgas.io/api/v1/orders?limit=10" \
-H "Authorization: Bearer $GETGAS_API_KEY"响应示例 · 200 OK
{
"data": [
{
"id": 123,
"status": "submitted",
"resource": "energy",
"address": "TXYZ...your-address...",
"volume": 65000,
"term": "1h",
"priceSun": 2730000,
"priceTrx": "2.73",
"txId": "5c1e...",
"createdAt": "2026-09-29T10:00:00.000Z",
"updatedAt": "2026-09-29T10:00:01.000Z"
}
]
}GET 获取订单
GET
单笔订单及其当前状态。https://getgas.io/api/v1/orders/{id}当订单处于 "submitted" 时,会向网络核实交付情况,因此轮询此接口正是订单变为 "filled" 的方式。请每隔几秒轮询一次,不要更快。
授权Bearer Token · 您的 API 密钥
响应
200 OK —
{"data": Order}请求示例
curl "https://getgas.io/api/v1/orders/123" \
-H "Authorization: Bearer $GETGAS_API_KEY"响应示例 · 200 OK
{
"data": {
"id": 123,
"status": "submitted",
"resource": "energy",
"address": "TXYZ...your-address...",
"volume": 65000,
"term": "1h",
"priceSun": 2730000,
"priceTrx": "2.73",
"txId": "5c1e...",
"createdAt": "2026-09-29T10:00:00.000Z",
"updatedAt": "2026-09-29T10:00:01.000Z"
}
}地址
GET 检查地址
GET
地址是否已在链上存在,以及激活它的费用。https://getgas.io/api/v1/addresses/{address}从未接收过任何东西的全新地址尚未在链上存在,资源无法代理给它。为以前未使用过的地址购买前,请先检查。
授权Bearer Token · 您的 API 密钥
响应
200 OK —
{"data": AddressCheck}请求示例
curl "https://getgas.io/api/v1/addresses/TXYZ...your-address..." \
-H "Authorization: Bearer $GETGAS_API_KEY"响应示例 · 200 OK
{
"data": {
"address": "TXYZ...your-address...",
"isActivated": true,
"activationSun": 1275000
}
}POST 激活地址
POST
激活新地址,从余额支付。https://getgas.io/api/v1/addresses/{address}/activate可安全重试:已激活的地址绝不会再次扣费,此时返回其 AddressCheck(200)。价格为提供商的激活费。
授权Bearer Token · 您的 API 密钥
响应
201 Created —
{"data": Activation}。200 OK — 地址已激活时返回 {"data": AddressCheck}。请求示例
curl -X POST "https://getgas.io/api/v1/addresses/TXYZ...your-address.../activate" \
-H "Authorization: Bearer $GETGAS_API_KEY"响应示例 · 201 Created
{
"data": {
"id": 123,
"address": "TXYZ...your-address...",
"status": "active",
"priceSun": 1275000,
"priceTrx": "1.275",
"createdAt": "2026-10-05T12:00:00.000Z"
}
}自动化
GET 自动化列表
GET
该账户的自动化(不含已删除的),按从新到旧排列。https://getgas.io/api/v1/automations包括在网站上创建的自动化。
授权Bearer Token · 您的 API 密钥
响应
200 OK —
{"data": [Automation, ...]}请求示例
curl "https://getgas.io/api/v1/automations" \
-H "Authorization: Bearer $GETGAS_API_KEY"响应示例 · 200 OK
{
"data": [
{
"id": 123,
"kind": "refill",
"status": "active",
"pauseReason": null,
"autoResume": true,
"address": "TXYZ...your-address...",
"volume": 65000,
"minimal": 65000,
"term": "1h",
"nextDeliverySun": 1275000,
"deliveries": 3,
"lastDeliveryAt": null,
"createdAt": "2026-10-05T12:00:00.000Z"
}
]
}POST 创建自动化
POST
在地址上启动 Auto-refill(自动补充)、Auto-renewal(自动续期)或 Smart mode(智能模式)。https://getgas.io/api/v1/automations余额必须覆盖本规则的首次交付,加上每个已运行自动化的下一次交付。此后每次交付发生时即从余额扣费——见“自动化”。
授权Bearer Token · 您的 API 密钥
请求体 · raw (json)
kindstring · 必填 | "refill"、"renewal" 或 "smart"。见“自动化”。 |
addressstring · 必填 | 需要持续补充资源的 TRON 地址。 |
volumeinteger | refill:每次补充的能量,65,000–5,000,000。renewal:保持在地址上的能量,65,000–1,000,000。smart 不使用此字段(固定为 131,000)。 |
minimalinteger | 仅限 refill:当地址上的能量少于此值时补充,0–5,000,000。 |
termstring | 仅限 refill:每次交付的持续时长,"1h"(默认值,也是唯一可选值)。 |
响应
201 Created —
{"data": Automation}请求示例
curl -X POST "https://getgas.io/api/v1/automations" \
-H "Authorization: Bearer $GETGAS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"kind": "refill", "address": "TXYZ...your-address...", "volume": 131000, "minimal": 65000, "term": "1h"}'响应示例 · 201 Created
{
"data": {
"id": 123,
"kind": "refill",
"status": "active",
"pauseReason": null,
"autoResume": true,
"address": "TXYZ...your-address...",
"volume": 65000,
"minimal": 65000,
"term": "1h",
"nextDeliverySun": 1275000,
"deliveries": 3,
"lastDeliveryAt": null,
"createdAt": "2026-10-05T12:00:00.000Z"
}
}GET 获取自动化
GET
单个自动化。https://getgas.io/api/v1/automations/{id}已删除的自动化仍会在此返回,状态为 "removed"。
授权Bearer Token · 您的 API 密钥
响应
200 OK —
{"data": Automation}请求示例
curl "https://getgas.io/api/v1/automations/7" \
-H "Authorization: Bearer $GETGAS_API_KEY"响应示例 · 200 OK
{
"data": {
"id": 123,
"kind": "refill",
"status": "active",
"pauseReason": null,
"autoResume": true,
"address": "TXYZ...your-address...",
"volume": 65000,
"minimal": 65000,
"term": "1h",
"nextDeliverySun": 1275000,
"deliveries": 3,
"lastDeliveryAt": null,
"createdAt": "2026-10-05T12:00:00.000Z"
}
}POST 暂停自动化
POST
暂停自动化。https://getgas.io/api/v1/automations/{id}/pause恢复之前不会有任何交付。在此处设置的暂停永远不会自动解除。
授权Bearer Token · 您的 API 密钥
响应
200 OK —
{"data": Automation}请求示例
curl -X POST "https://getgas.io/api/v1/automations/7/pause" \
-H "Authorization: Bearer $GETGAS_API_KEY"响应示例 · 200 OK
{
"data": {
"id": 123,
"kind": "refill",
"status": "active",
"pauseReason": null,
"autoResume": true,
"address": "TXYZ...your-address...",
"volume": 65000,
"minimal": 65000,
"term": "1h",
"nextDeliverySun": 1275000,
"deliveries": 3,
"lastDeliveryAt": null,
"createdAt": "2026-10-05T12:00:00.000Z"
}
}POST 恢复自动化
POST
恢复已暂停的自动化。https://getgas.io/api/v1/automations/{id}/resume余额必须覆盖它的下一次交付,加上每个已运行自动化的下一次交付。
授权Bearer Token · 您的 API 密钥
响应
200 OK —
{"data": Automation}请求示例
curl -X POST "https://getgas.io/api/v1/automations/7/resume" \
-H "Authorization: Bearer $GETGAS_API_KEY"响应示例 · 200 OK
{
"data": {
"id": 123,
"kind": "refill",
"status": "active",
"pauseReason": null,
"autoResume": true,
"address": "TXYZ...your-address...",
"volume": 65000,
"minimal": 65000,
"term": "1h",
"nextDeliverySun": 1275000,
"deliveries": 3,
"lastDeliveryAt": null,
"createdAt": "2026-10-05T12:00:00.000Z"
}
}DELETE 删除自动化
DELETE
永久删除自动化。https://getgas.io/api/v1/automations/{id}已完成的交付仍保留扣费并保留在列表中。
授权Bearer Token · 您的 API 密钥
响应
200 OK —
{"data": Automation},状态为 "removed"。请求示例
curl -X DELETE "https://getgas.io/api/v1/automations/7" \
-H "Authorization: Bearer $GETGAS_API_KEY"响应示例 · 200 OK
{
"data": {
"id": 123,
"kind": "refill",
"status": "active",
"pauseReason": null,
"autoResume": true,
"address": "TXYZ...your-address...",
"volume": 65000,
"minimal": 65000,
"term": "1h",
"nextDeliverySun": 1275000,
"deliveries": 3,
"lastDeliveryAt": null,
"createdAt": "2026-10-05T12:00:00.000Z"
}
}GET 交付列表
GET
自动化完成的交付,按从新到旧排列,附每次的费用。https://getgas.io/api/v1/deliveries每次交付一行,只扣费一次。
授权Bearer Token · 您的 API 密钥
查询参数
limit | 1–100,默认 25。 |
offset | 要跳过的条目数,默认 0。 |
响应
200 OK —
{"data": [Delivery, ...]}请求示例
curl "https://getgas.io/api/v1/deliveries?limit=10" \
-H "Authorization: Bearer $GETGAS_API_KEY"响应示例 · 200 OK
{
"data": [
{
"id": 123,
"automationId": 7,
"kind": "refill",
"address": "TXYZ...your-address...",
"volume": 65000,
"chargedSun": 1275000,
"chargedTrx": "1.275",
"txId": "b6e0…41d7",
"deliveredAt": "2026-10-05T12:00:00.000Z"
}
]
}文档
GET 获取本参考文档
GET
本参考文档的 Markdown 版本,始终与已部署的 API 一致。https://getgas.io/api/v1/docs无需 API 密钥。每个响应都带有 X-Docs-Version 请求头和 ETag,因此在内容未变化时,带 If-None-Match 的请求会返回 304。“更新日志”部分列出了何时更改了什么。
授权无需授权
响应
200 OK — Markdown(
text/markdown;Accept 中包含 text/html 的浏览器会以 text/plain 收到相同文本,以便在标签页中直接打开)。If-None-Match 匹配时返回 304 Not Modified。请求示例
curl "https://getgas.io/api/v1/docs"响应示例 · 200 OK
text/markdown对象
Order
| 字段 | 类型 | 说明 |
|---|---|---|
id | integer | 订单 id。 |
status | string | 见“订单状态”。 |
resource | string | "energy"。在网站上下的订单也可能是 "bandwidth"。 |
address | string | 资源被代理到的地址。 |
volume | integer | 资源数量。 |
term | string | "15m" 或 "1h"。2026年10月5日之前下的订单也可能显示 "1d"。 |
priceSun | integer | 订单费用,以 sun 计(1 TRX = 1,000,000 sun),含订单费。 |
priceTrx | string | 以精确十进制 TRX 字符串表示的同一价格,例如 "2.73"。 |
txId | string | null | 代理该资源的 TRON 交易。在订单变为 filled 时已填写;在极少数情况下,若提供商晚于两分钟才给出交易,订单会在没有它的情况下变为 filled,txId 随后补填。 |
createdAt | string | ISO 8601 时间戳。 |
updatedAt | string | 最后一次状态变更的 ISO 8601 时间戳。 |
Account
| 字段 | 类型 | 说明 |
|---|---|---|
email | string | 密钥所属的账户。 |
balanceSun | integer | 以 sun 计的余额。订单从中支付。 |
balanceTrx | string | 以精确十进制 TRX 字符串表示的同一余额。 |
depositAddress | string | null | 您用于为余额充值的固定 TRC-20 地址。仅在暂时无法分配时为 null;请稍后重试。 |
depositNetwork | string | "TRC20"。请仅通过 TRON 网络发送。 |
depositCurrencies | string[] | 充值地址接受的币种:TRX 和 USDT(TRC-20)。USDT 按入账时的汇率兑换为 TRX。 |
rates | object | 该账户当前支付的价格:按期限的 `energySunPerUnit`、`bandwidthSunPerUnit`、`smartDeliverySun`、`activationSun`,以及 `orderFeeSun`——加在每笔一次性订单上的固定费用。拥有自己费率的账户会在这里看到其费率。 |
Deposit
| 字段 | 类型 | 说明 |
|---|---|---|
id | integer | 充值 id。 |
transactionId | string | 付款的 TRON 交易哈希。 |
currency | string | "TRX" 或 "USDT-TRC20"。 |
amount | string | 发送的金额,十进制字符串。 |
netAmount | string | 扣除支付网络手续费后的金额,十进制字符串。 |
creditedSun | integer | 已计入余额的金额,以 sun 计。入账前为 0。 |
status | string | 入账后为 "confirmed";其他值表示仍在处理中,或在需要人工核查时(网络或币种错误)为 "ignored"。 |
receivedAt | string | ISO 8601 时间戳。 |
creditedAt | string | null | 余额入账的时间。 |
Automation
| 字段 | 类型 | 说明 |
|---|---|---|
id | integer | 自动化 id。 |
kind | string | "refill"、"renewal" 或 "smart"。 |
status | string | "active"、"paused" 或 "removed"。 |
pauseReason | string | null | 因余额不足以支付下一次交付而暂停时为 "system",应请求暂停时为 "user"。 |
autoResume | boolean | 当余额再次足以支付下一次交付时,"system" 暂停是否自动解除。 |
address | string | 持续补充资源的地址。 |
volume | integer | 每次交付的能量。 |
minimal | integer | null | refill:触发交付的阈值。 |
term | string | null | refill:每次交付的持续时长。 |
nextDeliverySun | integer | 下一次交付的预计费用:该规则继续运行所需的余额。 |
deliveries | integer | 迄今为止完成的交付次数。 |
lastDeliveryAt | string | null | 最后一次交付的 ISO 8601 时间戳。 |
createdAt | string | ISO 8601 时间戳。 |
Delivery
| 字段 | 类型 | 说明 |
|---|---|---|
id | integer | 交付 id。 |
automationId | integer | null | 完成这次交付的自动化。 |
kind | string | null | "refill"、"renewal" 或 "smart"。 |
address | string | null | 交付到的地址。 |
volume | integer | 已交付的能量。 |
chargedSun | integer | 从余额中扣除的金额,以 sun 计。 |
chargedTrx | string | 以精确十进制 TRX 字符串表示的同一金额。 |
txId | string | null | 代理的 TRON 交易。 |
deliveredAt | string | ISO 8601 时间戳。 |
Activation
| 字段 | 类型 | 说明 |
|---|---|---|
id | integer | 激活 id。 |
address | string | 已激活的地址。 |
status | string | "done"、"refunded"(网络拒绝;未扣费)或 "unknown"(未确认;在客服核查期间保持扣费)。 |
priceSun | integer | 费用,以 sun 计。 |
priceTrx | string | 以精确十进制 TRX 字符串表示的同一金额。 |
createdAt | string | ISO 8601 时间戳。 |
AddressCheck
| 字段 | 类型 | 说明 |
|---|---|---|
address | string | 被检查的地址。 |
isActivated | boolean | 该地址是否已在链上存在。资源无法代理到不存在的地址。 |
activationSun | integer | 当前激活该地址的费用,以 sun 计。 |
订单状态
| 状态 | 终态 | 含义 |
|---|---|---|
pending | — | 正在向网络下单。持续数秒。 |
submitted | — | 已接受,正在代理。价格已扣除。 |
filled | 是 | 已交付:能量已到地址上。txId 即代理交易。 |
refunded | 是 | 无法交付;全额已退回余额。 |
failed | 是 | 未交付。如果余额已被扣费,客服会退还。 |
unknown | — | 交付未得到确认。在客服核查期间保持扣费,之后变为 filled 或 refunded。 |
价格与最终价格
- 价格跟随能量提供商自身的价格,每隔几分钟刷新一次。
GET /prices显示通用价格;GET /account显示您的账户实际支付的价格(部分账户有自己的费率)。 - 订单费用为 数量 × 费率 加上一笔固定订单费(
orderFeeSun,除非调整,否则为 0.3 TRX;请从GET /prices读取),每笔订单收取一次。自动化交付和地址激活不收订单费。 - 订单在下单时按当前价格扣费。交付完成后,按提供商对该次交付的最终价格结算:如果更低,差额退回余额;如果更高,则补扣差额。此后订单的
priceSun显示最终价格。拥有自己费率的账户严格按其费率扣费,不进行结算。 - 在订单结算之前,带宽价格为估算值。
自动化如何运行
自动化由提供商执行;每次交付发生时即从余额扣费,按提供商对该次交付的价格(或您自己的费率)计费,不收订单费。每次交付都会列在
GET /deliveries 中,并且只扣费一次。- refill — 每当地址上的能量少于
minimal时,补充volume能量(期限为term)。最适合热钱包。如果地址上的能量一直少于minimal,则每次交付到期时都会再次补充。 - renewal — 在地址上保持
volume能量,每天续期。 - smart — 交付 131,000 能量,并在每笔转账后补足。适用于一次只发送一笔转账、且每 6 秒最多发送一笔的地址。
余额必须同时覆盖所有运行中自动化的下一次交付(
nextDeliverySun):启动或恢复一个自动化,需要在已运行的自动化之外再加上它自己的 nextDeliverySun。一旦余额不再足以覆盖全部,最新的自动化会被暂停(pauseReason: "system"),直到余额再次足够;并且——除非 autoResume 为 false——在充值使余额恢复后,按从旧到新的顺序自动恢复。已完成的交付总会扣费,即使因此导致余额低于零;下一次充值将补足欠款。幂等与重试
- 每次购买都发送一个新的
Idempotency-Key,重试该次购买时使用同一个键。如果请求超时,您无法知道订单是否已下单;用同一个键重试时,若订单已下单则返回该订单,若未下单则下单。它永远不会重复扣费。 - 以不同的地址、数量或期限重复使用同一个键,会返回
409 idempotency_conflict。 POST /orders返回的402、422和503错误不会扣费。在422或503之后可以用同一个键重试;收到402的键会一直返回402,因此请先充值,再用新的键发送购买请求。- 收到
429后,请等待Retry-After请求头中给出的秒数。
Webhook
在后台(https://getgas.io/dashboard/api 中的 Webhook 卡片)设置 webhook URL,即可在订单结束时收到通知,而不必轮询
GET /orders/{id}。该 URL 必须是 HTTPS,并且可从互联网访问。- 何时发送: 已被接受的订单变为
filled、refunded或failed。事件类型:order.filled、order.refunded、order.failed、balance.low(见下文),以及用于后台测试按钮的ping。在下单过程中即被拒绝的订单不会发送:API 已经用错误响应答复过它们。order.filled、order.refunded和order.failed均可在 Dashboard → Settings → Notifications 中单独关闭;已关闭的事件完全不会发送(不会排队,也不会重试)。除非关闭,所有事件默认开启。 - 请求:
POST,JSON 请求体为{"id": "evt_...", "type", "createdAt", "data": Order}(对于ping,data为{"message"};对于balance.low,见下文)。请求头:X-GetGas-Event(事件类型)和X-GetGas-Signature: t=<unix seconds>,v1=<hex>。 - 签名:
v1是使用您的 webhook 密钥(whsec_...,在后台显示)对<t>.<raw body>计算的 HMAC-SHA256。请以恒定时间比较,并拒绝t超过 5 分钟的请求。 - 在 5 秒内以任意 2xx 响应。 否则会在 5 秒、30 秒、1、2、5、10 和 30 分钟后重试,然后是 1、2 和 4 小时后——总计约八小时——并且重试在我们重启后依然保留。不跟随重定向。
- 重复: 同一事件的每次尝试都带有相同的
id(和createdAt);只有签名中的t是新的。请用id忽略重复事件。不同订单的事件可能乱序到达。 - 余额不足(
balance.low): 在后台(API & Keys → Webhook → Low balance alert)设置一个以 TRX 计的阈值;留空即关闭,在您设置之前它处于关闭状态。当一次扣费(订单、自动化交付、激活)使余额低于该阈值时,会立即发送一个事件,data={"balanceSun", "balanceTrx", "thresholdSun", "thresholdTrx"}(*Trx为精确的十进制字符串),之后只要余额仍低于阈值,每小时再发送一次,每次都带有当时的余额。余额达到或高于阈值即停止发送;下次再跌破时会立即再次发送。如果保存的阈值高于当前余额,每小时事件会立即开始(第一次在一分钟内发送)。这些事件需要 webhook URL,并与其他事件一样投递(签名、重试、各自的id)。 order.filled中的priceSun在订单按最终价格结算时仍可能变动一次(见“价格与最终价格”);GET /orders/{id}始终返回当前值。
验证 webhook
import {createHmac, timingSafeEqual} from 'node:crypto';
function verify(rawBody, header, secret) {
const {t, v1} = Object.fromEntries(header.split(',').map(part => part.split('=')));
if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex');
return v1?.length === expected.length && timingSafeEqual(Buffer.from(v1), Buffer.from(expected));
}错误
错误使用 HTTP 状态码和稳定不变的 code,便于据此分支处理。| 状态 | 代码 | 含义 |
|---|---|---|
| 400 | invalid_json | 请求体不是有效的 JSON。 |
| 400 | invalid_query | 某个查询参数的值无效。 |
| 400 | invalid_idempotency_key | POST /orders 需要 Idempotency-Key 请求头:8–64 个字母、数字、"-" 或 "_"。 |
| 401 | unauthorized | API 密钥缺失、无效或已吊销,或账户已被停用。 |
| 403 | ip_not_allowed | 请求来自不在账户 IP 白名单或不在该密钥自身白名单中的地址;错误消息会说明是哪一个。请在后台添加该地址(或其子网):API & Keys → Account IP allowlist,或密钥上的 Edit IPs。 |
| 402 | insufficient_funds | 余额不足(对于自动化:不足以支付本规则及所有运行中规则的下一次交付)。error.details 中包含 priceSun 和 balanceSun。未扣费。 |
| 404 | not_found | 该账户下没有此订单或自动化。 |
| 409 | idempotency_conflict | 该 Idempotency-Key 已被用于参数不同的订单。 |
| 409 | automation_exists | 该地址已有一个同类型的有效自动化。 |
| 415 | unsupported_media_type | 请发送 "Content-Type: application/json"。 |
| 422 | validation_failed | 见 error.details:每个无效字段对应一条消息。未知字段会被拒绝。 |
| 422 | volume_out_of_range | 网络当前接受的范围更窄。error.details 中包含 min 和 max。未扣费。 |
| 429 | rate_limited | 该密钥每分钟请求超过 120 个,或该账户每分钟新订单超过 30 笔。请等待 Retry-After 请求头给出的时间(秒)。 |
| 503 | provider_unavailable | 暂时不可用。未扣费;请稍后重试(如为订单,请使用同一个 Idempotency-Key)。 |
错误响应
{
"error": {
"code": "insufficient_funds",
"message": "The balance does not cover this order.",
"details": {"priceSun": 2730000, "balanceSun": 1000000}
}
}JavaScript 示例
一个完整脚本:查询余额、带幂等键下单,并等待交付完成。代码在右侧。buy.mjs
const API = 'https://getgas.io/api/v1';
const headers = {Authorization: `Bearer ${process.env.GETGAS_API_KEY}`};
async function buyEnergy(address, volume, term = '1h') {
// One key per purchase: a retry after a timeout returns the same order instead of buying twice.
const idempotencyKey = crypto.randomUUID();
let order;
for (let attempt = 0; attempt < 3 && !order; attempt++) {
const res = await fetch(`${API}/orders`, {
method: 'POST',
headers: {...headers, 'Content-Type': 'application/json', 'Idempotency-Key': idempotencyKey},
body: JSON.stringify({address, volume, term}),
}).catch(() => null);
if (!res) continue; // network error: retry with the same key
const body = await res.json();
if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message}`);
order = body.data;
}
if (!order) throw new Error('Could not reach the API');
// Wait until the order is final.
while (['pending', 'submitted', 'unknown'].includes(order.status)) {
await new Promise(resolve => setTimeout(resolve, 3000));
order = (await (await fetch(`${API}/orders/${order.id}`, {headers})).json()).data;
}
return order; // "filled", "refunded" or "failed"
}更新日志
2026-11-23
- API keys: creating a new key in the dashboard (API & Keys) now needs at least 30 TRX on the balance. Existing keys keep working whatever the balance, and no endpoint, field or error code of the API changes.
2026-11-20
- Webhook:order.filled、order.refunded 和 order.failed 现在均可在 Dashboard → Settings → Notifications 中单独关闭。已关闭的事件完全不会发送;除非账户将其关闭,每个事件都保持开启,因此现有 webhook 不受影响。balance.low 仍通过其阈值开启和关闭。
- GET /docs:Accept 请求头中包含 text/html 的请求(浏览器打开链接)现在会以 text/plain; charset=utf-8 收到参考文档,因此会在标签页中打开而不是下载。其他所有请求——没有 Accept、*/*、text/markdown——仍会收到 text/markdown; charset=utf-8,正文、ETag 和 X-Docs-* 请求头均相同。响应现在带有 Vary: Accept。
2026-10-15
- 新接口 GET /prices/history:最近 1–30 天(默认 7 天)的 1 小时能量价格,按小时返回(与后台价格图表一致),或使用 interval=15m 每 15 分钟返回(与定价页面图表一致)。无需密钥。其他内容均无变化。
2026-10-14
- Webhook:新增事件 balance.low。在后台(API & Keys → Webhook → Low balance alert)设置一个以 TRX 计的阈值。当一次扣费使您的余额低于该阈值时,会立即向您的 webhook 发送一个已签名的 POST,之后只要余额仍低于阈值,每小时再发送一次;充值到阈值或以上即停止,下次再跌破时会再次以立即发送的事件开始。data 为 {balanceSun, balanceTrx, thresholdSun, thresholdTrx},包含该事件发生时的余额。未设置阈值的账户不受影响:其他事件、接口或字段均无变化。
2026-10-08
- 按密钥设置 IP 白名单:除账户的白名单外,每个 API 密钥都可以有自己的白名单(后台 → API & Keys → Edit IPs,或在创建密钥时设置)。请求必须来自同时在两个白名单中的地址;403 ip_not_allowed 的消息会说明是哪个白名单拒绝了它。白名单支持子网(例如 203.0.113.0/24,不宽于 /16,IPv6 不宽于 /32);IPv6 地址现在无论以何种写法都能匹配,以 ::ffff:a.b.c.d 形式到达的 IPv4 地址也一样。
- Webhook:投递失败现在会重试约八小时(在 5 秒、30 秒、1、2、5、10 和 30 分钟后,然后是 1、2 和 4 小时后),且待重试的投递在我们重启和部署后依然保留。此前只会在一分钟内再尝试两次,重启会丢弃剩余的重试。
- Webhook:同一事件的每次尝试现在都带有相同的 id 和 createdAt,因此 id 真正能识别重复事件;此前每次重试都会有新的 id。
- 自动化:余额现在必须同时覆盖所有运行中自动化的下一次交付,而不是分别覆盖每一个。除非余额在已运行自动化之外还能覆盖新规则的 nextDeliverySun,否则 POST /automations 和 POST /automations/{id}/resume 会返回 402 insufficient_funds(error.details.priceSun 即为该总额)。当余额不再足以覆盖全部时,最新的自动化会以 pauseReason "system" 暂停,并在充值后按从旧到新的顺序恢复。
- POST /orders 以及其他拒绝未知字段的接口,现在也会以 validation_failed 拒绝名为 "__proto__" 的字段;此前该字段会被忽略。
- 订单现在会与其 txId 一起变为 "filled":当提供商先报告交付、后给出交易时,订单会在等待期间保持 "submitted" 最多两分钟,因此 order.filled webhook 会带有 txId。此前这类订单会以 txId 为 null 的状态变为 filled,并一直保持。
- POST /addresses/{address}/activate 现在在激活仍在确认期间也可安全重试:在一次已付费激活后的一小时内,重复请求会返回该激活(201),而不会再次扣费;为另一个账户正在激活的地址发出的请求会返回其 AddressCheck(200)。
2026-10-05
- 能量不再按天出售:POST /orders 会以 validation_failed 拒绝 term "1d",refill 自动化只接受 term "1h"。GET /prices 和 GET /account 不再列出 "1d" 费率。此前创建的订单和自动化保留其期限。
- 仅措辞调整,行为不变:价格、结算、激活和自动化交付被描述为跟随能量提供商的价格(而不是“网络的价格”);订单费除非调整,否则为 0.3 TRX,因此请从 GET /prices 读取 orderFeeSun;131,000 能量这一数字针对的是未持有 USDT 的收款方;本参考文档的网页版位于 https://getgas.io/zh/developers/docs
2026-10-03
- API 密钥、用量、webhook 和 IP 白名单已移至后台的独立页面:API & Keys(/dashboard/api)。API 本身没有任何变化。
2026-10-01
- Webhook:在后台(API & Keys → Webhook)设置一个 HTTPS URL,即可在订单变为 filled、refunded 或 failed 时收到已签名的 POST。见“Webhook”。
- IP 白名单:账户可以将其 API 密钥限制在一组 IP 地址内。来自任何其他地址的请求会收到 403 ip_not_allowed。
2026-09-30
- 带宽的最低订单量现为 1,000,即网络自身的最低值;更小的订单此前会被拒绝。
- 每笔一次性订单现在都包含一笔固定订单费(0.3 TRX),已计入订单的 priceSun。GET /prices 和 GET /account 以 orderFeeSun 显示该费用。自动化交付和激活不收此费用。
2026-09-29
- 订单现在可以按天租用:term "1d"。
- 首个版本:账户余额、充值地址和自有费率;充值;实时价格;从余额购买能量或带宽,并提供订单状态和历史;地址激活;自动化(Auto-refill、Auto-renewal、Smart mode)及其交付。