aloysius-pgast / bittrex-signalr-client

Node.js implementation of SignalR protocol tailored for Bittrex exchange
39 stars 14 forks source link

Documentation request: Event Listener for Close, Error events #24

Closed Slurpgoose closed 4 years ago

Slurpgoose commented 4 years ago

Hi, thank you for your work in creating this library and adding great examples/documentation. I am storing the order book state of all bittrex markets and passing this state to other services in my application on their request through a unix socket.

This library seems to have a good method for reconnecting automatically, but is it currently possible to receive events on_close or on_error?

Goal: prevent exporting stale market states to other services

I am thinking I could use an on_error event to notify me if socket is attempting to reconnect, then if max_reconnect reached error is emitted then call client.disconnect() and initialize a new instance from an on_close event. As well if the client is reconnecting then to set a flag and wait until 'orderBook' event is passed for all markets before removing the flag.

If this is something that is already possible or if you have any ideas for an alternative solution, any help would be greatly appreciated :)

aloysius-pgast commented 4 years ago

Hi. Thanks for your interest. Please take a look at https://github.com/aloysius-pgast/bittrex-signalr-client/blob/master/doc/api.md#emitted-events. Events disconnected and connectionError are probably what you're looking for. You don't have anything to do related to the connection in your event handler since re-connection will be automatic

client.on('connectionError', (data) => {
    // set flag
});
Slurpgoose commented 4 years ago

Thank you so much! I'm sorry for wasting your time, its clearly stated in the docs.