Sha256: a333fb05aad4456beab1dedfb806539873723a8c0dad3e59a1aebbd414a5684b

Contents?: true

Size: 862 Bytes

Versions: 1

Compression:

Stored size: 862 Bytes

Contents

module Mcoin
  module Market
    # :nodoc:
    class Kraken < Base
      # rubocop:disable Metrics/LineLength
      ENDPOINT = 'https://api.kraken.com/0/public/Ticker?pair=%<type>s%<currency>s'.freeze

      def initialize(type, currency)
        type = swap_btc(type)
        super
      end

      def to_ticker
        fetch
        Data::Ticker.new(
          swap_btc(@type), @currency,
          last: @data['c'][0],
          ask: @data['a'][0], bid: @data['b'][0],
          low: @data['l'][1], high: @data['h'][1],
          volume: @data['v'][1]
        )
      end

      def fetch
        super
        return self if @data['result'].nil?
        @data = @data.dig('result', "X#{@type}Z#{@currency}")
      end

      def swap_btc(type)
        return :BTC if type == :XBT
        return :XBT if type == :BTC
        type
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mcoin-0.1.0 lib/mcoin/market/kraken.rb