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
-
SHARED =
"_SHARED_"
Constructors
-
.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.
-
.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.
-
.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.
- .new(streams : Strings, handler : Binance::Handler, timeout : Time::Span = 0.seconds, service : Binance::Service = Binance::Service::Com)
Instance Method Summary
- #all_handler(stream)
- #array_wrap(value : Strings)
- #attach_events(ws)
- #build_handlers(symbols : Array(String), handler : Binance::Handler)
- #build_handlers(symbols : Array(String), handler_class)
- #build_stream_names(symbols, stream_name : String)
- #build_stream_names(symbols, stream_names : Array(String))
- #channel : ListenerChannel
- #handler_for_stream(stream)
- #handlers : Hash(String, Binance::Handler)
- #last_seen : Time
- #listen
- #message_stream(message : ChannelMessage)
- #messages : Int32
- #messages=(messages : Int32)
- #new_handler_hash(handler_class)
- #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_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.
No symbols provided for Listeners that are listening on all markets.
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.