首页 文档 价格 API 状态

API 文档

将实时货币汇率集成到您的应用程序所需的一切。

概述

AllRatesToday API 通过简单的 REST 接口提供实时和历史货币汇率。所有响应均为 JSON 格式。基础 URL 为:

https://allratestoday.com

我们提供免费公共端点(无需认证)和认证端点(更高的速率限制)。

认证

公共端点(/api/public/rates无需认证 — 直接调用即可。

对于认证端点,请将您的 API 密钥作为 Bearer 令牌包含在请求中:

Authorization: Bearer YOUR_API_KEY

登录后,从您的个人资料页面获取 API 密钥。

速率限制

速率限制响应头 所有响应都包含速率限制头:X-RateLimit-LimitX-RateLimit-RemainingX-RateLimit-Reset
方案 限制 认证
公共(免费) 每个 IP 每小时 100 次请求
认证(免费) 每个密钥每分钟 100 次请求 Bearer 令牌

公共汇率

GET /api/public/rates

免费的公共端点 — 无需认证。适用于 AI 聊天机器人、快速集成和原型开发。

参数类型描述
from必需 string 源货币代码(例如 USD、EUR)
to必需 string 目标货币代码(例如 GBP、INR)
amount可选 number 转换金额(默认:1)

请求示例:

curl "https://allratestoday.com/api/public/rates?from=USD&to=EUR&amount=100"

响应示例:

{
  "success": true,
  "from": { "currency": "USD", "amount": 100 },
  "to": { "currency": "EUR", "amount": 92.15 },
  "rate": 0.9215,
  "inverse_rate": 1.0852,
  "timestamp": "2026-04-03T12:00:00Z",
  "source": "AllRatesToday.com",
  "type": "mid-market rate",
  "disclaimer": "This is the mid-market rate. Actual transfer rates may vary.",
  "rateLimit": { "remaining": 99, "limit": 100 }
}
已启用 CORS 此端点支持跨域请求 — 您可以直接从浏览器调用。

认证汇率

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": "wise" }

历史汇率

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"
{
  "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": "wise",
  "period": "30d"
}

错误代码

状态码含义
400请求错误 — 缺少或无效的参数
401未授权 — 缺少或无效的 API 密钥
429超过速率限制 — 请检查 Retry-After 响应头
500服务器内部错误
503服务暂时不可用

支持的货币

支持 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/public/rates?from=USD&to=EUR'
);
const data = await response.json();
console.log(`1 USD = ${data.rate} EUR`);

Python

import requests

response = requests.get(
    'https://allratestoday.com/api/public/rates',
    params={'from': 'USD', 'to': 'EUR'}
)
data = response.json()
print(f"1 USD = {data['rate']} EUR")

PHP

$response = file_get_contents(
    'https://allratestoday.com/api/public/rates?from=USD&to=EUR'
);
$data = json_decode($response, true);
echo "1 USD = " . $data['rate'] . " EUR";

cURL

# Public endpoint (no auth)
curl "https://allratestoday.com/api/public/rates?from=USD&to=EUR&amount=500"

# Authenticated endpoint
curl "https://allratestoday.com/api/v1/rates?source=USD&target=EUR" \
  -H "Authorization: Bearer YOUR_API_KEY"

准备好集成了吗?

获取您的免费 API 密钥,几秒钟内即可开始发送请求。

获取免费API密钥