Class: Cryptoexchange::Exchanges::Dragonex::Services::Market

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

Constant Summary collapse

SEARCH_TIMESTAMP =
0
COUNT =
1
KLINE_TYPE =
1

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)


12
13
14
# File 'lib/cryptoexchange/exchanges/dragonex/services/market.rb', line 12

def supports_individual_ticker_query?
  true
end

Instance Method Details

#adapt(output, market_pair) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cryptoexchange/exchanges/dragonex/services/market.rb', line 37

def adapt(output, market_pair)
  market           = HashHelper.dig(output, 'data', 'lists').first
  ticker           = Cryptoexchange::Models::Ticker.new
  ticker.base      = market_pair.base
  ticker.target    = market_pair.target
  ticker.market    = Dragonex::Market::NAME
  ticker.high      = NumericHelper.to_d(market[2])
  ticker.low       = NumericHelper.to_d(market[3])
  ticker.last      = NumericHelper.to_d(market[1])
  ticker.volume    = NumericHelper.to_d(market[-1])
  ticker.timestamp = NumericHelper.to_d(market[6])
  ticker.payload   = output
  ticker
end

#fetch(market_pair) ⇒ Object



27
28
29
30
31
# File 'lib/cryptoexchange/exchanges/dragonex/services/market.rb', line 27

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

#inject_inst_id(market_pair) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/cryptoexchange/exchanges/dragonex/services/market.rb', line 17

def inject_inst_id(market_pair)
  # todo: refactor to global
  if !(market_pair.respond_to? :inst_id) || (market_pair.send(:inst_id).nil?)
    market_pairs = Cryptoexchange::Client.new.pairs(Dragonex::Market::NAME)
    market_pair = market_pairs.detect { |mp| mp.base == market_pair.base && mp.target == market_pair.target }
  end

  market_pair
end

#ticker_url(market_pair) ⇒ Object



33
34
35
# File 'lib/cryptoexchange/exchanges/dragonex/services/market.rb', line 33

def ticker_url(market_pair)
  "#{Cryptoexchange::Exchanges::Dragonex::Market::API_URL}/api/v1/market/kline/?symbol_id=#{market_pair.inst_id}&kline_type=#{KLINE_TYPE}&st=#{SEARCH_TIMESTAMP}&count=#{COUNT}"
end