Sha256: 2e440dc7b1a83e8a531e564e893dbee53f5cd0d4a0056f3f960ae0d61a8a4503

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

module CurrencyRate
  class BtceAdapter < CryptoAdapter

    FETCH_URL = {
      'btc_usd' => 'https://btc-e.com/api/2/btc_usd/ticker',
      'btc_eur' => 'https://btc-e.com/api/2/btc_eur/ticker',
      'btc_rub' => 'https://btc-e.com/api/2/btc_rur/ticker',
      'usd_rub' => 'https://btc-e.com/api/2/usd_rur/ticker',
      'eur_rub' => 'https://btc-e.com/api/2/eur_rur/ticker'
    }
    DEFAULT_CURRENCIES = ["USD", "BTC"]
    SUPPORTED_CRYPTO_CURRENCIES = ["BTC"]


    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['ticker']['last']
    end

    def invert_rate(from,to,rate)
      if self.class::SUPPORTED_CRYPTO_CURRENCIES.include?(to) || (from == 'RUB' && to == 'USD') || (from == 'RUB' && to == 'EUR')
        _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/btce_adapter.rb
currency-rate-0.4.0 lib/crypto_adapters/btce_adapter.rb
currency-rate-0.3.9 lib/crypto_adapters/btce_adapter.rb