Sha256: a9b4c88989b8e75896bf2c82456df68e72c5d3cdb9f75027b76f8661f6b47392

Contents?: true

Size: 775 Bytes

Versions: 3

Compression:

Stored size: 775 Bytes

Contents

module CurrencyRate
  class BitpayAdapter < CryptoAdapter

    FETCH_URL = 'https://bitpay.com/api/rates'
    DEFAULT_CURRENCIES = ["USD", "BTC"]
    SUPPORTED_CRYPTO_CURRENCIES = ["BTC"]

    def rate_for(from,to)
      super
      rate = nil
      @rates.each do |rt|
        if rt['code'] == to
          rate = invert_rate(from,to, currency_pair_rate(to,from,rt))
          return rate_to_f(rate)
        end
      end
    end

    def currency_pair_rate(currency1, currency2, rt)
      rate = rt['rate'] if [currency1, currency2].include?(rt['code'])
      rate
    end

    def supported_currency_pairs
      cache_supported_currency_pairs do
        @rates.each do |r|
          @supported_currency_pairs << "#{r["code"]}/BTC"
        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/bitpay_adapter.rb
currency-rate-0.4.0 lib/crypto_adapters/bitpay_adapter.rb
currency-rate-0.3.9 lib/crypto_adapters/bitpay_adapter.rb