Class: Cryptoexchange::Exchanges::CoinExchange::Services::Market

Inherits:
Services::Market
  • Object
show all
Defined in:
lib/cryptoexchange/exchanges/coin_exchange/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/coin_exchange/services/market.rb', line 8

def supports_individual_ticker_query?
  true
end

Instance Method Details

#adapt(output, market_pair) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cryptoexchange/exchanges/coin_exchange/services/market.rb', line 32

def adapt(output, market_pair)
  market = output['result']

  ticker           = Cryptoexchange::Models::Ticker.new
  ticker.base      = market_pair.base
  ticker.target    = market_pair.target
  ticker.market    = CoinExchange::Market::NAME
  ticker.last      = NumericHelper.to_d(market['LastPrice'])
  ticker.bid       = NumericHelper.to_d(market['BidPrice'])
  ticker.ask       = NumericHelper.to_d(market['AskPrice'])
  ticker.high      = NumericHelper.to_d(market['HighPrice'])
  ticker.low       = NumericHelper.to_d(market['LowPrice'])
  ticker.volume    = NumericHelper.divide(NumericHelper.to_d(market['Volume']), ticker.last)
  ticker.timestamp = nil
  ticker.payload   = market
  ticker
end

#fetch(market_pair) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/cryptoexchange/exchanges/coin_exchange/services/market.rb', line 13

def fetch(market_pair)
  unless @market_id_cache
    output = super(pairs_url)
    hydrate_market_id_cache(output)
  end

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

#pairs_urlObject



23
24
25
# File 'lib/cryptoexchange/exchanges/coin_exchange/services/market.rb', line 23

def pairs_url
  "#{Cryptoexchange::Exchanges::CoinExchange::Market::API_URL}/getmarkets"
end

#ticker_url(market_pair) ⇒ Object



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

def ticker_url(market_pair)
  id = market_id(market_pair)
  "#{Cryptoexchange::Exchanges::CoinExchange::Market::API_URL}/getmarketsummary?market_id=#{id}"
end