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]
25 26 27 28 29 30 |
# File 'lib/itbit/market.rb', line 25 def self.orders order_book = old_request("/markets/#{symbol.upcase}/orders").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 21 |
# File 'lib/itbit/market.rb', line 9 def self.ticker raw_ticker = JSON.parse(RestClient.get("#{Api.api_url}/markets/#{symbol.upcase}/ticker")) raw_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
34 35 36 37 38 39 40 |
# File 'lib/itbit/market.rb', line 34 def self.trades(tid = 0) trades = old_request("/markets/#{symbol.upcase}/trades", since: tid) trades.collect do |t| t.merge(price: t['price'].to_d, amount: t['amount'].to_d) .with_indifferent_access end end |