-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ratesapi.io is dead #12
Comments
You can switch to an alternative working service like so - await exchangeRates().setApiBaseUrl('https://api.exchangerate.host'). |
Thank you for the solution, can confirm this does work. Would be good to build in automatic retry on alternative hosts in case this host also goes down |
Is that issue solved? |
Hey @Wild-storm999, Unfortunately this isn't resolved yet. I'll get to it if I get some spare time over the weekend. In the meantime, you can switch to an alternative service (see Using a different API) like so: const { exchangeRates } = require('exchange-rates-api');
/* You can use it with pretty much any Fixer.io-compatible API */
(async () => {
await exchangeRates()
.setApiBaseUrl('https://api.exchangerate.host')
.latest()
.fetch(); // {THB: 34.978, PHP: 58.159, …, HUF: 323.58}
})(); |
Thanks for your reply. |
@Wild-storm999 You can't use a different API with This will be included in the next version (see Version 1.2 Milestone). However, you can use the following workaround: const { exchangeRates } = require('exchange-rates-api');
/**
* Convert the given amount from one currency to another using the exchange rate of the given date
*
* @param {number} amount The amount to convert
* @param {string} fromCurrency Which currency to convert from
* @param {string} toCurrency Which currency to convert to
* @param {Date|string} [date='latest'] The date to request the historic rate
* (if omitted, defaults to 'latest')
* @return {number} The converted amount
*/
const convert = (amount, fromCurrency, toCurrency, date = 'latest') => {
if (typeof amount !== 'number') {
throw new TypeError('The \'amount\' parameter has to be a number');
}
if (Array.isArray(toCurrency)) {
throw new TypeError('Cannot convert to multiple currencies at the same time');
}
const instance = new ExchangeRates();
instance.setApiBaseUrl('https://api.exchangerate.host');
if (date === 'latest') {
instance.latest();
} else {
instance.at(date);
}
return instance
.base(fromCurrency)
.symbols(toCurrency)
.fetch()
.then((rate) => rate * amount);
}; You can replace instance.setApiBaseUrl('https://api.exchangerate.host'); with the API you want to use. Then, you can invoke (async () => {
let amount = await convert(2000, 'USD', 'EUR', '2018-01-01');
console.log(amount); // 1667.6394564000002
})(); |
When v1.2 will be available? |
Exchangerate package is still not working as still its pointing to https://api.ratesapi.io could you please confirm when fix will be available as I need to use convert function |
@over-engineer : Exchangerate package is still not working as still its pointing to https://api.ratesapi.io/ I have changed code in npm module exchange-rates-api to replace the base url . Its all good in my local version but the moment I am deploying my code - its not taking the changed code and running through https://api.ratesapi.io/, hence giving error. I am using SAP CAP using nodejs and deploying my code to HANA cloud where its giving error. Local version is working fine. Could you please guide me how to fix this issue so that it takes custom code in npm module. |
https://api.ratesapi.io no longer works, please change it.
The text was updated successfully, but these errors were encountered: