Closed vikt20 closed 8 months ago
You should not really use the websocket returned by these subscribe*() calls. That WebSocket only lives for that connection, and if a reconnection happens, it will be replaced. All event handling should be on your instance of the websocket client itself. Take a look at the example here: https://github.com/tiagosiebler/binance/blob/master/examples/ws-public.ts#L34-L47
Note that if you want formatted events, you should also make sure to include beautify: true
in the wsclient options, as shown in this example as well.
Will close for now, feel free to reopen if you have more questions or issues here
const ws = await binance.subscribeUsdFuturesUserDataStream();
These events are firing
ws.on('open', () => console.log(
Connected to Binance
)); ws.on('close', () => console.log(Closed connection
)); ws.on('message', (data) => console.log(Message:
, data));These are not
ws.on('reconnecting', () => console.log(
Connecting to Binance
)); ws.on('reconnected', () => console.log(Reconnected to Binance
)); ws.on('formattedMessage', (data) => console.log(FormattedMessage:
, data)); ws.on('formattedUserDataMessage', (data) => console.log(FormattedUserDataMessage:
, data));Testing (close ws with auto reconnection)
setTimeout(() => binance.closeWs(ws, true), 3000)
What am I doing wrong? I appreciate your help.