DEV Community

Jenpo Zhan
Jenpo Zhan

Posted on

Copyable JavaScript and Python snippets for historical exchange rate CSV data

When you need historical exchange rates inside a report or spreadsheet workflow, the useful part is usually not a large SDK. It is a small, copyable request that can be scheduled, cached, and checked.

This post collects three minimal FXpeek examples:

  • fetch a JSON history series in JavaScript
  • save a CSV file in Python
  • download a CSV file with curl

FXpeek provides reference exchange rates for lookup, charting, CSV export, and lightweight reporting workflows. These are not transaction quotes.

JavaScript: fetch 30 days of history

async function getFxHistory(from, to, days = 30) {
  const url = new URL('https://fxpeek.com/api/history');
  url.searchParams.set('from', from);
  url.searchParams.set('to', to);
  url.searchParams.set('days', String(days));

  const res = await fetch(url);
  if (!res.ok) {
    throw new Error(`FXpeek API error: ${res.status}`);
  }

  return res.json();
}

const data = await getFxHistory('CNY', 'TRY', 30);
console.log(data.rates.slice(0, 3));
Enter fullscreen mode Exit fullscreen mode

Use this when you want to power a small chart, report preview, internal reconciliation tool, or spreadsheet add-on.

Python: save a CSV file

import requests

url = "https://fxpeek.com/api/csv"
params = {"from": "CNY", "to": "TRY", "days": 365}

res = requests.get(url, params=params, timeout=20)
res.raise_for_status()

with open("cny-try-365d.csv", "wb") as f:
    f.write(res.content)
Enter fullscreen mode Exit fullscreen mode

The CSV format is intentionally simple:

date,base,target,rate
2026-05-28,CNY,TRY,6.7699
2026-05-29,CNY,TRY,6.7811
2026-06-01,CNY,TRY,6.7839
Enter fullscreen mode Exit fullscreen mode

That makes it easy to import into Excel, Google Sheets, pandas, or BI tools.

Shell: quick CSV download

curl -L 'https://fxpeek.com/api/csv?from=CNY&to=TRY&days=365' \
  -o cny-try-365d.csv
Enter fullscreen mode Exit fullscreen mode

API docs and examples

API docs:

https://fxpeek.com/en/api?utm_source=devto&utm_medium=article&utm_campaign=fxpeek_wave1_api_csv&utm_content=code_snippets

Public GitHub examples:

https://github.com/Jenpo/historical-exchange-rate-api-examples

Public Gist:

https://gist.github.com/Jenpo/f2b04bb5416d503641fb3da94861f533

Notes

  • Rates are reference data, not executable transaction quotes.
  • The first public batch focuses on data-backed currency pairs.
  • For trading, settlement, tax filing, or regulated accounting, validate your source and licensing requirements first.

Top comments (0)