获取汇率
POST
/api/v1/bank/wallet/fx/rate/Bearer Token请求头
| 请求头 | 值 | 必填 |
|---|---|---|
Authorization | Bearer {A55_ACCESS_TOKEN} | 是 |
Content-Type | application/json | 是 |
请求体
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
from_currency | string | 是 | 源货币,ISO 4217(国际标准货币代码) |
to_currency | string | 是 | 目标货币,ISO 4217 代码 |
支持的货币
| 代码 | 货币 |
|---|---|
USD | 美元 |
BRL | 巴西雷亚尔 |
EUR | 欧元 |
MXN | 墨西哥比索 |
ARS | 阿根廷比索 |
COP | 哥伦比亚比索 |
CLP | 智利比索 |
PEN | 秘鲁索尔 |
所有组合共 56 个可用的兑换货币对。
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
price | float | 汇率,四舍五入到小数点后 2 位。1 单位源货币 = price 单位目标货币 |
HTTP 状态码
| 状态码 | 说明 |
|---|---|
| 200 | 汇率返回成功 |
| 400 | 无效的货币代码或源/目标货币相同 |
| 401 | Bearer Token(持有者令牌)无效或已过期 |
| 403 | 该钱包未启用外汇功能 |
| 422 | 不支持的货币对 |
| 429 | 超出速率限制 |
| 500 | 服务器内部错误——请使用指数退避重试 |
代码示例
- cURL
- Python
- Node.js
curl -s -X POST https://core-manager.a55.tech/api/v1/bank/wallet/fx/rate/ \
-H "Authorization: Bearer $A55_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"from_currency": "USD",
"to_currency": "BRL"
}'
import requests
import os
token = os.environ["A55_ACCESS_TOKEN"]
base = os.environ.get("A55_API_URL", "https://core-manager.a55.tech")
try:
response = requests.post(
f"{base}/api/v1/bank/wallet/fx/rate/",
json={
"from_currency": "USD",
"to_currency": "BRL",
},
headers={
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
},
)
response.raise_for_status()
fx = response.json()
print(f"汇率:1 USD = {fx['price']} BRL")
except requests.exceptions.HTTPError as e:
print(f"HTTP {e.response.status_code}: {e.response.json()}")
except requests.exceptions.RequestException as e:
print(f"请求失败:{e}")
const token = process.env.A55_ACCESS_TOKEN;
const base = process.env.A55_API_URL || "https://core-manager.a55.tech";
try {
const response = await fetch(`${base}/api/v1/bank/wallet/fx/rate/`, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
from_currency: "USD",
to_currency: "BRL",
}),
});
if (!response.ok) throw new Error(`请求失败(HTTP ${response.status}):${await response.text()}`);
const fx = await response.json();
console.log(`汇率:1 USD = ${fx.price} BRL`);
} catch (error) {
console.error("汇率查询失败:", error.message);
}
响应示例
{
"price": 5.73
}
错误响应示例
{
"status": "error",
"message": [
{
"code": "UNSUPPORTED_PAIR",
"source": "fx",
"description": "Currency pair GBP/BRL is not supported"
}
]
}