Class: Cryptoexchange::Exchanges::Cybex::Services::Trades

Inherits:
Services::Market show all
Defined in:
lib/cryptoexchange/exchanges/cybex/services/trades.rb

Constant Summary collapse

SECONDS =
86400

Instance Method Summary collapse

Methods inherited from Services::Market

#fetch_using_post, supports_individual_ticker_query?

Instance Method Details

#adapt(output, market_pair) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cryptoexchange/exchanges/cybex/services/trades.rb', line 20

def adapt(output, market_pair)
  output['result'].collect do |trade|
    tr           = Cryptoexchange::Models::Trade.new
    tr.trade_id  = nil
    tr.base      = market_pair.base
    tr.target    = market_pair.target
    tr.market    = Cybex::Market::NAME
    tr.price     = trade['price']
    tr.amount    = trade['amount']
    tr.timestamp = Time.parse(trade['date']).to_i
    tr.payload   = trade
    tr
  end
end

#fetch(market_pair) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/cryptoexchange/exchanges/cybex/services/trades.rb', line 7

def fetch(market_pair)
  base, target = Cybex::Market.prepend_symbol_prefix(market_pair)
  now         = transform_time_string(Time.now.utc)
  one_day_ago = transform_time_string(Time.now.utc - SECONDS)
  output      = fetch_using_post(ticker_url,
                                 { "jsonrpc": "2.0", "method": "get_trade_history", "params": ["#{target}", "#{base}", now, one_day_ago, 100], "id": 1 })
  adapt(output, market_pair)
end

#ticker_urlObject



16
17
18
# File 'lib/cryptoexchange/exchanges/cybex/services/trades.rb', line 16

def ticker_url
  "#{Cryptoexchange::Exchanges::Cybex::Market::API_URL}"
end

#transform_time_string(time) ⇒ Object



35
36
37
# File 'lib/cryptoexchange/exchanges/cybex/services/trades.rb', line 35

def transform_time_string(time)
  time.strftime("%FT%R")
end