Class: Cryptoexchange::Exchanges::Lykke::Services::Market

Inherits:
Services::Market show all
Defined in:
lib/cryptoexchange/exchanges/lykke/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)


6
7
8
# File 'lib/cryptoexchange/exchanges/lykke/services/market.rb', line 6

def supports_individual_ticker_query?
  false
end

Instance Method Details

#adapt(ticker_output, market_pair) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cryptoexchange/exchanges/lykke/services/market.rb', line 41

def adapt(ticker_output, market_pair)
ticker           = Cryptoexchange::Models::Ticker.new
ticker.base      = market_pair.base
ticker.target    = market_pair.target
ticker.market    = Lykke::Market::NAME
ticker.bid       = NumericHelper.to_d(ticker_output['bid'])
ticker.ask       = NumericHelper.to_d(ticker_output['ask'])
ticker.last      = NumericHelper.to_d(ticker_output['lastPrice'])
ticker.volume    = NumericHelper.divide(NumericHelper.to_d(ticker_output['volume24H']), ticker.last)
ticker.timestamp = nil
ticker.payload   = ticker_output
ticker
end

#adapt_all(output, pairs_dictionary) ⇒ Object



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

def adapt_all(output, pairs_dictionary)
  output.map do |ticker|
    next unless pairs_dictionary.any?{|match| match["id"] == ticker["assetPair"]}
    pair_object = pairs_dictionary.select{|pair| pair["id"] == ticker["assetPair"]}
    base = pair_object[0]["baseAssetId"]
    target = pair_object[0]["quotingAssetId"]
    market_pair = Cryptoexchange::Models::MarketPair.new(
                    base: base,
                    target: target,
                    market: Lykke::Market::NAME
                  )
    adapt(ticker, market_pair)
  end.compact
end

#dictionary_urlObject



22
23
24
# File 'lib/cryptoexchange/exchanges/lykke/services/market.rb', line 22

def dictionary_url
  "#{Cryptoexchange::Exchanges::Lykke::Market::API_URL}/AssetPairs/dictionary"
end

#fetchObject



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

def fetch
  output = super(ticker_url)
  pairs_output = HTTP.get(dictionary_url)
  pairs_dictionary = JSON.parse(pairs_output.to_s)
  adapt_all(output, pairs_dictionary)
end

#ticker_urlObject



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

def ticker_url
  "#{Cryptoexchange::Exchanges::Lykke::Market::API_URL}/Market"
end