Open Source Exchange Rates API & money.js

December 20, 2011

The Open Source Exchange Rates API is a free API that provides exchange rates for 120+ currencies relative to USD. Historical exchange rates that go back as far as 1999 are available via the API. Data is collected from the Yahoo! Finance API and is updated hourly.

Get started with Rise Vision

Going hand-in-hand with the Exchange Rates API is money.js, a JavaScript library for realtime currency conversion. It can convert to and from any currency, provided you have the exchange rates (which you can get from the Exchange Rates API). You only need exchange rates relative to one single currency to be able to convert between any others.

Using money.js is easy. Start by downloading it from here, or you can download a minified version from here. Then, include it in your Javascript, ensuring that you replace the value of the src attribute with the correct path:

<script src="path/to/money.js"></script>

Next you'll need some exchange rates, and a base currency, if you want to be able to do currency conversions. The latest rates will be returned as JSON. As previously mentioned, the base rate used by this API is USD. money.js stores rates in the fx.rates object, while the base currency is stored in fx.base. You'll need to configure these before performing any conversions:

fx.base = "USD";
fx.rates = {
/* Set to the rates returned by the Exchange Rates API */
}

Once you have the exchange rates and your base currency set, you can convert currencies to your heart's content:

fx.convert(1000, {from: "USD", to: "GBP"});

It would be an interesting project to take these components and build a digital signage open source Gadget. Please be sure to let us know in the forum if you decide to give it a try!