Class: Flashboy::Exchange

Inherits:
Client
  • Object
show all
Defined in:
lib/flashboy/exchange.rb

Direct Known Subclasses

Bitfinex, Bittrex, Cex, Gdax, Gemini, Kraken, Poloniex, Quoine

Instance Method Summary collapse

Methods inherited from Client

#docs, docs, #host, host, #key, key, #name, name, order_book_path, #order_book_path, quote_path, #quote_path, trades_path, #trades_path

Instance Method Details

#order_book(pair) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/flashboy/exchange.rb', line 30

def order_book(pair)
  id = formatted_pair(pair)
  data = request order_book_path(id)
  OrderBook.new parse_order_book(data, id).merge(
    pair: pair,
    exchange: name
  )
end

#quote(pair) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/flashboy/exchange.rb', line 3

def quote(pair)
  id = formatted_pair(pair)
  data = request quote_path(id)
  Quote.new parse_quote(data, id).merge(
    pair: pair,
    exchange: name
  )
end

#trades(pair, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/flashboy/exchange.rb', line 12

def trades(pair, options = {})
  start, finish, cursor = nil
  if options[:start] || options[:finish]
    finish = options[:finish] || Time.now.to_i
    start  = options[:start] || finish - (60 * 60)
  elsif options[:since]
    cursor = options[:since] || 0
  end

  id = formatted_pair(pair)
  url = trades_path(id, {start: start, finish: finish, since: cursor})
  # puts url
  data = request url
  parse_trades(data, self, id).map do |trade|
    Trade.new(trade.merge(pair: pair, exchange: name))
  end
end