class Binance::Listener

Overview

The Listener class is responsible for managing the websocket connection and passing all messages to the Handler. No parsing is done here. The JSON of the message is passed as a String object ready to be parsed.

Binance's websocket service ocassionally goes quiet with no updates and without closing the websocket stream. Because of this, the Listener class implements a watcher in another thread that will periodically check to see if data is still flowing. If not, the websocket stream is closed. Any of your handlers that are processing data and running in a Fiber on a timed-loop should also check the Handler's #stopped property to see if the Listener's websocket stream has closed.

Defined in:

binance/client/websocket/listener.cr

Constant Summary

SHARED = "_SHARED_"

Constructors

Instance Method Summary

Constructor Detail

def self.new(symbols : Strings, streams : Strings, handler_class : Binance::Handler.class, timeout : Time::Span = 0.seconds, service : Binance::Service = Binance::Service::Com) #

Uses one handler for all market/symbols when an instantiated handler is passed If a timeout > 0.seconds is given, then a watcher loop is started and will force close the websocket stream if data stops flowing for longer than the given timeout span.


[View source]
def self.new(symbols : Strings, streams : Strings, handler : Binance::Handler, timeout : Time::Span = 0.seconds, service : Binance::Service = Binance::Service::Com) #

One handler for each market/symbol is instantiated. If a timeout > 0.seconds is given, then a watcher loop is started and will force close the websocket stream if data stops flowing for longer than the given timeout span.


[View source]
def self.new(streams : Strings, handler_class : Binance::Handler.class, timeout : Time::Span = 0.seconds, service : Binance::Service = Binance::Service::Com) #

No symbols provided for Listeners that are listening on all markets.


[View source]
def self.new(streams : Strings, handler : Binance::Handler, timeout : Time::Span = 0.seconds, service : Binance::Service = Binance::Service::Com) #

[View source]

Instance Method Detail

def all_handler(stream) #

[View source]
def array_wrap(value : Strings) #

[View source]
def attach_events(ws) #

[View source]
def build_handlers(symbols : Array(String), handler : Binance::Handler) #

[View source]
def build_handlers(symbols : Array(String), handler_class) #

[View source]
def build_stream_names(symbols, stream_name : String) #

[View source]
def build_stream_names(symbols, stream_names : Array(String)) #

[View source]
def channel : ListenerChannel #

[View source]
def handler_for_stream(stream) #

[View source]
def handlers : Hash(String, Binance::Handler) #

[View source]
def last_seen : Time #

[View source]
def listen #

[View source]
def message_stream(message : ChannelMessage) #

[View source]
def messages : Int32 #

[View source]
def messages=(messages : Int32) #

[View source]
def new_handler_hash(handler_class) #

[View source]
def open_connection #

[View source]
def run #

[View source]
def service : Service #

[View source]
def service=(service : Service) #

[View source]
def service_host #

[View source]
def start_watcher #

If the listener is started with a timeout > 0, then the watcher will close the websocket connection if no messages from the server is received within the timeout span.


[View source]
def stopped : Bool #

[View source]
def stopped=(stopped : Bool) #

[View source]
def stream_names : String #

[View source]
def symbols_param #

[View source]
def timeout : Time::Span #

[View source]
def websocket : HTTP::WebSocket #

[View source]