class Binance::Listener
- Binance::Listener
- Reference
- Object
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.crConstant Summary
-
SENTINEL =
"SENTINEL"
Constructors
-
.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.
- .new(symbol : String, streams : Array(String), handler : Binance::Handler, timeout : Time::Span = 0.seconds, service = Binance::Service::Com)
-
.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.
- .new(symbol : String, stream : String, handler_class, timeout : Time::Span = 0.seconds, service = Binance::Service::Com)
- .new(stream : String, handler_class, timeout : Time::Span = 0.seconds, service = Binance::Service::Com)
Instance Method Summary
- #attach_events(ws)
- #build_stream_names(stream_name : String)
- #build_stream_names(stream_names : Array(String))
- #handler_class? : Binance::Handler.class
- #handler_for_stream(stream)
- #handlers : Hash(String, Binance::Handler)
- #last_seen : Time
- #listen
- #message_stream(message : ChannelMessage)
- #messages : Int32
- #messages=(messages : Int32)
- #open_connection
- #run
- #service : Service
- #service=(service : Service)
- #service_host
-
#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.
- #stopped : Bool
- #stopped=(stopped : Bool)
- #stream_names : String
- #symbols : Array(String)
- #symbols_param
- #timeout : Time::Span
- #websocket : HTTP::WebSocket
Constructor Detail
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.
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.
Instance Method Detail
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.