ExchangeRates

exchange-rate-api~ ExchangeRates

ExchangeRates

Constructor

new ExchangeRates()

Source:

Members

url :string

The API url to request

Source:
Type:
  • string

Methods

_buildUrl() → {string}

Build and return the url to request

Source:
Returns:
Type:
string

The url to request

_isHistoryRequest() → {boolean}

Determine whether this request should call the /history endpoint or not

Source:
Returns:
Type:
boolean

Whether this a history request or not

_validate()

Throw an error if any of our validations fails

Source:
Throws:

Will throw an error if any validation fails

Type
ExchangeRatesError

_validateCurrency()

Throw an error if the given currency is not supported

Source:
Throws:

Will throw an error if the given currency doesn't exist in the currencies object

Type
ExchangeRatesError

at(date) → {ExchangeRates}

Set the date to get historical rates for that specific day

Source:
Parameters:
Name Type Description
date Date

The date to request its historical rates

Returns:
Type:
ExchangeRates

The instance on which this method was called

avg(decimalPlacesnullable) → {Promise.<(object|number)>}

Return the average value of each exchange rate for the selected time period To select a time period, create a chain with .from() and .to() before .avg()

Source:
Parameters:
Name Type Attributes Default Description
decimalPlaces number <nullable>
null

If set, it limits the number of decimal places

Returns:
Type:
Promise.<(object|number)>

A Promise that when resolved, returns either an object containing the average value of each rate for the selected time period, or a number if a single date was selected

base(currency) → {ExchangeRates}

Set the base currency (if not explicitly set, it defaults to 'EUR')

Source:
Parameters:
Name Type Description
currency string

The base currency

Returns:
Type:
ExchangeRates

The instance on which this method was called

fetch() → {Promise.<(object|number)>}

Fetch the exchange rates from exchangeratesapi.io, parse the response and return it

Source:
Returns:
Type:
Promise.<(object|number)>

A Promise that when resolved, returns either an object containing the exchange rates, or a number if the response contains a single exchange rate

from(date) → {ExchangeRates}

Set the date from which to request historical rates

Source:
Parameters:
Name Type Description
date Date

The date from which to request historical rates

Returns:
Type:
ExchangeRates

The instance on which this method was called

latest() → {ExchangeRates}

Set the date to get the latest exchange rates

Source:
Returns:
Type:
ExchangeRates

The instance on which this method was called

symbols(currencies) → {ExchangeRates}

Set symbols to limit results to specific exchange rate(s)

Source:
Parameters:
Name Type Description
currencies string | Array.<string>

The currency (or an array of currencies)

Returns:
Type:
ExchangeRates

The instance on which this method was called

to(date) → {ExchangeRates}

Set the date to which to request historical rates

Source:
Parameters:
Name Type Description
date Date

The date to which to request historical rates

Returns:
Type:
ExchangeRates

The instance on which this method was called