class Bitstamper::Models::OrderBook

Attributes

asks[RW]
bids[RW]
timestamp[RW]

Public Class Methods

new(hash) click to toggle source
# File lib/bitstamper/models/order_book.rb, line 6
def initialize(hash)
  self.bids   =   []
  self.asks   =   []
  
  self.timestamp  =  ::Bitstamper::Utilities.epoch_to_time(hash.fetch("timestamp", nil)) if hash.has_key?("timestamp") && !hash.fetch("timestamp", nil).to_s.empty?
  
  process(hash)
end

Public Instance Methods

process(hash) click to toggle source
# 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