Class: Orderbook
- Inherits:
-
Object
- Object
- Orderbook
- Includes:
- BookAnalysis, BookMethods
- Defined in:
- lib/orderbook.rb,
lib/orderbook/version.rb,
lib/orderbook/book_methods.rb,
lib/orderbook/book_analysis.rb,
lib/orderbook/real_time_book.rb
Overview
Orderbook version number. I try to keep it semantic.
Direct Known Subclasses
Defined Under Namespace
Modules: BookAnalysis, BookMethods Classes: RealTimeBook
Constant Summary collapse
- PING_INTERVAL =
seconds in between pinging the connection.
15
- VERSION =
'2.0.2'
Constants included from BookMethods
Instance Attribute Summary collapse
-
#asks ⇒ Object
readonly
Array of asks.
-
#bids ⇒ Object
readonly
Array of bids.
-
#callback ⇒ Object
Callback to pass each received message to.
-
#client ⇒ Object
readonly
Coinbase::Exchange::AsyncClient object.
-
#first_sequence ⇒ Object
readonly
Sequence number from the initial level 3 snapshot.
-
#last_pong ⇒ Object
readonly
Last time a pong was received after a ping.
-
#last_sequence ⇒ Object
readonly
Sequence number of most recently received message.
-
#thread ⇒ Object
readonly
Thread running the EM loop.
-
#websocket ⇒ Object
readonly
Coinbase::Exchange::Websocket object.
Instance Method Summary collapse
-
#initialize(live = true, &block) ⇒ Orderbook
constructor
Creates a new live copy of the orderbook.
-
#live! ⇒ 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.
Methods included from BookAnalysis
#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
Constructor Details
#initialize(live = true, &block) ⇒ Orderbook
Creates a new live copy of the orderbook.
If live
is set to false, the orderbook will not start automatically.
If a block
is given it is passed each message as it is received.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/orderbook.rb', line 58 def initialize(live = true, &block) @bids = [{ price: nil, size: nil, order_id: nil }] @asks = [{ price: nil, size: nil, order_id: nil }] @first_sequence = 0 @last_sequence = 0 @websocket = Coinbase::Exchange::Websocket.new(keepalive: true) @client = Coinbase::Exchange::AsyncClient.new @callback = block if block_given? live && live! end |
Instance Attribute Details
#asks ⇒ Object (readonly)
Array of asks
22 23 24 |
# File 'lib/orderbook.rb', line 22 def asks @asks end |
#bids ⇒ Object (readonly)
Array of bids
18 19 20 |
# File 'lib/orderbook.rb', line 18 def bids @bids end |
#callback ⇒ Object
Callback to pass each received message to
50 51 52 |
# File 'lib/orderbook.rb', line 50 def callback @callback end |
#client ⇒ Object (readonly)
Coinbase::Exchange::AsyncClient object
38 39 40 |
# File 'lib/orderbook.rb', line 38 def client @client end |
#first_sequence ⇒ Object (readonly)
Sequence number from the initial level 3 snapshot
26 27 28 |
# File 'lib/orderbook.rb', line 26 def first_sequence @first_sequence end |
#last_pong ⇒ Object (readonly)
Last time a pong was received after a ping
46 47 48 |
# File 'lib/orderbook.rb', line 46 def last_pong @last_pong end |
#last_sequence ⇒ Object (readonly)
Sequence number of most recently received message
30 31 32 |
# File 'lib/orderbook.rb', line 30 def last_sequence @last_sequence end |
#thread ⇒ Object (readonly)
Thread running the EM loop
42 43 44 |
# File 'lib/orderbook.rb', line 42 def thread @thread end |
#websocket ⇒ Object (readonly)
Coinbase::Exchange::Websocket object
34 35 36 |
# File 'lib/orderbook.rb', line 34 def websocket @websocket end |
Instance Method Details
#live! ⇒ 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.
72 73 74 75 |
# File 'lib/orderbook.rb', line 72 def live! setup_websocket start_thread end |