Skip to content
dino.markets
DocsPricing
StocksSee the stocks API →CryptoSee the crypto API →CommoditiesSee the commodities API →EURUSDCurrenciesSee the currencies API →EconomicsSee the economics API →CoverageSee the coverage →
  • StocksStocks and ETFs on 42 exchanges, US funds and crypto
  • CryptoPrices and history for crypto pairs
  • CommoditiesGold in 31 currencies, other metals and oil in US dollars
  • CurrenciesHistory and conversion for 143 currencies
  • EconomicsInflation, GDP, jobs and yield curves
  • CoverageEvery country, currency, commodity and exchange the APIs cover
Build withDocsEndpointsMCPllms.txt
GuidesRead the guides →fxUse casesSee the use cases →dino.marketsCompareSee the comparisons →ChangelogSee what's new →
  • GuidesStep by step, with code you can run
  • Use casesThe calls each kind of app makes
  • CompareHow dino.markets sits against other data APIs
  • ChangelogNew data, countries and features
Build withDocsEndpointsMCPllms.txt
Sign inSign-ups paused

Home/Guides/How to get exchange rates in Python

How to get exchange rates in Python

Exchange rates in Python with requests: fetch latest rates, convert an amount and read daily history with a dino.markets key, plus error handling and caching.

EURUSD

Python’s requests library can fetch the latest USD rates and convert an amount through dino.markets. Send your API key in a Bearer header with each request.

import os
import requests

API = "https://api.dino.markets/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['DINO_API_KEY']}"}

def get(path, params):
    response = requests.get(f"{API}{path}", params=params, headers=HEADERS, timeout=30)
    response.raise_for_status()
    return response.json()

latest = get("/fx/rates/USD", {"currencies": "IDR,EUR"})
rates = {item["currency"]: item["rate"] for item in latest["rates"]}
print(f"1 USD = {rates['IDR']} IDR")

result = get("/fx/convert", {"from": "USD", "to": "IDR", "amount": "100"})
print(f"100 USD = {result['converted']} IDR")

Before you start

  • Python 3.8 or newer.
  • The requests library.
  • A dino.markets API key.
  • Each successful request counts against your plan’s monthly limit. Failed requests do not count.

Get a key

Sign up for the Free plan, which needs no card. Then open keys in the dashboard, create a key and save it as the environment variable DINO_API_KEY.

Install requests

Install requests with pip.

pip install requests

Request the latest rates

Call GET /v1/fx/rates/{base} with a base currency. The optional currencies parameter lists the quote currencies you want, separated by commas. Leave it out to get every currency.

import os
import requests

API = "https://api.dino.markets/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['DINO_API_KEY']}"}

response = requests.get(
    f"{API}/fx/rates/USD",
    params={"currencies": "IDR,EUR"},
    headers=HEADERS,
    timeout=30,
)
response.raise_for_status()
data = response.json()

The response:

{
  "base": "USD",
  "market_session": "open",
  "rates": [
    { "currency": "IDR", "rate": "18038.7", "timestamp": "2026-10-26T23:59:59Z", "stale": false },
    { "currency": "EUR", "rate": "0.89499", "timestamp": "2026-10-26T23:59:59Z", "stale": false }
  ]
}

Print a rate

The rates array has one item per currency, with currency and rate fields. Each rate is a decimal string.

rates = {item["currency"]: item["rate"] for item in data["rates"]}
print(f"1 USD = {rates['IDR']} IDR")

Output:

1 USD = 18038.7 IDR

Convert an amount

Call GET /v1/fx/convert with from, to and amount. The amount is a decimal string, and the response gives the rate used and the converted amount.

response = requests.get(
    f"{API}/fx/convert",
    params={"from": "USD", "to": "IDR", "amount": "100"},
    headers=HEADERS,
    timeout=30,
)
response.raise_for_status()
result = response.json()
print(f"100 USD = {result['converted']} IDR")

Output:

100 USD = 1803870.00 IDR

The response:

{
  "from": "USD",
  "to": "IDR",
  "rate": "18038.70",
  "converted": "1803870.00",
  "market_session": "open",
  "timestamp": "2026-10-26T23:59:59Z",
  "stale": false
}

Get historical rates

