Members
Methods
_buildUrl() → {string}
Build and return the url to request
Returns:
- Type:
-
string
The url to request
_isHistoryRequest() → {boolean}
Determine whether this request should call the /history endpoint or not
Returns:
- Type:
-
boolean
Whether this a history request or not
_validate()
Throw an error if any of our validations fails
Throws:
-
Will throw an error if any validation fails
- Type
-
ExchangeRatesError
_validateCurrency()
Throw an error if the given currency is not supported
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
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()
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')
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
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
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
Returns:
- Type:
-
ExchangeRates
The instance on which this method was called
symbols(currencies) → {ExchangeRates}
Set symbols to limit results to specific exchange rate(s)
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