Class: Deribit::WS::Handler

Inherits:
BaseHandler show all
Defined in:
lib/deribit/ws/handler.rb

Instance Attribute Summary collapse

Attributes inherited from BaseHandler

#timestamp, #ws

Instance Method Summary collapse

Methods inherited from BaseHandler

#process

Constructor Details

#initializeHandler

Returns a new instance of Handler.



6
7
8
9
# File 'lib/deribit/ws/handler.rb', line 6

def initialize
  @subscriptions = []
  super
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



4
5
6
# File 'lib/deribit/ws/handler.rb', line 4

def access_token
  @access_token
end

#subscriptionsObject

Returns the value of attribute subscriptions.



4
5
6
# File 'lib/deribit/ws/handler.rb', line 4

def subscriptions
  @subscriptions
end

Instance Method Details

#auth(json) ⇒ Object



29
30
31
# File 'lib/deribit/ws/handler.rb', line 29

def auth(json)
  @access_token = json.dig(:result, :access_token)
end

#heartbeat(json) ⇒ Object

test request response



12
13
14
15
16
17
18
# File 'lib/deribit/ws/handler.rb', line 12

def heartbeat(json)
  # debug
  # puts "GOT HEARTBEAT, json: #{json}"
  if json.dig(:params, :type) == "test_request"
    ws.send(path: "public/test")
  end
end

#subscribe(json) ⇒ Object



20
21
22
# File 'lib/deribit/ws/handler.rb', line 20

def subscribe(json)
  @subscriptions += json[:result]
end

#subscription(json) ⇒ Object



33
34
35
36
37
38
# File 'lib/deribit/ws/handler.rb', line 33

def subscription(json)
  channel = json.dig(:params, :channel)
  data = json.dig(:params, :data)

  puts "GOT subscription EVENT: #{json}"
end

#unsubscribe(json) ⇒ Object



24
25
26
27
# File 'lib/deribit/ws/handler.rb', line 24

def unsubscribe(json)
  channels = json[:result]
  channels.each { |ch| @subscriptions.delete(ch) }
end