Sha256: 533038c17adf06220ab2ae0412d3a354da8a501626a43c8d2321adc4ceb90b72
Contents?: true
Size: 1.31 KB
Versions: 2
Compression:
Stored size: 1.31 KB
Contents
module CurrencyRate class BitstampAdapter < CryptoAdapter FETCH_URL = { 'btc_usd' => 'https://www.bitstamp.net/api/v2/ticker/btcusd/', 'btc_eur' => 'https://www.bitstamp.net/api/v2/ticker/btceur/', 'ltc_usd' => 'https://www.bitstamp.net/api/v2/ticker/ltcusd/', 'ltc_eur' => 'https://www.bitstamp.net/api/v2/ticker/ltceur/', 'eur_usd' => 'https://www.bitstamp.net/api/v2/ticker/eurusd/' } 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 # Because Bitstamp has USD/EUR pair def invert_rate(from,to,rate) if self.class::SUPPORTED_CRYPTO_CURRENCIES.include?(to) || (from == 'USD' && to == 'EUR') _invert_rate(rate) else rate end end def currency_pair_rate(currency1, currency2) rate = @rates["#{currency1.downcase}_#{currency2.downcase}"] || @rates["#{currency2.downcase}_#{currency1.downcase}"] raise CurrencyNotSupported unless rate rate['last'] 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
currency-rate-0.4.1 | lib/crypto_adapters/bitstamp_adapter.rb |
currency-rate-0.4.0 | lib/crypto_adapters/bitstamp_adapter.rb |