1. 請求兩個匯率
Path 入面 USD 係基準貨幣,`symbols` 入面 EUR 同 GBP 係目標貨幣。換成你需要嘅 code 就得。
curl -fsS --max-time 10 "https://api.exchangerate.dev/v1/latest/USD?symbols=EUR,GBP"from urllib.request import Request, urlopen
import 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);回應範例
{
"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."
}rates.EUR 代表 1 USD 對應嘅 EUR 數量。effective_at.EUR 係觀測時間,sources.EUR 顯示來源類別。數值同時間只係示例。
2. 讀取回應
數值會變,結構唔會。讀 `rates.EUR`,並將 `source`、`market_session`、`data_updated_at` 同匯率一齊保存。
{
"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. 要帳戶額度先加入 key
建立免費 key,再用 `Authorization: Bearer YOUR_KEY` 傳送。Key 應該留喺 server,唔好放入公開 browser code。
curl "https://api.exchangerate.dev/v1/latest/USD?symbols=EUR,GBP" -H "Authorization: Bearer YOUR_KEY"只屬指示性匯率
適合應用程式、模型同分析,唔係可以成交嘅報價,亦唔可以用作結算。