SDKs
JavaScript/Typescript
User Methods
Market
Rates

Exchange Rates

Returns a list of current or historical exchange rates for a range of currencies. Historical exchange rates are updated daily (one rate is maintained for the day). The current exchange rates are updated every 5 minutes.

All parameters are optional, if no parameters are provided the latest exchange rates for the current day are returned.

The base currency is the currency that the exchange rates are relative to. For example, if the base currency is set as GBP and the exchange rates requested are for USD and EUR, then the returned rates will be GBP/USD and GBP/EUR.

The base currency can be any currency supported by the API and defaults to USD.

Usage

import { ExchangeRates } from '@tradrapi/trading-sdk';
 
const rates: ExchangeRates = await tradrApi.markets.rates({
  // The date from which to get exchange rates, defaults to today (ISO 8601 format)
  from: '2023-07-09',
  // The date to which to get exchange rates, defaults to today (ISO 8601 format)
  to: '2023-07-09',
  // The base currency to return the exchange rates for (ISO 4217 format)
  base: 'USD',
  // The list of currencies to return the exchange rates for
  currencies: ['GBP', 'SEK'],
});

Response

interface ExchangeRates {
  // The date from which the exchange rates are for
  from: string;
  // The date to which the exchange rates are for
  to: string;
  // The base currency (ISO 4217 format)
  base: string;
  // The rates for each data, the key is the date in ISO 8601 format
  rates: {
    '2023-07-08': {
      GBP: 0.123,
      SEK: 0.456,
    },
    '2023-07-09': {
      GBP: 0.122,
      SEK: 0.454,
    },
  };
}

To fetch the current exchange rates, omit the from and to parameters to the same date:

import { ExchangeRates } from '@tradrapi/trading-sdk';
 
const currentRates: ExchangeRates = await tradrApi.markets.rates({
  // The base currency to return the exchange rates for (ISO 4217 format)
  base: 'USD',
  // The list of currencies to return the exchange rates for
  currencies: ['GBP', 'SEK'],
});