Class: Bitstamper::Models::OrderBook
- Inherits:
-
Object
- Object
- Bitstamper::Models::OrderBook
- Defined in:
- lib/bitstamper/models/order_book.rb
Instance Attribute Summary collapse
-
#asks ⇒ Object
Returns the value of attribute asks.
-
#bids ⇒ Object
Returns the value of attribute bids.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#initialize(hash) ⇒ OrderBook
constructor
A new instance of OrderBook.
- #process(hash) ⇒ Object
Constructor Details
#initialize(hash) ⇒ OrderBook
Returns a new instance of OrderBook.
6 7 8 9 10 11 12 13 |
# File 'lib/bitstamper/models/order_book.rb', line 6 def initialize(hash) self.bids = [] self.asks = [] self. = ::Bitstamper::Utilities.epoch_to_time(hash.fetch("timestamp", nil)) if hash.has_key?("timestamp") && !hash.fetch("timestamp", nil).to_s.empty? process(hash) end |
Instance Attribute Details
#asks ⇒ Object
Returns the value of attribute asks.
4 5 6 |
# File 'lib/bitstamper/models/order_book.rb', line 4 def asks @asks end |
#bids ⇒ Object
Returns the value of attribute bids.
4 5 6 |
# File 'lib/bitstamper/models/order_book.rb', line 4 def bids @bids end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
4 5 6 |
# File 'lib/bitstamper/models/order_book.rb', line 4 def end |
Instance Method Details
#process(hash) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bitstamper/models/order_book.rb', line 15 def process(hash) [:bids, :asks].each do |type| hash.fetch(type.to_s, []).each do |item| price = item&.first&.to_f quantity = item&.last&.to_f value = !price.nil? && !quantity.nil? ? price * quantity : nil self.send(type).send(:<<, {price: price, quantity: quantity, value: value}) end end end |