ECBExchangeRatesApi

This is an unofficial wrapper for the awesome, free ExchangeRatesAPI, which provides exchange rate lookups courtesy of the European Central Bank.

Gem Version Build Status

Installation

Add this line to your application's Gemfile:

gem 'ecb_exchange_rates_api'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install ecb_exchange_rates_api

Getting Started

Since the CurrencyExchangeAPI does not require API keys or authentication in order to access and interrogate its API, getting started with this library is easy. The following examples show how to achieve various functions using the library.

Basic usage:

Fetch the latest exchange rates from the European Central Bank:

client = ECBExchangeRatesApi::Client.new 
client.fetch

Historical data:

Get historical rates for any day since 1999:

client.at("2010-09-21").fetch

or specify some date range:

client.from("2010-09-21").to("2010-10-21").fetch

Set the base currency:

By default, the base currency is set to Euro (EUR), but it can be changed:

client.with_base("USD").fetch

currency code should be passed as an ISO 4217 code.

Fetch specific rates:

If you do not want all current rates, it's possible to specify only the currencies you want using with for_rate(symbol) or for_rates(array_of_symbols). The following code fetches only the exchange rate between GBP and EUR:

client.with_base("GBP").for_rate("EUR").fetch

Convert

It is useful not just to check the exchange rates but also to calculate the amount of money for them. This is the case where the convert method comes into play. You can specify options with the method arguments convert(amount, base, symbols, specific_data) or use the preconfigured client as follow:

client.convert(100, "USD", %w(EUR SEK), "2018-02-01")
#or
base_client = ECBExchangeRatesApi::Client.new do |c|
  c.with_base "USD"
  c.for_rates %w(EUR SEK)
  c.at "2018-02-01"
end
base_client.convert(100)

Please refer to the API website for further information and full API docs.

Supported Currencies:

The library supports any currency currently available on the European Central Bank's web service, which at the time of the latest release are as follows:

Australian Dollar (AUD)
Brazilian Real (BRL)
British Pound Sterline (GBP)
Bulgarian Lev (BGN)
Canadian Dollar (CAD)
Chinese Yuan Renminbi (CNY)
Croatian Kuna (HRK)
Czech Koruna (CZK)
Danish Krone (DKK)
Euro (EUR)
Hong Kong Dollar (HKD)
Hungarian Forint (HUF)
Icelandic Krona (ISK)
Indonesian Rupiah (IDR)
Indian Rupee (INR)
Israeli Shekel (ILS)
Japanese Yen (JPY)
Malaysian Ringgit (MYR)
Mexican Peso (MXN)
New Zealand Dollar (NZD)
Norwegian Krone (NOK)
Philippine Peso (PHP)
Polish Zloty (PLN)
Romanian Leu (RON)
Russian Rouble (RUB)
Singapore Dollar (SGD)
South African Rand (ZAR)
South Korean Won (KRW)
Swedish Krona (SEK)
Swiss Franc (CHF)
Thai Baht (THB)
Turkish Lira (TRY)
US Dollar (USD)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/overchind/ECBExchangeRatesApi. This project is intended to be a safe, welcoming space for collaboration.

License

The gem is available as open source under the terms of the MIT License.