能量平台提供了API接口,允许您通过程序化方式访问我们的服务,包括能量闪租和笔数购买功能。
所有API请求应使用以下基础URL:
https://your-domain.com/api/v1
所有API请求都需要通过API密钥和密钥进行双重认证。您可以在平台的"API管理"页面创建和管理您的API密钥。
将您的API密钥和密钥添加到每个请求的HTTP头部:
X-API-Key: your_api_key
X-Secret-Key: your_secret_key
系统会自动验证您的API密钥和密钥组合是否有效并确认您的身份。请妥善保管您的API密钥和密钥,不要泄露给他人。
注意: API密钥和密钥在创建或重置后只显示一次,请务必立即保存好。
为了保护系统资源并确保服务质量,API请求受到速率限制。目前限制为每个API密钥每分钟最多20个请求。如果超过限制,将返回HTTP 429状态码。
请求:
POST /quick-energy
请求参数:
参数名 | 类型 | 是否必须 | 描述 |
---|---|---|---|
quantity | integer | 是 | 需要租用的能量数量,最小值为65000 |
address | string | 是 | TRC20地址,用于接收能量 |
请求示例:
{
"quantity": 65000,
"address": "TYourTronAddress123456789012345678901234"
}
响应:
{
"success": true,
"data": {
"order_id": 12345,
"quantity": 65000,
"amount": 3.000,
"address": "TYourTronAddress123456789012345678901234",
"created_at": "2023-06-15T08:00:00Z",
"status": "PENDING"
},
"message": "能量闪租订单创建成功"
}
请求:
POST /transaction-order
请求参数:
参数名 | 类型 | 是否必须 | 描述 |
---|---|---|---|
quantity | integer | 是 | 需要购买的笔数,最小值为5 |
address | string | 是 | TRC20地址,用于接收能量 |
请求示例:
{
"quantity": 10,
"address": "TYourTronAddress123456789012345678901234"
}
响应:
{
"success": true,
"message": "Transaction order created successfully",
"data": {
"order_id": 12346,
"quantity": 10,
"amount": 35.00,
"address": "TYourTronAddress123456789012345678901234",
"balance": 165.00
}
}
API使用标准HTTP响应码来表示请求的结果:
状态码 | 描述 |
---|---|
200 | 请求成功 |
400 | 请求参数错误 |
401 | 认证失败 |
403 | 权限不足 |
404 | 资源未找到 |
409 | 请求冲突 |
429 | 请求过于频繁 |
500 | 服务器内部错误 |
当发生错误时,响应主体将包含错误详情:
{
"success": false,
"message": "错误描述",
"code": "错误代码(可选)"
}
使用我们的API时,请遵循以下最佳实践:
const axios = require('axios');
async function createQuickEnergyOrder() {
try {
const response = await axios.post('https://your-domain.com/api/v1/quick-energy', {
quantity: 65000,
address: 'TYourTronAddress123456789012345678901234'
}, {
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your_api_key',
'X-Secret-Key': 'your_secret_key'
}
});
console.log('Order created:', response.data);
return response.data;
} catch (error) {
console.error('Error creating order:', error.response ? error.response.data : error.message);
throw error;
}
}
import requests
def create_transaction_order():
try:
url = "https://your-domain.com/api/v1/transaction-order"
headers = {
"Content-Type": "application/json",
"X-API-Key": "your_api_key",
"X-Secret-Key": "your_secret_key"
}
payload = {
"quantity": 10,
"address": "TYourTronAddress123456789012345678901234"
}
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
print("Order created:", response.json())
return response.json()
except requests.exceptions.RequestException as e:
print("Error creating order:", e)
if hasattr(e, 'response') and e.response:
print("Response:", e.response.text)
raise
如果您在使用API过程中遇到任何问题或有任何疑问,请联系我们的技术支持团队。