gtklocker / bittrex-orderbook

Follow the bittrex.com orderbook in real time
34 stars 6 forks source link

Cannot disconnect websocket after getting data. #9

Open gitterxo opened 6 years ago

gitterxo commented 6 years ago

Hello.

I can't seem to be able to disconnect the websocket after I get the data I need. I've looked in the files but couldn't not find a way. Is there anything I am missing ?

gtklocker commented 6 years ago

Hi, thanks for trying out bittrex-orderbook!

I'm afraid you're right, there's currently no way to disconnect. Without being certain I think bit.conn.client.end() (assuming bit is your BittrexOrderbook object) will probably do what you need if you actually need to disconnect from the websocket. Would you be interested in adding this functionality with a PR?

If you just need to stop the events from coming in though you could alternatively do bit.market(...).removeAllListeners().

Let me know how you get on with this.

gitterxo commented 6 years ago

Using both methods it works great. I tried the client.end() method before I posted here and it worked but the connection would send another message or maybe more before disconnecting. When I also removed the listeners after I ended the connection everything is great. Thank you for your great work