Class: Bibox::Models::OrderBook
- Inherits:
-
Object
- Object
- Bibox::Models::OrderBook
- Defined in:
- lib/bibox/models/order_book.rb
Instance Attribute Summary collapse
-
#asks ⇒ Object
Returns the value of attribute asks.
-
#bids ⇒ Object
Returns the value of attribute bids.
-
#pair ⇒ Object
Returns the value of attribute pair.
-
#update_time ⇒ Object
Returns the value of attribute update_time.
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 14 |
# File 'lib/bibox/models/order_book.rb', line 6 def initialize(hash) self.pair = hash.fetch("pair", nil) self.update_time = ::Bibox::Utilities.epoch_to_time(hash.fetch("update_time", nil), ms: true) if hash.has_key?("update_time") && !hash.fetch("update_time", nil).to_s.empty? self.bids = [] self.asks = [] process(hash) end |
Instance Attribute Details
#asks ⇒ Object
Returns the value of attribute asks.
4 5 6 |
# File 'lib/bibox/models/order_book.rb', line 4 def asks @asks end |
#bids ⇒ Object
Returns the value of attribute bids.
4 5 6 |
# File 'lib/bibox/models/order_book.rb', line 4 def bids @bids end |
#pair ⇒ Object
Returns the value of attribute pair.
4 5 6 |
# File 'lib/bibox/models/order_book.rb', line 4 def pair @pair end |
#update_time ⇒ Object
Returns the value of attribute update_time.
4 5 6 |
# File 'lib/bibox/models/order_book.rb', line 4 def update_time @update_time end |
Instance Method Details
#process(hash) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bibox/models/order_book.rb', line 16 def process(hash) [:bids, :asks].each do |type| hash.fetch(type.to_s, []).each do |item| price = ::Bibox::Utilities.convert_value(item.fetch("price", nil), :float) volume = ::Bibox::Utilities.convert_value(item.fetch("volume", nil), :float) value = !price.nil? && !volume.nil? ? price * volume : nil self.send(type).send(:<<, {price: price, volume: volume, value: value}) end end end |