Module: Orderbook::BookMethods

Included in:
Orderbook
Defined in:
lib/orderbook/book_methods.rb

Overview

This class provides methods to apply updates to the state of the orderbook as they are received by the websocket.

Constant Summary collapse

BIGDECIMAL_KEYS =
%w(size old_size new_size remaining_size price)

Instance Method Summary collapse

Instance Method Details

#apply(msg) ⇒ Object

Applies a message to an Orderbook object by making relevant changes to @bids, @asks, and @last_sequence.



12
13
14
15
16
17
18
19
20
# File 'lib/orderbook/book_methods.rb', line 12

def apply(msg)
  return if msg.fetch('sequence') <= @first_sequence
  @last_sequence = msg.fetch('sequence')
  BIGDECIMAL_KEYS.each do |key|
    msg[key] = BigDecimal.new(msg.fetch(key)) if msg.fetch(key, false)
  end

  __send__(msg.fetch('type'), msg)
end