ใช้ range endpoint 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
} วันที่ในปฏิทินที่หายไป ไม่มีวันเสาร์ที่ 13 มิถุนายน 2026 เพราะ range คืนข้อมูลที่บันทึก ไม่ได้สร้างแถวทุกวัน
แบ่งหน้าด้วย 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 "") แยกข้อมูลจริงกับค่าที่เลื่อนมา ข้อมูล range มี is_forward_filled เป็น false ส่วนการขอวันที่อาจคืนค่าก่อนหน้าพร้อม true
วันหยุดสุดสัปดาห์ไม่ใช่ข้อมูล
range ไม่รวมวันเสาร์ที่ 13 มิถุนายน 2026 การขอโดยตรงอาจคืนค่าก่อนหน้าและตั้ง is_forward_filled เป็น true
เลือกวันที่เดียวหรือช่วง วันที่เดียวเหมาะกับการตรวจสอบ ส่วนช่วงเหมาะกับกราฟ backfill และการวิเคราะห์จำนวนมาก
มิติ วันที่เดียว ช่วง
คำขอ วันละหนึ่งครั้ง หนึ่งคำขอและหลายหน้า
ผลลัพธ์ หนึ่งวัน อาร์เรย์ 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 เครื่องมืออื่นก็จัดการแถวเดียวกันได้
ค้นหาวันที่ในเครื่องมืออัตราแลกเปลี่ยนย้อนหลัง (ภาษาอังกฤษ)