Wednesday, July 22nd, 2009, 11:45 am | Computer, Hacking, Information, Internet, Programming, Software

Currency Exchange Rates API

There are so many websites out there who can calculate Currency Exchange Rates for you, e.g. Google Search, Bing Search or Yahoo Currency Converter. But what if you just want to have the exchange rate to use in your Desktop or Web Application? It would be kinda troublesome to extract the rate from one of the websites above, especially when they decide to change the layout of their HTML code.

That’s why I decided to create a very simple Currency Exchange Rates API. This API allows you to either get the conversion rate from US Dollar to your desired currency or can directly convert an entered value. The output is plain text, without HTML or XML attributes for easy access from all sources.

How does it work?

Just call the URL of the API with your desired exchange rate as parameter, e.g.

for Euro. This will return the exchange rate from USD to EUR:

currencyapi01

Which currencies are supported?

All in all, 126 different currencies are supported. See a list of all supported currencies on the index page.

Are the values up-to-date?

The API updates itself once an hour, so the values you’re getting may be up to 1h old. This should be good enough since these values are for information purposes only.

How can I use the API on my website?

This example shows how to use the API to display 100$ in € (please replace the & stuff in the URL with a normal &, can’t display it correctly here):

$amount = 100; // amount in your original currency, e.g USD

$oricurr = "USD" // iso code for your original currency

$newcurr = "EUR" // iso code for your new currency

$url = "http://www.multimolti.com/apps/currencyapi/calculator.php?original=".$oricurr."&target=".$newcurr."&value=".$amount;

$result = file_get_contents($url);

echo $result." ".$newcurr;

How does the calculator work?

The calculator works almost the same way as the API itself. Call calculator.php with three parameters: original, target and value. original and target are ISO codes of the currency, and value is the amount of orignal currency to convert. The output is the corresponding amout of target currency.

currencyapi02

How accurate are the values?

The acuracy of the exchange rates can’t be guaranteed. All values are for informational purposes only. See the footer of the index page for more information.

Mirrors (most recent list):

Please use multimolti.com or sann-gmbh.com since they’re the most stable ones!

Websites using the Currency Exchange Rates API:

If there are any questions about the API, bug reports or feature requests, please feel free to comment!

VN:F [1.0.7_345]
Rating: 8.3/10 (12 votes cast)



