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

SENTINEL = "SENTINEL"

Constructors

Instance Method Summary

Constructor Detail

def self.new(symbols : Array(String), streams : Array(String), handler : Binance::Handler, timeout : Time::Span = 0.seconds, 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.


def self.new(symbol : String, streams : Array(String), handler : Binance::Handler, timeout : Time::Span = 0.seconds, service = Binance::Service::Com) #

def self.new(symbols : Array(String), stream : String, handler_class, timeout : Time::Span = 0.seconds, 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.


def self.new(symbol : String, stream : String, handler_class, timeout : Time::Span = 0.seconds, service = Binance::Service::Com) #

def self.new(stream : String, handler_class, timeout : Time::Span = 0.seconds, service = Binance::Service::Com) #

Instance Method Detail

def attach_events(ws) #

def build_stream_names(stream_name : String) #

def build_stream_names(stream_names : Array(String)) #

def handler_class? : Binance::Handler.class #

def handler_for_stream(stream) #

def handlers : Hash(String, Binance::Handler) #

def last_seen : Time #

def listen #

def message_stream(message : ChannelMessage) #

def messages : Int32 #

def messages=(messages : Int32) #

def open_connection #

def run #

def service : Service #

def service=(service : Service) #

def service_host #

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.


def stopped : Bool #

def stopped=(stopped : Bool) #

def stream_names : String #

def symbols : Array(String) #

def symbols_param #

def timeout : Time::Span #

def websocket : HTTP::WebSocket #