class Cryptoexchange::Exchanges::Bitkub::Services::OrderBook

Constants

ORDER_LIMIT

Public Class Methods

supports_individual_ticker_query?() click to toggle source
# File lib/cryptoexchange/exchanges/bitkub/services/order_book.rb, line 7
def supports_individual_ticker_query?
  true
end

Public Instance Methods

adapt(asks, bids, market_pair) click to toggle source
# File lib/cryptoexchange/exchanges/bitkub/services/order_book.rb, line 30
def adapt(asks, bids, market_pair)
  order_book = Cryptoexchange::Models::OrderBook.new

  order_book.base      = market_pair.base
  order_book.target    = market_pair.target
  order_book.market    = Bitkub::Market::NAME
  order_book.asks      = adapt_orders(asks['result'])
  order_book.bids      = adapt_orders(bids['result'])
  order_book.timestamp = Time.now.to_i
  order_book.payload   = [asks, bids]
  order_book
end
adapt_orders(orders) click to toggle source
# File lib/cryptoexchange/exchanges/bitkub/services/order_book.rb, line 43
def adapt_orders(orders)
  orders.collect do |order_entry|
    Cryptoexchange::Models::Order.new(
      price:     order_entry[3],
      amount:    order_entry[-1],
      timestamp: order_entry[1]
    )
  end
end
asks_url(market_pair) click to toggle source
# File lib/cryptoexchange/exchanges/bitkub/services/order_book.rb, line 18
def asks_url(market_pair)
  base   = market_pair.base
  target = market_pair.target
  "#{Cryptoexchange::Exchanges::Bitkub::Market::API_URL}/market/asks?sym=#{target}_#{base}&lmt=#{ORDER_LIMIT}"
end
bids_url(market_pair) click to toggle source
# File lib/cryptoexchange/exchanges/bitkub/services/order_book.rb, line 24
def bids_url(market_pair)
  base   = market_pair.base
  target = market_pair.target
  "#{Cryptoexchange::Exchanges::Bitkub::Market::API_URL}/market/bids?sym=#{target}_#{base}&lmt=#{ORDER_LIMIT}"
end
fetch(market_pair) click to toggle source
Calls superclass method Cryptoexchange::Services::Market#fetch
# File lib/cryptoexchange/exchanges/bitkub/services/order_book.rb, line 12
def fetch(market_pair)
  asks_output = super(asks_url(market_pair))
  bids_output = super(bids_url(market_pair))
  adapt(asks_output, bids_output, market_pair)
end