API 文档
将实时货币汇率集成到您的应用程序所需的一切。
概述
AllRatesToday API 通过简单的 REST 接口提供实时和历史货币汇率。所有响应均为 JSON 格式。基础 URL 为:
https://allratestoday.com 免费注册即可获取 API 密钥,访问认证端点。提供免费层级。
认证
请将您的 API 密钥作为 Bearer 令牌包含在请求中:
Authorization: Bearer YOUR_API_KEY 登录后,从您的个人资料页面获取 API 密钥。
速率限制
速率限制响应头
所有响应包含:
X-RateLimit-Limit、X-RateLimit-Remaining、X-RateLimit-Reset、X-Monthly-Limit、X-Monthly-Used、X-Monthly-Resets。
| 方案 | 月请求量 | 速率 | 认证 | 价格 |
|---|---|---|---|---|
| 公共 | 每IP每小时10次 | 10/小时 | 无 | 免费 |
速率限制因计划而异。超出月限额后API返回 429。达到90%时发送警告邮件。
查看定价
认证汇率
GET /api/v1/rates
具有更高速率限制的认证端点。需要 Bearer 令牌。
| 参数 | 类型 | 描述 |
|---|---|---|
| source可选 | string | 源货币代码(例如 USD) |
| target可选 | string | 目标货币代码(例如 EUR) |
| time可选 | ISO 8601 | 特定时间点的汇率 |
| from可选 | YYYY-MM-DD | 历史范围的开始日期 |
| to可选 | YYYY-MM-DD | 历史范围的结束日期 |
| group可选 | string | 分组方式:day、hour、minute |
示例:
curl "https://allratestoday.com/api/v1/rates?source=USD&target=EUR" \
-H "Authorization: Bearer YOUR_API_KEY" 响应:
[
{
"rate": 0.9215,
"source": "USD",
"target": "EUR",
"time": "2026-04-03T12:00:00Z"
}
] 简单汇率
GET /api/rate
用于获取单个货币对汇率的轻量级端点。
| 参数 | 类型 | 描述 |
|---|---|---|
| source必需 | string | 源货币代码 |
| target必需 | string | 目标货币代码 |
curl "https://allratestoday.com/api/rate?source=GBP&target=USD" { "rate": 1.2634, "source": "refinitiv" } 历史汇率
GET /api/historical-rates
获取历史汇率数据,用于图表和分析。
| 参数 | 类型 | 描述 |
|---|---|---|
| source必需 | string | 源货币代码 |
| target必需 | string | 目标货币代码 |
| period可选 | string | 1d、7d、30d 或 1y(默认:7d) |
curl "https://allratestoday.com/api/historical-rates?source=USD&target=EUR&period=30d" \
-H "Authorization: Bearer YOUR_API_KEY" {
"source": "USD",
"target": "EUR",
"data": [
{ "date": "2026-03-04", "rate": 0.9198, "timestamp": 1741046400000 },
{ "date": "2026-03-05", "rate": 0.9210, "timestamp": 1741132800000 }
],
"source_api": "refinitiv",
"period": "30d"
} 错误代码
| 状态码 | 含义 |
|---|---|
400 | 请求错误 — 缺少或无效的参数 |
401 | 未授权 — 缺少或无效的 API 密钥 |
429 | 超过速率限制 — 请检查 Retry-After 响应头 |
500 | 服务器内部错误 |
503 | 服务暂时不可用 |
数据时效性
AllRatesToday 提供实时汇率。与其他每60分钟更新一次的服务不同,我们的汇率在每次请求时从Reuters (Refinitiv) 和银行间市场数据实时获取,确保您始终获得最新的中间市场汇率。
实时更新
汇率从Reuters (Refinitiv) 和银行间市场数据实时获取——没有延迟或批量更新。
支持的货币
支持 160+ 种货币,包括:
主要货币
USD, EUR, GBP, JPY, CHF, CAD, AUD, NZD
热门货币
INR, CNY, BRL, MXN, RUB, TRY, ZAR, SGD, HKD, KRW, THB, PHP, PKR, BDT, LKR, NGN, GHS, KES, AED, SAR, EGP 等
完整列表请参阅 OpenAPI 规范。
代码示例
JavaScript / Node.js
const response = await fetch(
'https://allratestoday.com/api/v1/rates?source=USD&target=EUR',
{ headers: { 'Authorization': 'Bearer YOUR_API_KEY' } }
);
const data = await response.json();
console.log(`1 USD = ${data.rate} EUR`); Python
import requests
response = requests.get(
'https://allratestoday.com/api/v1/rates',
params={'source': 'USD', 'target': 'EUR'},
headers={'Authorization': 'Bearer YOUR_API_KEY'}
)
data = response.json()
print(f"1 USD = {data['rate']} EUR") PHP
$opts = {'http' => {'header' => 'Authorization: Bearer YOUR_API_KEY'}};
$context = stream_context_create($opts);
$response = file_get_contents(
'https://allratestoday.com/api/v1/rates?source=USD&target=EUR',
false, $context
);
$data = json_decode($response, true);
echo "1 USD = " . $data['rate'] . " EUR"; cURL
curl "https://allratestoday.com/api/v1/rates?source=USD&target=EUR" \
-H "Authorization: Bearer YOUR_API_KEY"