是否可以使用Ruby on Rails中的并发Gem来获取历史汇率?当前的文档只描述了此时的转换:Concurrency Gem,但它也使用了来自Currency Converter API的数据,该数据具有可用的历史数据。
当前请求当前汇率的方式:
Concurrency.conversion_rate("NZD", "INR")发布于 2021-09-28 18:23:20
不,Concurrency Gem没有实现API历史数据。它只设置q,而不是Currency Converter API中描述的date/endDate。
url = "https://free.currencyconverterapi.com/api/v6/convert?q=#{from}_#{to}&compact=ultra&apiKey=#{Concurrency.configuration.api_key}"您可以改用Money Historical Bank。您可以在此处使用时间戳:
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 = mhhttps://stackoverflow.com/questions/69337668
复制相似问题