Class: Itbit::MarketData
- Inherits:
-
Object
- Object
- Itbit::MarketData
- Defined in:
- lib/itbit/market.rb
Overview
Public market data for a pair, do not use directly, use XBTUSDMarketData, XBTSGDMarketData and XBTEURMarketData instead.
Direct Known Subclasses
Class Method Summary collapse
-
.orders ⇒ Object
The symbol order book as a Hash with two keys: bids and asks.
-
.ticker ⇒ Object
The symbol ticker conveniently formatted as a ruby Hash with symbolized keys.
-
.trades(tid = 0) ⇒ Object
The symbol trades since tid (transaction id) as a list of hashes that look like unix_timestamp, price: 123.5, amount: 1.97, tid: 98375.
Class Method Details
.orders ⇒ Object
The symbol order book as a Hash with two keys: bids and asks. Each of them is a list of list consisting of [price, quantity]
24 25 26 27 28 29 |
# File 'lib/itbit/market.rb', line 24 def self.orders order_book = public_request("/markets/#{symbol.upcase}/order_book").symbolize_keys order_book.each do |key, value| order_book[key] = value.collect { |tuple| tuple.collect(&:to_d) } end end |
.ticker ⇒ Object
The symbol ticker conveniently formatted as a ruby Hash with symbolized keys.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/itbit/market.rb', line 9 def self.ticker public_request("/markets/#{symbol.upcase}/ticker").reduce({}) do |ticker, pair| key = pair.first.underscore.to_sym value = case key when :pair then pair[1].underscore.to_sym when :servertime_utc then Time.parse(pair[1]).to_i else pair[1].to_d end ticker[key] = value ticker end end |
.trades(tid = 0) ⇒ Object
The symbol trades since tid (transaction id) as a list of hashes that look like unix_timestamp, price: 123.5, amount: 1.97, tid: 98375
33 34 35 36 37 38 39 40 |
# File 'lib/itbit/market.rb', line 33 def self.trades(tid = 0) trades = public_request("/markets/#{symbol.upcase}/trades", since: tid) trades['recentTrades'].collect do |t| { price: t['price'].to_d, amount: t['amount'].to_d, tid: t['matchNumber'], date: DateTime.parse(t['timestamp']).to_i }.with_indifferent_access end end |