Class: Deribit::WS::Handler
- Inherits:
-
Object
- Object
- Deribit::WS::Handler
show all
- Defined in:
- lib/deribit/ws/handler.rb
Constant Summary
collapse
- AVAILABLE_METHODS =
[
:account,
:getcurrencies,
:subscribe,
:subscribed,
:unsubscribe,
:buy,
:sell,
:trade,
:trade_event,
:order_book_event,
:user_order_event,
:user_orders_event,
:announcements,
:index,
:heartbeat,
:order,
:pong
]
- SILENT =
[:setheartbeat, :subscribed, :heartbeat, :"public API test"]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *json, &block) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/deribit/ws/handler.rb', line 27
def method_missing(m, *json, &block)
return false if SILENT.include?(m.to_sym)
puts "Delegating #{m}"
if AVAILABLE_METHODS.include?(m.to_sym)
notice(json)
else
super
end
end
|
Instance Attribute Details
#timestamp ⇒ Object
Returns the value of attribute timestamp.
4
5
6
|
# File 'lib/deribit/ws/handler.rb', line 4
def timestamp
@timestamp
end
|
Instance Method Details
#handle_error(json, error) ⇒ Object
45
46
47
|
# File 'lib/deribit/ws/handler.rb', line 45
def handle_error(json, error)
puts "Alert! #{error.class} on message: '#{json.try(:fetch, :message)}', #{json.inspect}. Message: #{error.full_message}"
end
|
#notice(json) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/deribit/ws/handler.rb', line 38
def notice(json)
return json.each { |e| notice(e) } if json.is_a?(Array)
msg = json.is_a?(String) ? json : json[:message]
puts "Notice: #{msg}" if msg && !SILENT.include?(msg.to_sym)
end
|
#update_timestamp! ⇒ Object
49
50
51
|
# File 'lib/deribit/ws/handler.rb', line 49
def update_timestamp!
@timestamp = Time.now.to_i
end
|