How to get historical exchange rate data and time series? #7
Answered
by
cahthuranag
cahthuranag
asked this question in
Q&A
-
|
I need to fetch exchange rates for specific past dates and date ranges for charting. How do I do this? AnswerExchange Rate API supports both single-date historical lookups and date range time series. JavaScript: import { ExchangeRateAPI } from '@exchangerateapi/sdk';
const client = new ExchangeRateAPI({ apiKey: 'era_live_YOUR_KEY' });
// Single date
const data = await client.forDate('2026-01-15', { base: 'USD', symbols: ['EUR', 'GBP'] });
console.log(data.rates); // { EUR: 0.92, GBP: 0.78 }
// Time series (date range)
const series = await client.timeSeries('2026-01-01', '2026-03-31', {
base: 'USD',
symbols: ['EUR'],
});
// Preset periods: 1d, 7d, 30d, 1y
const history = await client.getHistoricalRates('USD', 'EUR', '30d');Python: from exchangerateapi import ExchangeRateAPI
client = ExchangeRateAPI(api_key="era_live_YOUR_KEY")
# Single date
data = client.for_date("2026-01-15", base="USD", symbols=["EUR"])
# Time series
data = client.time_series("2026-01-01", "2026-03-31", base="USD", symbols=["EUR"])
# Preset period
history = client.get_historical_rates("USD", "EUR", "30d")Available preset periods: |
Beta Was this translation helpful? Give feedback.
Answered by
cahthuranag
Jun 21, 2026
Replies: 1 comment
-
|
Exchange Rate API supports both single-date historical lookups and date range time series. JavaScript: import { ExchangeRateAPI } from '@exchangerateapi/sdk';
const client = new ExchangeRateAPI({ apiKey: 'era_live_YOUR_KEY' });
// Single date
const data = await client.forDate('2026-01-15', { base: 'USD', symbols: ['EUR', 'GBP'] });
console.log(data.rates); // { EUR: 0.92, GBP: 0.78 }
// Time series (date range)
const series = await client.timeSeries('2026-01-01', '2026-03-31', {
base: 'USD',
symbols: ['EUR'],
});
// Preset periods: 1d, 7d, 30d, 1y
const history = await client.getHistoricalRates('USD', 'EUR', '30d');Python: from exchangerateapi import ExchangeRateAPI
client = ExchangeRateAPI(api_key="era_live_YOUR_KEY")
# Single date
data = client.for_date("2026-01-15", base="USD", symbols=["EUR"])
# Time series
data = client.time_series("2026-01-01", "2026-03-31", base="USD", symbols=["EUR"])
# Preset period
history = client.get_historical_rates("USD", "EUR", "30d")Available preset periods: |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
cahthuranag
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exchange Rate API supports both single-date historical lookups and date range time series.
JavaScript:
Python: