Class: RTCBX
- Inherits:
-
Object
- Object
- RTCBX
- Defined in:
- lib/rtcbx/version.rb,
lib/rtcbx.rb,
lib/rtcbx/trader.rb,
lib/rtcbx/candles.rb,
lib/rtcbx/orderbook.rb,
lib/rtcbx/candles/candle.rb,
lib/rtcbx/orderbook/book_methods.rb,
lib/rtcbx/orderbook/book_analysis.rb
Overview
This class represents the current state of the CoinBase Exchange orderbook.
Defined Under Namespace
Classes: Candles, Orderbook, Trader
Constant Summary collapse
- PING_INTERVAL =
seconds in between pinging the connection.
2- VERSION =
'0.0.5'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
API key used to authenticate to the API Not required for Orderbook or Candles.
-
#client ⇒ Object
readonly
The GDAX Client object You can use this if you need to make API calls.
-
#last_pong ⇒ Object
readonly
Epoch time indicating the last time we received a pong from GDAX in response to one of our pings.
-
#message_callbacks ⇒ Object
readonly
An array of blocks to be run each time a message comes in on the Websocket.
-
#product_id ⇒ Object
readonly
The GDAX product being tracked (eg. “BTC-USD”).
-
#queue ⇒ Object
readonly
The message queue from the Websocket.
-
#start ⇒ Object
readonly
Boolean, whether the orderbook goes live on creation or not If
false,#start!must be called to initiate tracking. -
#websocket ⇒ Object
readonly
The Websocket object.
-
#websocket_thread ⇒ Object
readonly
The thread that consumes the websocket data.
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ RTCBX
constructor
Create a new RTCBX object with options and an optional block to be run when each message is called.
-
#reset! ⇒ Object
Stops, then starts the thread that consumes the Websocket feed.
-
#start! ⇒ Object
Starts the thread to consume the Websocket feed.
-
#stop! ⇒ Object
Stops the thread and disconnects from the Websocket.
Constructor Details
#initialize(options = {}, &block) ⇒ RTCBX
Create a new RTCBX object with options and an optional block to be run when each message is called.
Generally you won’t call this directly. You’ll use RTCBX::Orderbook.new, RTCBX::Trader.new, or RTCBX::Candles.new.
You can also subclass RTCBX and call this method through super, as the classes mentioned above do.
RTCBX handles connecting to the Websocket, setting up the client, and managing the thread that consumes the Websocket feed.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rtcbx.rb', line 57 def initialize( = {}, &block) @product_id = .fetch(:product_id, 'BTC-USD') @start = .fetch(:start, true) @api_key = .fetch(:api_key, '') @api_secret = .fetch(:api_secret, '') @api_passphrase = .fetch(:api_passphrase, '') = [] << block if block_given? @client = Coinbase::Exchange::Client.new( api_key, api_secret, api_passphrase, product_id: product_id ) @websocket = Coinbase::Exchange::Websocket.new( keepalive: true, product_id: product_id ) @queue = Queue.new start! if start end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
API key used to authenticate to the API Not required for Orderbook or Candles
22 23 24 |
# File 'lib/rtcbx.rb', line 22 def api_key @api_key end |
#client ⇒ Object (readonly)
The GDAX Client object You can use this if you need to make API calls
32 33 34 |
# File 'lib/rtcbx.rb', line 32 def client @client end |
#last_pong ⇒ Object (readonly)
Epoch time indicating the last time we received a pong from GDAX in response to one of our pings
40 41 42 |
# File 'lib/rtcbx.rb', line 40 def last_pong @last_pong end |
#message_callbacks ⇒ Object (readonly)
An array of blocks to be run each time a message comes in on the Websocket
25 26 27 |
# File 'lib/rtcbx.rb', line 25 def end |
#product_id ⇒ Object (readonly)
The GDAX product being tracked (eg. “BTC-USD”)
14 15 16 |
# File 'lib/rtcbx.rb', line 14 def product_id @product_id end |
#queue ⇒ Object (readonly)
The message queue from the Websocket. The websocket_thread processes this queue
36 37 38 |
# File 'lib/rtcbx.rb', line 36 def queue @queue end |
#start ⇒ Object (readonly)
Boolean, whether the orderbook goes live on creation or not If false, #start! must be called to initiate tracking.
18 19 20 |
# File 'lib/rtcbx.rb', line 18 def start @start end |
#websocket ⇒ Object (readonly)
The Websocket object
28 29 30 |
# File 'lib/rtcbx.rb', line 28 def websocket @websocket end |
#websocket_thread ⇒ Object (readonly)
The thread that consumes the websocket data
43 44 45 |
# File 'lib/rtcbx.rb', line 43 def websocket_thread @websocket_thread end |
Instance Method Details
#reset! ⇒ Object
Stops, then starts the thread that consumes the Websocket feed
91 92 93 94 |
# File 'lib/rtcbx.rb', line 91 def reset! stop! start! end |
#start! ⇒ Object
Starts the thread to consume the Websocket feed
80 81 82 |
# File 'lib/rtcbx.rb', line 80 def start! start_websocket_thread end |
#stop! ⇒ Object
Stops the thread and disconnects from the Websocket
85 86 87 88 |
# File 'lib/rtcbx.rb', line 85 def stop! websocket_thread.kill websocket.stop! end |