Class: Bibox::Models::OrderBook

Inherits:
Object
  • Object
show all
Defined in:
lib/bibox/models/order_book.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#asksObject

Returns the value of attribute asks.



4
5
6
# File 'lib/bibox/models/order_book.rb', line 4

def asks
  @asks
end

#bidsObject

Returns the value of attribute bids.



4
5
6
# File 'lib/bibox/models/order_book.rb', line 4

def bids
  @bids
end

#pairObject

Returns the value of attribute pair.



4
5
6
# File 'lib/bibox/models/order_book.rb', line 4

def pair
  @pair
end

#update_timeObject

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