{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreihyipx5jj7h3agcygrlbnunreajehhxr6wycmi4vsjv3jyktwvs54",
    "uri": "at://did:plc:25rdn5elo5izoxrmtis34zuk/app.bsky.feed.post/3mojp2fnzty42"
  },
  "coverImage": {
    "$type": "blob",
    "ref": {
      "$link": "bafkreicbyavuhvkrwkxd2jusv3hijpsyxnrkrwoodasaueifxkdbpov5pm"
    },
    "mimeType": "image/webp",
    "size": 71064
  },
  "path": "/jenpo_zhan_aca905ad2a8a5b/how-to-download-historical-exchange-rates-as-csv-with-a-free-api-40o7",
  "publishedAt": "2026-06-18T01:18:44.000Z",
  "site": "https://dev.to",
  "tags": [
    "api",
    "javascript",
    "python",
    "csv",
    "https://fxpeek.com/en/api?utm_source=devto&utm_medium=article&utm_campaign=fxpeek_wave1_api_csv&utm_content=csv_tutorial",
    "https://fxpeek.com/en/cny-to-try?utm_source=devto&utm_medium=article&utm_campaign=fxpeek_wave1_api_csv&utm_content=pair_page"
  ],
  "textContent": "Developers and spreadsheet users often need historical exchange rates for reporting, bookkeeping, ecommerce reconciliation, or dashboards.\n\nThe usual workflow is awkward:\n\n  * Search a currency converter.\n  * Copy a single number.\n  * Repeat for many dates.\n  * Paste everything into a spreadsheet.\n\n\n\nThis tutorial shows a simpler workflow using FXpeek's free JSON and CSV endpoints.\n\n##  1. Get The Latest Reference Rate\n\n\n    curl 'https://fxpeek.com/api/rates?from=CNY&to=TRY'\n\n\nExample response:\n\n\n\n    {\n      \"from\": \"CNY\",\n      \"to\": \"TRY\",\n      \"rate\": 6.789,\n      \"timestamp\": 1780576363130\n    }\n\n\n##  2. Get A Historical Series\n\n\n    curl 'https://fxpeek.com/api/history?from=CNY&to=TRY&days=365'\n\n\nUse this when you want to build:\n\n  * A chart\n  * A dashboard\n  * A report\n  * A validation script\n  * A lightweight finance tool\n\n\n\n##  3. Download CSV For Excel Or Google Sheets\n\n\n    curl -L 'https://fxpeek.com/api/csv?from=CNY&to=TRY&days=365' \\\n      -o cny-try-history.csv\n\n\nCSV output:\n\n\n\n    date,base,target,rate\n    2026-05-28,CNY,TRY,6.7699\n    2026-05-29,CNY,TRY,6.7811\n    2026-06-01,CNY,TRY,6.7839\n\n\n##  4. Use It In JavaScript\n\n\n    async function getHistory(from, to, days = 365) {\n      const url = new URL('https://fxpeek.com/api/history');\n      url.searchParams.set('from', from);\n      url.searchParams.set('to', to);\n      url.searchParams.set('days', String(days));\n\n      const res = await fetch(url);\n      if (!res.ok) {\n        throw new Error(`FX API error: ${res.status}`);\n      }\n      return res.json();\n    }\n\n    const history = await getHistory('CNY', 'TRY', 30);\n    console.log(history.rates);\n\n\n##  5. Use It In Python\n\n\n    import requests\n    import pandas as pd\n\n    url = \"https://fxpeek.com/api/history\"\n    params = {\"from\": \"CNY\", \"to\": \"TRY\", \"days\": 365}\n\n    data = requests.get(url, params=params, timeout=20).json()\n    df = pd.DataFrame(data[\"rates\"])\n    df.to_csv(\"cny-try-history.csv\", index=False)\n\n\n##  Notes\n\nFXpeek provides reference rates for historical lookup, spreadsheets, reports, and lightweight apps. These are not transaction quotes.\n\nAPI docs:\n\nhttps://fxpeek.com/en/api?utm_source=devto&utm_medium=article&utm_campaign=fxpeek_wave1_api_csv&utm_content=csv_tutorial\n\nExample pair page:\n\nhttps://fxpeek.com/en/cny-to-try?utm_source=devto&utm_medium=article&utm_campaign=fxpeek_wave1_api_csv&utm_content=pair_page\n\n##  Good Next Steps\n\n  * Add a date picker.\n  * Cache the API result.\n  * Build a chart with Recharts or Chart.js.\n  * Export monthly averages.\n  * Combine rates with ecommerce order data.\n\n",
  "title": "How to Download Historical Exchange Rates as CSV with a Free API"
}