class Cryptoexchange::Exchanges::BitboxPrivate::Services::Market

Public Class Methods

supports_individual_ticker_query?() click to toggle source
# File lib/cryptoexchange/exchanges/bitbox_private/services/market.rb, line 6
def supports_individual_ticker_query?
  true
end

Public Instance Methods

adapt(output, market_pair) click to toggle source
# File lib/cryptoexchange/exchanges/bitbox_private/services/market.rb, line 42
def adapt(output, market_pair)
  output = output["responseData"]
  ticker = Cryptoexchange::Models::Ticker.new
  ticker.base = market_pair.base
  ticker.target = market_pair.target
  ticker.market = BitboxPrivate::Market::NAME
  ticker.last = NumericHelper.to_d(output['last'])
  ticker.bid = NumericHelper.to_d(output['bid'])
  ticker.ask = NumericHelper.to_d(output['ask'])
  ticker.volume = NumericHelper.divide(output['volume'], ticker.last)
  ticker.timestamp = nil
  ticker.payload = output
  ticker
end
endpoint() click to toggle source
# File lib/cryptoexchange/exchanges/bitbox_private/services/market.rb, line 26
def endpoint
  "/v1/market/public/currentTickValue"
end
fetch(market_pair) click to toggle source
# File lib/cryptoexchange/exchanges/bitbox_private/services/market.rb, line 11
def fetch(market_pair)
  authentication = Cryptoexchange::Exchanges::BitboxPrivate::Authentication.new(
    :market,
    Cryptoexchange::Exchanges::BitboxPrivate::Market::NAME
  )
  authentication.validate_credentials!

  timestamp = (Time.now.to_i * 1000).to_s
  payload_ = payload(timestamp, market_pair)
  headers = authentication.headers(payload_, timestamp)
  api_url = "#{Cryptoexchange::Exchanges::BitboxPrivate::Market::API_URL}" + endpoint + "?" + params(market_pair)
  output = HTTP.timeout(:write => 2, :connect => 15, :read => 18).headers(headers).get(api_url).parse :json
  adapt(output, market_pair)
end
params(market_pair) click to toggle source
# File lib/cryptoexchange/exchanges/bitbox_private/services/market.rb, line 30
def params(market_pair)
  "coinPair=#{market_pair.base}.#{market_pair.target}"
end
payload(timestamp, market_pair) click to toggle source
# File lib/cryptoexchange/exchanges/bitbox_private/services/market.rb, line 34
def payload(timestamp, market_pair)
  "12345" + timestamp + "GET" + endpoint + params(market_pair)
end
ticker_url(market_pair) click to toggle source
# File lib/cryptoexchange/exchanges/bitbox_private/services/market.rb, line 38
def ticker_url(market_pair)
  "#{Cryptoexchange::Exchanges::BitboxPrivate::Market::API_URL}/currentTickValue?coinPair=#{market_pair.base}.#{market_pair.target}"
end