Skip to content
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

Open
endnch opened this issue May 20, 2021 · 10 comments
Open

ratesapi.io is dead #12

endnch opened this issue May 20, 2021 · 10 comments
Assignees
Milestone

Comments

@endnch
Copy link

endnch commented May 20, 2021

https://api.ratesapi.io no longer works, please change it.

@kwerty
Copy link

kwerty commented May 26, 2021

You can switch to an alternative working service like so -

await exchangeRates().setApiBaseUrl('https://api.exchangerate.host').

@trent823
Copy link

trent823 commented Jun 2, 2021

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

@over-engineer
Copy link
Owner

@endnch, thanks for letting me know! I'll push an update once I get some spare time (it should hopefully be done in the next days).

@kwerty, thanks for the help with this issue! 😄

@trent823, that's a great idea! I'll try to include this in the next version.

@happyleow
Copy link

Is that issue solved?
I can't use it anymore.

@over-engineer
Copy link
Owner

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}
})();

@happyleow
Copy link

happyleow commented Jun 7, 2021

Thanks for your reply.
In some case, i would like to use convert function.
Maybe i need to set base url first.
How to use it?

@over-engineer
Copy link
Owner

@Wild-storm999 You can't use a different API with convert() yet (see #7).

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 https://api.exchangerate.host in:

instance.setApiBaseUrl('https://api.exchangerate.host');

with the API you want to use.

Then, you can invoke convert() as you would normally do:

(async () => {
    let amount = await convert(2000, 'USD', 'EUR', '2018-01-01');
    console.log(amount);    // 1667.6394564000002
})();

@metalheadcode
Copy link

When v1.2 will be available?

@w48402
Copy link

w48402 commented Nov 21, 2022

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

@w48402
Copy link

w48402 commented Aug 7, 2023

@over-engineer : Exchangerate package is still not working as still its pointing to https://api.ratesapi.io/
I am using this in my app and as per your suggestion I have replaced the baseurl with setApiBaseUrl('https://api.exchangerate.host');

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants