Get currency exchange rates from the Reserve Bank of Australia
Retrieves exchange rates from the Reserve Bank of Australia's exchange rate datasets. Base currency is always AUD.
All datasets are cached after being downloaded for quick retrieval, and each dataset covers multiple years. Exchange rate data goes back to December 1983. A maximum of 11 datasets will be downloaded, totalling about 6MB. Datasets are only downloaded as needed, so you will likely only ever download one dataset (each dataset covers 3 - 4 years).
Some currencies are not available through the entire 1983 – current datasets, double check RBA datasets for if the specified currency is available throughout the required period. USD is available for the entire dataset period, excluding non-business days.
npm install exchange-rates-rba
import getExchangeRate from 'exchange-rates-rba';
await getExchangeRate('USD', new Date(2023, 1, 22));
//=> 0.6789
await getExchangeRate('JPY', new Date(2017, 1, 1), { defaultToClosestPriorRate: true });
//=> 128.12
await getExchangeRate('USD', new Date(2023, 0, 1);
// => 0.6929
await getExchangeRate('USD', new Date(2023, 0, 1), { defaultToNull: true });
// => null
Returns a Promise that resolves to the currency
's exchange rate with AUD.
If an exchange rate is not available on a given date, the closest exchange rate after the date will be provided. If there is a gap of greater than 7 days between the closest exchange rate and the date provided, null
will be returned.
See below options to instead provide the closest rate before the date, or return null
if no rate is available on the given date.
Type: string
Must be one of the following currency codes:
USD, TWI, CNY, JPY, EUR, KRW, GBP, SGD, INR, THB, NZD, TWD, MYR, IDR, VND, AED, PGK, HKD, CAD, ZAR, CHF, PHP, SDR
TWI is the trade-weighted index.
Type: Date object
Date to retrieve exchange rate for.
Type: object
Type: boolean
Default: false
If no exchange rate is available for the given date, the closest available rate prior to the given date will be provided.
Type: boolean
Default: false
If no exchange rate is available for the given date, null
will be returned.