Class: Cryptoexchange::Exchanges::Ercdex::Services::Market

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

def supports_individual_ticker_query?
  true
end

Instance Method Details

#adapt(output, pair_id, market_pair) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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) ⇒ Object



11
12
13
14
15
16
17
18
19
# 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_urlObject



21
22
23
# File 'lib/cryptoexchange/exchanges/ercdex/services/market.rb', line 21

def ticker_url
  "#{Cryptoexchange::Exchanges::Ercdex::Market::API_URL}/reports/historical"
end