Class: RTCBX

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

Candles, Orderbook, Trader

Defined Under Namespace

Classes: Candles, Orderbook, Trader

Constant Summary collapse

PING_INTERVAL =

seconds in between pinging the connection.

15
VERSION =
'0.0.3'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RTCBX.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rtcbx.rb', line 25

def initialize(options = {}, &block)
  @product_id     = options.fetch(:product_id, 'BTC-USD')
  @start          = options.fetch(:start, true)
  @api_key        = options.fetch(:api_key, '')
  @api_secret     = options.fetch(:api_secret, '')
  @api_passphrase = options.fetch(:api_passphrase, '')
  @message_callbacks = []
  @message_callbacks << 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_keyObject (readonly)

Returns the value of attribute api_key.



17
18
19
# File 'lib/rtcbx.rb', line 17

def api_key
  @api_key
end

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#last_pongObject (readonly)

Returns the value of attribute last_pong.



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

def last_pong
  @last_pong
end

#message_callbacksObject (readonly)

Returns the value of attribute message_callbacks.



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

def message_callbacks
  @message_callbacks
end

#product_idObject (readonly)

Returns the value of attribute product_id.



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

def product_id
  @product_id
end

#queueObject (readonly)

Returns the value of attribute queue.



21
22
23
# File 'lib/rtcbx.rb', line 21

def queue
  @queue
end

#startObject (readonly)

Returns the value of attribute start.



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

def start
  @start
end

#websocketObject (readonly)

Returns the value of attribute websocket.



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

def websocket
  @websocket
end

#websocket_threadObject (readonly)

Returns the value of attribute websocket_thread.



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

def websocket_thread
  @websocket_thread
end

Instance Method Details

#reset!Object



56
57
58
59
# File 'lib/rtcbx.rb', line 56

def reset!
  stop!
  start!
end

#start!Object



47
48
49
# File 'lib/rtcbx.rb', line 47

def start!
  start_websocket_thread
end

#stop!Object



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

def stop!
  websocket_thread.kill
  websocket.stop!
end