0

Is it possible to get an historical exchange rate using the Concurrency Gem in Ruby on Rails? The current documentation only describe converting as at this moment: Concurrency Gem but it also uses data from Currency Converter API which has historical data available.

The current way of requesting a current exchange rate:

Concurrency.conversion_rate("NZD", "INR")
doer123456789
  • 369
  • 1
  • 7
  • 22

1 Answers1

-1

No, the Concurrency Gem doesn't implement the APIs historical data. It only sets q and not date/endDate as described in the Currency Converter API.

concurrency.rb:

url = "https://free.currencyconverterapi.com/api/v6/convert?q=#{from}_#{to}&compact=ultra&apiKey=#{Concurrency.configuration.api_key}"

You could use Money Historical Bank instead. Here you can use a Timestamp:

require 'money/bank/historical_bank'
mh = Money::Bank::HistoricalBank.new

# Exchanges 1000 EUR to USD using Date.today (default if no date has been entered).
# Will download today's rates if none have been entered
mh.exchange_with(1000.to_money('EUR'), 'USD')

# Exchanges 1000 EUR to USD using historical rates
date = Date.new(2009,9,9)
mh.set_rate(date, 'USD', 'EUR', 0.7634)
mh.exchange_with(date, 1000.to_money('USD'), 'EUR') # => 763.4 EUR

Money.default_bank = mh
hendrixfan
  • 44
  • 3
  • Thanks for your help, however Money Historical Bank doesn't seem to work with historical rates - or at all. Not sure if it has something to do with having to set up API codes for the site which it pulls the data from? I just ended up using REST-Client to pull the data from Currency Converter API, thanks for your help though. – doer123456789 Sep 30 '21 at 08:34