Posted: 15th July 2014

Author: Ric

Tagged: Tutorials

Alternative to Google's currency conversion API

It's just been brought to my attention that Google closed their currency conversion API last November. Frustratingly a lot of the international websites that I've built in the past have made use of this API in some way, so I needed a quick fix. In the end this came in the form of rate-exchange.appspot.com who provide an API almost identical to the old Google service.

If your Google API call looked something like this:

http://www.google.com/ig/calculator?q=1USD=?EUR

Then the rate-exchange equivalent is this:

http://rate-exchange.appspot.com/currency?from=USD&to=EUR&q=1

And here's how you can use it from within a PHP script:

$baseCurrency = 'USD';
$currency = 'EUR';
$amount = 1;

$currencyAPIHandle = curl_init();
curl_setopt($currencyAPIHandle, CURLOPT_URL, 'http://rate-exchange.appspot.com/currency?from='.urlencode($baseCurrency).'&to='.urlencode($currency).'&q='.$amount);
curl_setopt($currencyAPIHandle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($currencyAPIHandle, CURLOPT_CONNECTTIMEOUT, 0);
$currencyAPIReturn = curl_exec($currencyAPIHandle);
curl_close($currencyAPIHandle);
$priceData = json_decode($currencyAPIReturn);
$price = $priceData->v;

If this is as useful to you as it is me, please consider donating towards their service.

Blog posts written by former QWeb employees are not necessarily an accurate indication of the current opinions of QWeb Ltd and the information provided in tutorials might be biased or subjective, or might become out of date.

Discuss this post

Muhammad Reda
13/07/2015 16:19

Link is broken (http://rate-exchange.appspot.com/currency). The app no longer exists.
You can use Currency API instead https://currency-api.appspot.com/

Ric
13/07/2015 16:57

Thanks Muhammad,

We noticed this was broken but weren’t too keen on the alternatives, so we built our own! You’re welcome to use this one too: http://rates.egg-basket.com/

Biranchi
21/01/2017 08:35

Ric Grant, its working great.

I tried to convert from usd to sar with the below request,
http://rates.egg-basket.com/exchange?from=usd&to=sar&amount=1

but i didn’t receive any response.

It would be great if more currencies are supported.

Ric
23/01/2017 09:39

Hi Biranchi,

We’ve added SAR to the supported currencies now, so the above conversion should work for you =).

Beckley
10/09/2018 00:33

I've also tried to convert from usd to ngn (Nigerian Naira) but didn't get any response. Have you considered adding the NGN? Thanks.

Ric
10/09/2018 10:40

Sorry Beckley, it looks like the services that our rates API relies on have made some changes recently that's preventing our system from updating its rates. I'm afraid the current exchange rates returned are therefore out of date and we're unable to add new currencies in at this time.

Working on a resolution and will post back here when we have one!

Ric
10/09/2018 12:07

Scrap that, sometimes we get things done faster than expected!

The issue found a couple of hours ago is now resolved - we're back up and running thanks to new data providers.

Added in the NGN currency as requested, and also moved the service to https (still available via http, but I'd encourage that you update your scripts to make https calls where possible). Also tidied up the information page inline with our new branding: https://rates.egg-basket.com/

Leave a comment

Your email address is used to notify you of new comments to this thread, and also to pull your Gravatar image. Your name, email address, and message are stored as encrypted text and you won't be added to any mailing list and your details won't be shared with any third party.