class Bibox::Models::OrderBook
Attributes
asks[RW]
bids[RW]
pair[RW]
update_time[RW]
Public Class Methods
new(hash)
click to toggle source
# 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
Public Instance Methods
process(hash)
click to toggle source
# 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