使用範圍接口 start_date 同 end_date 包括首尾兩日。base 預設 USD,symbols 用逗號分隔。亦可以開英文歷史工具。
data 包含保存觀測行。有下一頁就繼續用 has_more 同 next_cursor;CSV 同 Parquet 可以下載支援時段。
GET /v1/range copy
$ curl -G "https://api.exchangerate.dev/v1/range" \
-H "Authorization: Bearer exr_live_..." \
--data-urlencode "base=USD" \
--data-urlencode "symbols=EUR,GBP" \
--data-urlencode "start_date=2026-06-10" \
--data-urlencode "end_date=2026-06-13" 閱讀 JSON 回應 data 包含保存觀測行。有下一頁就繼續用 has_more 同 next_cursor;CSV 同 Parquet 可以下載支援時段。
JSON copy
{
"result": "success",
"base": "USD",
"start_date": "2026-06-10",
"end_date": "2026-06-13",
"data": [
{ "date": "2026-06-10", "rates": { "EUR": 0.86663, "GBP": 0.74727 },
"source": "ecb_daily", "is_forward_filled": false },
{ "date": "2026-06-11", "rates": { "EUR": 0.86678, "GBP": 0.74829 },
"source": "ecb_daily", "is_forward_filled": false },
{ "date": "2026-06-12", "rates": { "EUR": 0.86453, "GBP": 0.74613 },
"source": "ecb_daily", "is_forward_filled": false }
],
"has_more": false,
"next_cursor": null
} 缺少嘅曆日 例子冇 2026 年 6 月 13 日,因為範圍接口只返回保存觀測,唔會為每個曆日整行。
用 Python 分頁 呢個迴圈會跟晒每個游標。
Python · requests copy
import requests
API = "https://api.exchangerate.dev/v1"
KEY = "exr_live_..." # free key at https://exchangerate.dev/signup
params = {
"base": "USD",
"symbols": "EUR,GBP",
"start_date": "2026-06-10",
"end_date": "2026-06-13",
}
rows = []
while True:
resp = requests.get(
f"{API}/range",
headers={"Authorization": f"Bearer {KEY}"},
params=params,
timeout=10,
)
resp.raise_for_status()
data = resp.json()
rows.extend(data["data"])
if not data["has_more"]:
break
cursor = data.get("next_cursor")
if not cursor or cursor <= params.get("cursor", ""):
raise RuntimeError("Incomplete historical response")
params["cursor"] = cursor
for row in rows:
filled = row["is_forward_filled"]
print(row["date"], row["rates"]["EUR"], row["rates"]["GBP"], "filled" if filled else "") 分清觀測值同順延值 範圍觀測嘅 is_forward_filled 係 false;指定日期可能返回之前嘅值並標記 true。
週末唔係觀測值
範圍結果省略 2026 年 6 月 13 日。直接查呢日可能返回之前嘅值,並標記 is_forward_filled 為 true。
選擇指定日期或範圍 單日查詢適合睇一日;範圍適合圖表、回填同批量分析。
項目 指定日期 範圍
請求 每日一次 一次請求加分頁
回應 一日 data 陣列
檢查覆蓋範圍 1,830 日係請求上限,唔代表每個貨幣對都有咁長歷史。檢查 source、行同 data: []。
pandas 載入 pandas 後按日期排序,計算前剔除順延值。
Python · pandas copy
import pandas as pd
# rows contains every page from the loop above
df = pd.json_normalize(rows)
df["date"] = pd.to_datetime(df["date"])
df = df.set_index("date").sort_index()
# keep only rows that were actually published that day
df = df[~df["is_forward_filled"]]
print(df[["rates.EUR", "rates.GBP"]].tail()) pandas 唔係必需,其他工具都可以處理相同資料。
在歷史匯率工具查詢日期(英文)