Class: Cryptoexchange::Exchanges::Liqui::Services::Market

Inherits:
Services::Market show all
Defined in:
lib/cryptoexchange/exchanges/liqui/services/market.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Services::Market

#fetch_using_post

Class Method Details

.supports_individual_ticker_query?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/cryptoexchange/exchanges/liqui/services/market.rb', line 8

def supports_individual_ticker_query?
  true
end

Instance Method Details

#adapt(output, market_pair) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cryptoexchange/exchanges/liqui/services/market.rb', line 23

def adapt(output, market_pair)
  handle_invalid(output)
  market = output["#{market_pair.base}_#{market_pair.target}".downcase]

  ticker = Cryptoexchange::Models::Ticker.new
  ticker.base      = market_pair.base
  ticker.target    = market_pair.target
  ticker.market    = Liqui::Market::NAME
  ticker.last      = NumericHelper.to_d(market['last'])
  ticker.bid       = NumericHelper.to_d(market['buy'])
  ticker.ask       = NumericHelper.to_d(market['sell'])
  ticker.high      = NumericHelper.to_d(market['high'])
  ticker.low       = NumericHelper.to_d(market['low'])
  ticker.volume    = NumericHelper.to_d(market['vol_cur'])
  ticker.timestamp = NumericHelper.to_d(market['updated'])
  ticker.payload   = market
  ticker
end

#fetch(market_pair) ⇒ Object



13
14
15
16
# File 'lib/cryptoexchange/exchanges/liqui/services/market.rb', line 13

def fetch(market_pair)
  output = super(ticker_url(market_pair))
  adapt(output, market_pair)
end

#handle_invalid(output) ⇒ Object



42
43
44
45
46
# File 'lib/cryptoexchange/exchanges/liqui/services/market.rb', line 42

def handle_invalid(output)
  if output['success'] == 0
    raise Cryptoexchange::ResultParseError, { response: output }
  end
end

#ticker_url(market_pair) ⇒ Object



18
19
20
21
# File 'lib/cryptoexchange/exchanges/liqui/services/market.rb', line 18

def ticker_url(market_pair)
  market = "#{market_pair.base}_#{market_pair.target}".downcase
  "#{Cryptoexchange::Exchanges::Liqui::Market::API_URL}/ticker/#{market}"
end