Sha256: 30a106429ee81167dedff6cca2d13730e6c96723d9c0aa10ed5c2cc5a4b82999
Contents?: true
Size: 1.04 KB
Versions: 3
Compression:
Stored size: 1.04 KB
Contents
module CurrencyRate class BitfinexAdapter < CryptoAdapter FETCH_URL = { 'btc_usd' => 'https://api.bitfinex.com/v1/pubticker/btcusd', 'ltc_usd' => 'https://api.bitfinex.com/v1/pubticker/ltcusd' } DEFAULT_CURRENCIES = ["USD", "BTC"] SUPPORTED_CRYPTO_CURRENCIES = ["BTC", "LTC"] def rate_for(from,to) super rate = rate_to_f(currency_pair_rate(to,from)) invert_rate(from,to,rate) end def currency_pair_rate(currency1, currency2) rate = @rates["#{currency1.downcase}_#{currency2.downcase}"] || @rates["#{currency2.downcase}_#{currency1.downcase}"] raise CurrencyNotSupported unless rate rate['last_price'] end def invert_rate(from,to,rate) if self.class::SUPPORTED_CRYPTO_CURRENCIES.include?(to) _invert_rate(rate) else rate end end def supported_currency_pairs cache_supported_currency_pairs do @rates.each do |k,v| @supported_currency_pairs << k.sub("_", "/").upcase end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
currency-rate-0.4.1 | lib/crypto_adapters/bitfinex_adapter.rb |
currency-rate-0.4.0 | lib/crypto_adapters/bitfinex_adapter.rb |
currency-rate-0.3.9 | lib/crypto_adapters/bitfinex_adapter.rb |