1. 请求两种汇率
路径中的 USD 是基准货币,symbols 中的 EUR 和 GBP 是目标货币。换成你需要的代码即可。
curl -fsS --max-time 10 "https://api.exchangerate.dev/v1/latest/USD?symbols=EUR,GBP"from urllib.request import Request, urlopenimport json# Identify your application explicitly when calling the API.request = Request("https://api.exchangerate.dev/v1/latest/USD?symbols=EUR,GBP", headers={"User-Agent": "exchangerate-docs/1.0"})with urlopen(request, timeout=10) as response: data = json.load(response)print(data["rates"]["EUR"])const response = await fetch("https://api.exchangerate.dev/v1/latest/USD?symbols=EUR,GBP", { signal: AbortSignal.timeout(10_000),});if (!response.ok) throw new Error(`HTTP ${response.status}`);const data = await response.json();console.log(data.rates.EUR);集成指南: Python · JavaScript / Node.js · Google Sheets · Excel · Go · Swift · Zapier
2. 读取响应
数值会变化,结构不会。读取 rates.EUR,并把 source、market_session、data_updated_at 与汇率一起保存。
json
{ "result": "success", "base": "USD", "source": "live", "sources": { "EUR": "live", "GBP": "live" }, "market_session": "open", "timestamp": "2026-06-15T12:00:00Z", "data_updated_at": "2026-06-15T12:00:00Z", "effective_at": { "EUR": "2026-06-15T12:00:00Z", "GBP": "2026-06-15T12:00:00Z" }, "rates": { "EUR": 0.86207, "GBP": 0.74627 }, "stale": { "EUR": false, "GBP": false }, "derived_symbols": [], "notice": "Indicative rates, not for settlement."}3. 需要账户额度时添加密钥
创建免费密钥,通过 Authorization: Bearer YOUR_KEY 发送。密钥应保存在服务端,不要放进公开的浏览器代码。
bash
curl "https://api.exchangerate.dev/v1/latest/USD?symbols=EUR,GBP" \ -H "Authorization: Bearer YOUR_KEY"