class Cryptoexchange::Exchanges::CoinExchange::Services::Market
Public Class Methods
supports_individual_ticker_query?()
click to toggle source
# File lib/cryptoexchange/exchanges/coin_exchange/services/market.rb, line 8 def supports_individual_ticker_query? true end
Public Instance Methods
adapt(output, market_pair)
click to toggle source
# 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)
click to toggle source
Calls superclass method
Cryptoexchange::Services::Market#fetch
# 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_url()
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
hydrate_market_id_cache(output)
click to toggle source
# File lib/cryptoexchange/exchanges/coin_exchange/services/market.rb, line 56 def hydrate_market_id_cache(output) @market_id_cache = {} output['result'].each do |market| key = "#{market['MarketAssetCode'].upcase}_#{market['BaseCurrencyCode']}" @market_id_cache[key] = market['MarketID'] end end
market_id(market_pair)
click to toggle source
# File lib/cryptoexchange/exchanges/coin_exchange/services/market.rb, line 65 def market_id(market_pair) @market_id_cache[market_id_cache_key(market_pair)] end
market_id_cache_key(market_pair)
click to toggle source
# File lib/cryptoexchange/exchanges/coin_exchange/services/market.rb, line 52 def market_id_cache_key(market_pair) "#{market_pair.base}_#{market_pair.target}" end