Class: Cryptoexchange::Exchanges::Ccex::Services::Market

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

def supports_individual_ticker_query?
  true
end

Instance Method Details

#adapt(ticker_output, volumes_output, market_pair) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cryptoexchange/exchanges/ccex/services/market.rb', line 27

def adapt(ticker_output, volumes_output, market_pair)
  market = ticker_output['ticker']
  volume = HashHelper.dig(volumes_output, 'ticker', market_pair.base.downcase, 'vol')

  ticker           = Cryptoexchange::Models::Ticker.new
  ticker.base      = market_pair.base
  ticker.target    = market_pair.target
  ticker.market    = Ccex::Market::NAME
  ticker.last      = NumericHelper.to_d(market['lastprice'])
  ticker.bid       = NumericHelper.to_d(market['lastbuy'])
  ticker.ask       = NumericHelper.to_d(market['lastsell'])
  ticker.high      = NumericHelper.to_d(market['high'])
  ticker.low       = NumericHelper.to_d(market['low'])
  ticker.volume    = volume ? NumericHelper.to_d(volume)/ticker.last : 0
  ticker.timestamp = NumericHelper.to_d(market['updated'])
  ticker.payload   = market
  ticker
end

#fetch(market_pair) ⇒ Object



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

def fetch(market_pair)
  ticker_output  = super(ticker_url(market_pair))
  volume_output = super(volume_url(market_pair))
  adapt(ticker_output, volume_output, market_pair)
end

#ticker_url(market_pair) ⇒ Object



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

def ticker_url(market_pair)
  name = "#{market_pair.base}-#{market_pair.target}".downcase
  "#{Cryptoexchange::Exchanges::Ccex::Market::API_URL}/#{name}.json"
end

#volume_url(market_pair) ⇒ Object



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

def volume_url(market_pair)
  target = market_pair.target.downcase
  "#{Cryptoexchange::Exchanges::Ccex::Market::API_URL}/volume_#{target}.json"
end