Call GET /v1/fx/rates/{base}/observations for daily history. It needs currencies, start_date and end_date, with both dates included, in YYYY-MM-DD format.

response = requests.get(
    f"{API}/fx/rates/USD/observations",
    params={"currencies": "IDR", "start_date": "2026-10-20", "end_date": "2026-10-23"},
    headers=HEADERS,
    timeout=30,
)
response.raise_for_status()
for day in response.json()["observations"]:
    print(day["date"], day["rates"][0]["rate"])

Output:

2026-10-20 17985.4
2026-10-21 18042.7
2026-10-22 18075.8
2026-10-23 18107.8

The response, trimmed to three of the four days:

{
  "base": "USD",
  "observations": [
    { "date": "2026-10-20", "rates": [{ "currency": "IDR", "rate": "17985.4" }] },
    { "date": "2026-10-21", "rates": [{ "currency": "IDR", "rate": "18042.7" }] },
    { "date": "2026-10-22", "rates": [{ "currency": "IDR", "rate": "18075.8" }] }
  ],
  "next_cursor": null
}

A page holds up to 366 days (limit, default 100). When next_cursor is not null, pass it as cursor with the same other parameters to get the next page.

Handle errors

Errors use problem JSON with a code field. Read the errors guide for the full list of codes.

Status Code What to do
401 unauthenticated The key is wrong or revoked. Replace it.
429 See code You reached the per-minute limit or the monthly limit of your plan. Wait, or change plan.

Every 429 includes a Retry-After header. Fix the key before retrying a 401. Retry timeouts and server errors with a short wait that doubles each time.

import time

def get_with_retry(path, params, tries=3):
    for attempt in range(tries):
        try:
            response = requests.get(f"{API}{path}", params=params, headers=HEADERS, timeout=10)
        except (requests.Timeout, requests.ConnectionError):
            if attempt == tries - 1:
                raise
            time.sleep(2 ** attempt)
            continue
        if response.status_code >= 500 and attempt < tries - 1:
            time.sleep(2 ** attempt)
            continue
        response.raise_for_status()
        return response.json()

A successful retry counts as one request.

Cache the result

Most pages and scripts can reuse a rate for a minute. Cache the last response so repeat lookups do not make another API call or incur another charge.

cache = {}

def cached_rate(base, quote, seconds=60):
    hit = cache.get((base, quote))
    if hit and time.time() - hit[0] < seconds:
        return hit[1]
    data = get_with_retry(f"/fx/rates/{base}", {"currencies": quote})
    rate = data["rates"][0]["rate"]
    cache[(base, quote)] = (time.time(), rate)
    return rate

Common questions

How many requests do I get

The Free plan has 3,000 successful requests a month. Starter has 20,000, Basic has 100,000 and Pro has 1,000,000. Failed requests do not count.

Can I try it before paying

Yes. Sign up for the Free plan, which needs no card.

Why are rates strings and not numbers

Rates and amounts are decimal strings to preserve their digits. Use Python's Decimal for calculations.

How do I get more than one currency

Pass the codes to currencies separated by commas, for example IDR,EUR. Leave the parameter out to get every currency.

How much history can I get in one call

Up to 366 days per page. Use next_cursor to read the next page.

Next steps

  • Browse every endpoint in the currencies reference.
  • Compare options in free exchange rate APIs.
  • Make your first call from the quickstart.

Next steps

  • DocumentationQuickstart: your first request→
  • API referenceEvery endpoint, parameter and response field→
  • PricingPlans and limits→
  • DocumentationErrors and limits→

Start with a free key

3,000 requests a month, no card needed.

Sign-ups paused ↗
  • Other MCP clientsServer address and key

Guides

How to get exchange rates in PythonHow to get stock prices in PythonHow to get stock prices in JavaScriptHow to get stock prices in ExcelHow to get stock prices in Google SheetsBeta and cost of equity in Excel
dino.markets

Stocks, currencies, commodities and economics through one API.

APIs

StocksCryptoCommoditiesCurrenciesEconomicsCoverage

Docs

QuickstartAPI referenceMCP serverllms.txtChangelog

Resources

GuidesUse casesCompareAll APIs

Support

PricingAboutSupport
© 2026 Nusantara Ventures, LLC
TermsAcceptable usePrivacy