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.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RTCBX.



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

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
  @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.



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

def api_key
  @api_key
end

#api_passphraseObject (readonly)

Returns the value of attribute api_passphrase.



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

def api_passphrase
  @api_passphrase
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



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

def api_secret
  @api_secret
end

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#last_pongObject (readonly)

Returns the value of attribute last_pong.



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

def last_pong
  @last_pong
end

#message_callbacksObject (readonly)

Returns the value of attribute message_callbacks.



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

def message_callbacks
  @message_callbacks
end

#product_idObject (readonly)

Returns the value of attribute product_id.



13
14
15
# File 'lib/rtcbx.rb', line 13

def product_id
  @product_id
end

#queueObject (readonly)

Returns the value of attribute queue.



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

def queue
  @queue
end

#startObject (readonly)

Returns the value of attribute start.



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

def start
  @start
end

#websocketObject (readonly)

Returns the value of attribute websocket.



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

def websocket
  @websocket
end

#websocket_threadObject (readonly)

Returns the value of attribute websocket_thread.



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

def websocket_thread
  @websocket_thread
end

Instance Method Details

#reset!Object



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

def reset!
  stop!
  start!
end

#start!Object



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

def start!
  start_websocket_thread
end

#stop!Object



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

def stop!
  websocket_thread.kill
  websocket.stop!
end