Class: Cryptoexchange::Exchanges::BitboxPrivate::Services::Market
- Inherits:
-
Services::Market
- Object
- Services::Market
- Cryptoexchange::Exchanges::BitboxPrivate::Services::Market
- Defined in:
- lib/cryptoexchange/exchanges/bitbox_private/services/market.rb
Class Method Summary collapse
Instance Method Summary collapse
- #adapt(output, market_pair) ⇒ Object
- #endpoint ⇒ Object
- #fetch(market_pair) ⇒ Object
- #params(market_pair) ⇒ Object
- #payload(timestamp, market_pair) ⇒ Object
- #ticker_url(market_pair) ⇒ Object
Methods inherited from Services::Market
Class Method Details
.supports_individual_ticker_query? ⇒ Boolean
6 7 8 |
# File 'lib/cryptoexchange/exchanges/bitbox_private/services/market.rb', line 6 def supports_individual_ticker_query? true end |
Instance Method Details
#adapt(output, market_pair) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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. = nil ticker.payload = output ticker end |
#endpoint ⇒ Object
26 27 28 |
# File 'lib/cryptoexchange/exchanges/bitbox_private/services/market.rb', line 26 def endpoint "/v1/market/public/currentTickValue" end |
#fetch(market_pair) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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! = (Time.now.to_i * 1000).to_s payload_ = payload(, market_pair) headers = authentication.headers(payload_, ) 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) ⇒ Object
30 31 32 |
# 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) ⇒ Object
34 35 36 |
# File 'lib/cryptoexchange/exchanges/bitbox_private/services/market.rb', line 34 def payload(, market_pair) "12345" + + "GET" + endpoint + params(market_pair) end |
#ticker_url(market_pair) ⇒ Object
38 39 40 |
# 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 |