Class: RTCBX::Orderbook

Inherits:
RTCBX
  • Object
show all
Includes:
BookAnalysis, BookMethods
Defined in:
lib/rtcbx/orderbook.rb,
lib/rtcbx/orderbook/book_methods.rb,
lib/rtcbx/orderbook/book_analysis.rb

Defined Under Namespace

Modules: BookAnalysis, BookMethods

Constant Summary

Constants included from BookMethods

BookMethods::BIGDECIMAL_KEYS

Constants inherited from RTCBX

PING_INTERVAL, VERSION

Instance Attribute Summary collapse

Attributes inherited from RTCBX

#api_key, #client, #last_pong, #message_callbacks, #product_id, #queue, #start, #websocket, #websocket_thread

Instance Method Summary collapse

Methods included from BookAnalysis

#aggregate, #aggregate_asks, #aggregate_bids, #ask_count, #ask_volume, #average, #average_ask, #average_bid, #best, #best_ask, #best_bid, #bid_count, #bid_volume, #count, #spread, #summarize, #volume

Methods included from BookMethods

#apply

Methods inherited from RTCBX

#reset!

Constructor Details

#initialize(options = {}, &block) ⇒ Orderbook

Creates a new live copy of the orderbook.

If start is set to false, the orderbook will not start automatically.

If a block is given it is passed each message as it is received.



39
40
41
42
43
44
45
# File 'lib/rtcbx/orderbook.rb', line 39

def initialize(options = {}, &block)
  @bids = []
  @asks = []
  @snapshot_sequence = 0
  @last_sequence = 0
  super(options, &block)
end

Instance Attribute Details

#asksObject (readonly)

Array of asks



19
20
21
# File 'lib/rtcbx/orderbook.rb', line 19

def asks
  @asks
end

#bidsObject (readonly)

Array of bids



15
16
17
# File 'lib/rtcbx/orderbook.rb', line 15

def bids
  @bids
end

#last_sequenceObject (readonly)

Sequence number of most recently received message



27
28
29
# File 'lib/rtcbx/orderbook.rb', line 27

def last_sequence
  @last_sequence
end

#snapshot_sequenceObject (readonly)

Sequence number from the initial level 3 snapshot



23
24
25
# File 'lib/rtcbx/orderbook.rb', line 23

def snapshot_sequence
  @snapshot_sequence
end

#update_threadObject (readonly)

Reads from the queue and updates the Orderbook.



31
32
33
# File 'lib/rtcbx/orderbook.rb', line 31

def update_thread
  @update_thread
end

Instance Method Details

#start!Object

Used to start the thread that listens to updates on the websocket and applies them to the current orderbook to create a live book.



50
51
52
53
54
55
# File 'lib/rtcbx/orderbook.rb', line 50

def start!
  super
  sleep 1
  apply_orderbook_snapshot
  start_update_thread
end

#stop!Object

Stop the thread that listens to updates on the websocket



59
60
61
62
# File 'lib/rtcbx/orderbook.rb', line 59

def stop!
  super
  update_thread.kill
end