Class: Cryptoexchange::Exchanges::Coinut::Services::Trades

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

Instance Method Summary collapse

Methods inherited from Services::Market

#fetch_using_post, supports_individual_ticker_query?

Instance Method Details

#adapt(output, market_pair) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cryptoexchange/exchanges/coinut/services/trades.rb', line 27

def adapt(output, market_pair)
  output["trades"].collect do |trade|
    tr = Cryptoexchange::Models::Trade.new
    tr.base      = market_pair.base
    tr.target    = market_pair.target
    tr.market    = Coinut::Market::NAME
    tr.trade_id  = trade["trans_id"]
    tr.type      = trade["side"]
    tr.price     = trade["price"]
    tr.amount    = trade["qty"]
    tr.timestamp = trade["timestamp"]
    tr.payload   = trade
    tr
  end
end

#fetch(market_pair) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/cryptoexchange/exchanges/coinut/services/trades.rb', line 5

def fetch(market_pair)
  authentication = Cryptoexchange::Exchanges::Coinut::Authentication.new(
    :trades,
    Cryptoexchange::Exchanges::Coinut::Market::NAME
  )
  authentication.validate_credentials!

  payload_ = payload(market_pair)
  headers = authentication.headers(payload_)
  output = fetch_using_post(ticker_url, payload_, headers)
  adapt(output, market_pair)
end

#payload(market_pair) ⇒ Object



18
19
20
# File 'lib/cryptoexchange/exchanges/coinut/services/trades.rb', line 18

def payload(market_pair)
  '{"nonce":' + SecureRandom.random_number(99999).to_s + ',"request":"inst_trade", "inst_id":' + market_pair.inst_id + ' }'
end

#ticker_urlObject



23
24
25
# File 'lib/cryptoexchange/exchanges/coinut/services/trades.rb', line 23

def ticker_url
  Cryptoexchange::Exchanges::Coinut::Market::API_URL
end