class Cryptoexchange::Exchanges::Ercdex::Services::Market

Public Class Methods

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

Public Instance Methods

adapt(output, pair_id, market_pair) click to toggle source
# File lib/cryptoexchange/exchanges/ercdex/services/market.rb, line 25
def adapt(output, pair_id, market_pair)
  ticker = Cryptoexchange::Models::Ticker.new
  ticker.base      = market_pair.base
  ticker.target    = market_pair.target
  ticker.market    = Ercdex::Market::NAME
  ticker.ask       = NumericHelper.to_d(pair_id[0]['ask'])
  ticker.bid       = NumericHelper.to_d(pair_id[0]['bid'])
  ticker.last      = NumericHelper.to_d(output['close'])
  ticker.high      = NumericHelper.to_d(output['high'])
  ticker.low       = NumericHelper.to_d(output['low'])
  ticker.volume    = NumericHelper.to_d(pair_id[0]['tokenPair']['baseVolume'])
  ticker.timestamp = DateTime.parse(output['date']).strftime("%s").to_i
  ticker.payload   = output,pair_id
  ticker
end
fetch(market_pair) click to toggle source
# File lib/cryptoexchange/exchanges/ercdex/services/market.rb, line 11
def fetch(market_pair)
  # call IdFetcher to obtain base, target, base volume, bid, and ask
  pair_id = IdFetcher.get_id(market_pair.base.upcase, market_pair.target.upcase)
  base = pair_id[0]["tokenPair"]["tokenA"]["address"]
  target = pair_id[0]["tokenPair"]["tokenB"]["address"]
  raw_output = HTTP.post(ticker_url, :json => { :baseTokenAddress=>"#{base}",:quoteTokenAddress=>"#{target}",:networkId=>1,:startDate=>"#{DateTime.parse("#{(Time.now - 1200).utc}").iso8601}" })
  output = JSON.parse(raw_output)
  adapt(output.last, pair_id, market_pair)
end
ticker_url() click to toggle source
# File lib/cryptoexchange/exchanges/ercdex/services/market.rb, line 21
def ticker_url
  "#{Cryptoexchange::Exchanges::Ercdex::Market::API_URL}/reports/historical"
end