Sha256: 955bc8f1ec52e7bce1396c62bc7f6d4f49951a1be8acf05063302f5e5e29c54b
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
module Deribit class WS class Handler attr_accessor :timestamp 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"] def initialize @timestamp = Time.now.to_i end 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 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 def handle_error(json, error) puts "Alert! #{error.class} on message: '#{json.try(:fetch, :message)}', #{json.inspect}. Message: #{error.full_message}" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
deribit-1.3.2 | lib/deribit/ws/handler.rb |