Class: Cryptoexchange::Exchanges::Bittrex::Services::Market

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

def supports_individual_ticker_query?
  true
end

Instance Method Details

#adapt(output, market_pair) ⇒ Object



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

def adapt(output, market_pair)
  handle_invalid(output)
  ticker = Cryptoexchange::Models::Ticker.new
  market = output['result'][0]

  ticker.base      = market_pair.base
  ticker.target    = market_pair.target
  ticker.market    = Bittrex::Market::NAME
  ticker.last      = NumericHelper.to_d(market['Last'])
  ticker.high      = NumericHelper.to_d(market['High'])
  ticker.low       = NumericHelper.to_d(market['Low'])
  ticker.ask       = NumericHelper.to_d(market['Ask'])
  ticker.bid       = NumericHelper.to_d(market['Bid'])
  ticker.volume    = NumericHelper.to_d(market['Volume'])
  ticker.timestamp = NumericHelper.to_d(DateTime.parse(market['TimeStamp']).to_time.to_i)
  ticker.payload   = market
  ticker
end

#fetch(market_pair) ⇒ Object



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

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

#handle_invalid(output) ⇒ Object



42
43
44
45
46
# File 'lib/cryptoexchange/exchanges/bittrex/services/market.rb', line 42

def handle_invalid(output)
  if output['message'] == 'INVALID_MARKET'
    raise Cryptoexchange::ResultParseError, { response: output }
  end
end

#ticker_url(market_pair) ⇒ Object



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

def ticker_url(market_pair)
  base = market_pair.base
  target = market_pair.target
  # Bittrex pair has BTC comes first, when BTC is typically a Target not a Base
  "#{Cryptoexchange::Exchanges::Bittrex::Market::API_URL}/public/getmarketsummary?market=#{target}-#{base}"
end