范围接口返回带分页、来源和填充标记的已保存观测。
- JSON 每页最多 366 条观测值;has_more 为 true 时,用 next_cursor 获取下一页。
- Free 为 30 天,Basic 为 1 年,Plus 和 Pro 提供完整历史。每次最多 1,830 天,实际深度因货币对而异。
- 示例没有 2026 年 6 月 13 日,因为范围接口返回保存的观测,不会为每个日历日创建行。
- 不可以。这些是指示性汇率;请查看 notice 和 source。
使用范围接口
start_date 和 end_date 包含首尾日期。base 默认为 USD,symbols 用逗号分隔。也可以打开英文历史工具。
data 包含保存的观测行。继续使用 has_more 和 next_cursor;CSV 和 Parquet 可下载支持窗口。
GET /v1/range
$ 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
{ "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
import requestsAPI = "https://api.exchangerate.dev/v1"KEY = "exr_live_..." # Basic or higher: https://exchangerate.dev/pricingparams = { "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"] = cursorfor 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 数组 |
检查覆盖范围
Free 为 30 天,Basic 为 1 年,Plus 和 Pro 提供完整历史。每次最多 1,830 天,实际深度因货币对而异。
pandas
加载到 pandas 后按日期排序,并在计算前排除顺延值。
Python · pandas
import pandas as pd# rows contains every page from the loop abovedf = 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 daydf = df[~df["is_forward_filled"]]print(df[["rates.EUR", "rates.GBP"]].tail())pandas 不是必需的;也可以使用其他工具处理相同的行。