Class: Deribit::WS::Handler
- Inherits:
-
Object
- Object
- Deribit::WS::Handler
- 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
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #handle_error(json, error) ⇒ Object
-
#initialize ⇒ Handler
constructor
A new instance of Handler.
- #method_missing(m, *json, &block) ⇒ Object
- #notice(json) ⇒ Object
Constructor Details
#initialize ⇒ Handler
Returns a new instance of Handler.
28 29 30 |
# File 'lib/deribit/ws/handler.rb', line 28 def initialize = Time.now.to_i end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *json, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/deribit/ws/handler.rb', line 32 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.
5 6 7 |
# File 'lib/deribit/ws/handler.rb', line 5 def end |
Instance Method Details
#handle_error(json, error) ⇒ Object
50 51 52 |
# File 'lib/deribit/ws/handler.rb', line 50 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
43 44 45 46 47 48 |
# File 'lib/deribit/ws/handler.rb', line 43 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 |