Looking for a free online currency exchange rate service

February 9th, 2010 | by Sean |

There are plenty of webpages where you can get foreign exchange rate information, like XE.com and OANDA, but those are heavyweight pages intended for human use. Those same sites offer real-time exchange rate data, but for fairly hefty charges. What I wanted was a simple feed with just the bare minimum of information to update my e-commerce application’s internal exchange rates. The application itself is not forex dealing, so it doesn’t require up-to-the-minute rates, daily would be good enough.

Xurrency.com

Xurrency.com

The first site I found that actually looked like they were trying to provide what I wanted was Xurrency.com. They have an API for programmers who use SOAP in their applications (not me, I’m a SOAP-dodger!). They also provide an RSS feed (although they use the wrong Content-Type in their headers – it’s served as text/html when it should be application/rss+xml) for specific exchange rate queries. This was almost what I wanted, but still looked a little bit ‘overweight’ – and Xurrency only provide free access for non-commercial use.

ECB

European Central Bank

After a little more searching I found that the European Central Bank (ECB) provide daily exchange rates against the Euro from their website. The updates are in several different formats and historical rates are also available. This is perfect for my needs. One small wrinkle is that their simplest format is published as a zipped CSV (Comma-Separated Values) file. I wonder why they do that, as their separator is not a comma (as per the RFC4180 standard), it’s a comma-space pair. The file is only slightly shorter zipped (448 bytes zipped against 465 unzipped), when it would be much shorter if they just omitted the spaces – only 397 bytes. They could save bandwidth and possibly the lives of several ponies worldwide if all the systems that downloaded the file did not have to unzip it.

I’ve written some preliminary code for handling currencies and exchange rates, I’ll try to get a demo online later. The preliminary code is online at spider.my on its Currency Conversion page. There’s also an example of what I’d originally hoped to find: a bare-bones plain-text exchange rate service. Here, for example, is the UK Pounds Sterling (GBP) – US Dollar (USD) rate. The ‘filename’ part of the URL specifies the pair of currencies. The response contains only the raw text that is the exchange rate.

Update 9th February 2010: ECB’s server sends the CSV rates file with a Last-Modified header – which is great – but I’m currently falling foul of caching. I dimly remember something in the HTTP standard which says User-Agents may serve content from their own cache if they ‘expect’ it to have not yet expired. That’s not the clearest explanation of a heuristic ever! If I understand it correctly, my User-Agent may not be fetching this afternoon’s rates if it cached (Last-Modified) yesterday’s rates in a testing session only a few minutes ago: it would consider them ‘fresh’ for a few hours.

My application has built-in safeguards against too-frequent requests from ECB’s server, so I added the “Pragma: no-cache” header line to the request for the rates file. That seems to defeat any local User-Agent’s ‘freshness’ heuristics nicely.

Post a Comment