Class: Mcoin::Market::Kraken

Inherits:
Base
  • Object
show all
Defined in:
lib/mcoin/market/kraken.rb

Overview

:nodoc:

Constant Summary collapse

ENDPOINT =

rubocop:disable Metrics/LineLength

'https://api.kraken.com/0/public/Ticker?pair=%<type>s%<currency>s'

Instance Method Summary collapse

Methods inherited from Base

#name, #uri

Constructor Details

#initialize(type, currency) ⇒ Kraken

Returns a new instance of Kraken.



10
11
12
13
# File 'lib/mcoin/market/kraken.rb', line 10

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

Instance Method Details

#fetchObject



27
28
29
30
31
32
# File 'lib/mcoin/market/kraken.rb', line 27

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

#swap_btc(type) ⇒ Object



34
35
36
37
38
# File 'lib/mcoin/market/kraken.rb', line 34

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

#to_tickerObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mcoin/market/kraken.rb', line 15

def to_ticker
  fetch
  Data::Ticker.new(
    :Kraken,
    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