Class: RTCBX::Orderbook
- 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
Constants inherited from RTCBX
Instance Attribute Summary collapse
-
#asks ⇒ Object
readonly
Array of asks.
-
#bids ⇒ Object
readonly
Array of bids.
-
#last_sequence ⇒ Object
readonly
Sequence number of most recently received message.
-
#snapshot_sequence ⇒ Object
readonly
Sequence number from the initial level 3 snapshot.
-
#update_thread ⇒ Object
readonly
Reads from the queue and updates the Orderbook.
Attributes inherited from RTCBX
#api_key, #client, #last_pong, #message_callbacks, #product_id, #queue, #start, #websocket, #websocket_thread
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ Orderbook
constructor
Creates a new live copy of the orderbook.
-
#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.
-
#stop! ⇒ Object
Stop the thread that listens to updates on the websocket.
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
Methods inherited from RTCBX
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( = {}, &block) @bids = [] @asks = [] @snapshot_sequence = 0 @last_sequence = 0 super(, &block) end |
Instance Attribute Details
#asks ⇒ Object (readonly)
Array of asks
19 20 21 |
# File 'lib/rtcbx/orderbook.rb', line 19 def asks @asks end |
#bids ⇒ Object (readonly)
Array of bids
15 16 17 |
# File 'lib/rtcbx/orderbook.rb', line 15 def bids @bids end |
#last_sequence ⇒ Object (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_sequence ⇒ Object (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_thread ⇒ Object (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 |