Websocket event handling through hollaex-node-lib

I found this very useful npm library called hollaex-node-lib hollaex-node-lib - npm

I am using the websocket to get orderbook data so following the example code provided:

client.ws.on('message', (data) => {
	data = JSON.parse(data);
	console.log(data);
});

This works great and I am able to receive the events I subscribe too. However after couple of hours I get socket hang up error and it disconnects.

How should I handle the error event handling and reconnect my websocket to keep the channel open?

1 Like

Hey Martin,

For hollaex-node-lib versions 2.0.0 and up, websocket connections should automatically try to reconnect every 5 seconds unless you’ve explicitly closed the connection yourself using the disconnect() function. The library attempts reconnections on close, unexpected-response, and error events.

2 Likes