Exchange Rates API module gives some elements to developers to allow their modules to convert from one currency to another.

It uses the Open Exchange Rates API to keep the rates of more than 170 currencies around the world updated.

Here are the 4 main functions of the module:

  • era_rate($from, $to, $date = NULL): To get the rate to convert a currency to another. For example, if you need the rate to convert Canadian Dollars to Euros just use era_rate('CAD', 'EUR').
  • era_convert($amount, $from, $to, $date = NULL): To convert an amount from one currency to another. For example, if you need to convert 5 Bitcoins to Australian Dollars just use era_convert(5, 'BTC', 'AUD').
  • era_get_rates($date = NULL): To get a list of all the rate conversions from a base currency. Currently the base currency is always US Dollar, but don't worry, the module knows the maths needed to convert from any currency to any other.
  • era_get_currencies(): To get a list of all the available currencies. Currently there are more than 170!

The optional $date parameter can receive a date in the format YYYY-MM-DD, or a timestamp that will be converted to that format, and will let you do calculations with historical rates of the given date.

Hooks are also provided to let you alter all these functions information.

You don't have to set up the currency rates because they are always* updated from Open Exchange Rates API. You will need an APP ID, it is free, but they also have paid plans.

Demo: If you want to see this module working, you can install the Android app Cashmeleon, it is a currency conversion app that uses Drupal 7 with Exchange Rates API module as a backend.

* Important notice: The information retrieved from Open Exchange Rates is stored in Drupal's cache**. Setting up the module to store the information in cache for 3 hours will give you approximately 240 calls to Open Exchange Rates API per month, much less than the 1000 requests per month they give you in their free plan. Even refreshing the rates every 1 hour would be enough (~720 requests per month). You can disable the cache, but you will probably need a paid plan.

** Historical Rates information for each day are stored in the Database once they are requested and will never be prompted again. Every request to Open Exchange Rates API for historical rates counts in your monthly usage.

Drupal 8

I, the original developer, don't plan to port this module to Drupal 8. If you want to create a Drupal 8 version just let me know to add you as a co-maintainer.

Drupal 8 users can try Currency module.

Supporting organizations: 
Donated the time and knowledge to develop the module.

Project information

Releases