Class: Deribit::WS::Handler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- Deribit::WS::Handler
- Defined in:
- lib/deribit/ws/handler.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#subscriptions ⇒ Object
Returns the value of attribute subscriptions.
Attributes inherited from BaseHandler
Instance Method Summary collapse
- #auth(json) ⇒ Object
-
#heartbeat(json) ⇒ Object
test request response.
-
#initialize ⇒ Handler
constructor
A new instance of Handler.
- #subscribe(json) ⇒ Object
- #subscription(json) ⇒ Object
- #unsubscribe(json) ⇒ Object
Methods inherited from BaseHandler
Constructor Details
#initialize ⇒ Handler
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_token ⇒ Object
Returns the value of attribute access_token.
4 5 6 |
# File 'lib/deribit/ws/handler.rb', line 4 def access_token @access_token end |
#subscriptions ⇒ Object
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 |