21 Responses to “Currency Exchange Rates API”

  1. det Says:

    been looking for something like this, but im not sure how to use it, though…

    would you please be so kind to provide an example of how to use this on wordpress?

    thanks a lot

    VA:F [1.0.7_345]
    Rating: 5.0/5 (2 votes cast)
  2. Lennart Moltrecht (admin) Says:

    Well, this API is actually for automatic usage. You could use it in your theme somehow like this:
    < ?
    $amount = 100; // amount in your original currency, e.g USD
    $oricurr = "USD" // iso code for your original currency
    $newcurr = "EUR" // iso code for your new currency
    $url = "http://www.lennart-moltrecht.com/apps/currencyapi/calculator.php?original=".$oricurr."&target=".$newcurr."&value=".$amount;
    $result = file_get_contents($url);

    echo $result." ".$newcurr;
    ?>
    This will output the current amount of 100 USD in EUR every time a visitor visits your website.

    VN:F [1.0.7_345]
    Rating: 5.0/5 (2 votes cast)
  3. det Says:

    wow! that was fast!

    i’ll try and see how it goes

    THANK YOU!

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  4. Lennart Moltrecht (admin) Says:

    Oh, you have to replace the first line of my code, it says “< ?” there, actually no space should be between < and ?, but my WordPress put it there automatically.
    If it doesn’t work, try using “<?php” instead of “<?”.

    VN:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  5. det Says:

    i’m using it, and is working like a charme.. i’ve tried to paste the code im using, but somehow i think i get rejected

    any way, i was having an overload on my server, yesterday august the 3rd between 1pm and 4pm of my local time (-3gmt)…

    i know that it could’nt possible be this, but, was your site down by any chance?

    thank you

    VA:F [1.0.7_345]
    Rating: 4.0/5 (1 vote cast)
  6. Lennart Moltrecht (admin) Says:

    Cool that you’re using my API =)

    And yeah, it was probably my site that was down… the server is really shit, i have to get a newer and faster one soon…

    VN:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  7. det Says:

    is there a way i can help?

    i don’t know how does the api work exactly, but if it’s just a couple of php files retrieving info from another server, i can host it for my own so i don’t use your bandwidth…

    this is such a fine solution that i refuse to believe that it could be causing problems on my site….

    thanks!

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  8. Lennart Moltrecht (admin) Says:

    no, its actually a very easy PHP script. it just needs around 10kb webspace and a mysql database. i can send you the files if you want to host them, bandwidth shouldnt be a problem since it usually only sends around 5 characters…

    VN:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  9. det Says:

    if you are kind enough to do that, i’ll try to set up a mirror and see if the issues i had was because of this…

    of course, if everything is working ok, i’ll let you know and you can use it as a mirror…

    you’ve got my email…

    thank you!!

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  10. Lennart Moltrecht (admin) Says:

    Sent you a mail… Is http://noticiasaudio.com/ the website you’re using the API with? Can you tell me where? And can I link your website on the API’s page to show which sites are using it already?

    VN:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  11. Nathan Says:

    I may seem like a noob but how do I use this on my own site? What should the HTML look like when I use it on a normal website?

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  12. Lennart Moltrecht (admin) Says:

    @Nathan:
    Well, you will only be able to use this in combination with PHP. You may also just include the exchange rate with an iFrame, but that wouldn’t be that useful, I guess.
    I added an example of how to use this API with PHP above, hope it helps you. If there are more questions, feel free to ask.

    VN:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  13. doma Says:

    using this with a combination of filemaker and java, works like a charm. thanks alot

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  14. Guri Says:

    It Works gr8.
    I will post a little Script for them who wanna Convert 1 EUR to USD GBP and CHF Sure u can change Original and Target as u want and implement them on ur site as u want :D

    Here is a little Script ..

    5)
    {

    $USD = substr(”$usd1″, 0, -8);
    }

    $gbp1 = file_get_contents(’http://www.lennart-moltrecht.com/apps/currencyapi/calculator.php?original=EUR&target=GBP&value=1′);

    if(strlen($gbp1) > 5)
    {

    $GBP = substr(”$gbp1″, 0, -8);
    }

    $chf1 = file_get_contents(’http://www.lennart-moltrecht.com/apps/currencyapi/calculator.php?original=EUR&target=CHF&value=1′);

    if(strlen($chf1) > 5)
    {

    $CHF = substr(”$chf1″, 0, -8);
    }

    ?>

    It Will Look Like This:

    1.499
    0.909
    1.507

    So u can add any Layout or anything u want in the HTML Code ..

    Thank You for ur script

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  15. Guri Says:

    Hmmm sorry here is the code one more time ..

    5)
    {

    $USD = substr(”$usd1″, 0, -8);
    }

    $gbp1 = file_get_contents(’http://www.lennart-moltrecht.com/apps/currencyapi/calculator.php?original=EUR&target=GBP&value=1′);

    if(strlen($gbp1) > 5)
    {

    $GBP = substr(”$gbp1″, 0, -8);
    }

    $chf1 = file_get_contents(’http://www.lennart-moltrecht.com/apps/currencyapi/calculator.php?original=EUR&target=CHF&value=1′);

    if(strlen($chf1) > 5)
    {

    $CHF = substr(”$chf1″, 0, -8);
    }

    ?>

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  16. Guri Says:

    Im sorry it dont shows the whole code.
    u can download the code from here

    http://www.file-upload.net/download-2045508/exchange.zip.html

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  17. Lennart Moltrecht (admin) Says:

    Thanks for your code!

    VN:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  18. Lennart Moltrecht (admin) Says:

    @Guri:
    Just a small addition, please don’t use lennart-moltrecht.com as host, rather use this domain (multimolti.com) since it’s more stable and thus your website will work better!

    VN:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  19. Guri Says:

    @Lennart Moltrecht:

    Thank You . I will change it.

    Kind Regards,
    Guri

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  20. Carsten Sann Says:

    Hi!

    I am also interested in hosting a mirror … can you send me the files, too?

    Best wishes
    Carsten

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  21. Lennart Moltrecht (admin) Says:

    Done, thanks for your mirror! I added it to the list!

    VN:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)

Leave a Reply

ss_blog_claim=c7d0757dcb48491268e39569f229169b ss_blog_claim=c7d0757dcb48491268e39569f229169b