binance-api-node icon indicating copy to clipboard operation
binance-api-node copied to clipboard

Option to disconnect all WebSocket connections

Open bennycode opened this issue 2 years ago • 1 comments

Is there an option to disconnect the client from all open WebSocket connections? I couldn't find such function in the WebSocket interface: https://github.com/Ashlar/binance-api-node/blob/0.11.30/index.d.ts#L625

bennycode avatar Feb 09 '22 12:02 bennycode

The WebSocket connection method returns the closing function. You can use it to close that connection.

Example:

const wsClose = api.ws.ticker(<symbol>, response => {
    console.log(response)
});

// After 10 seconds the ticker websocket will disconnect
setTimeout(() => {
    console.log(wsClose())
}, 10000)

hirenreshamwala avatar Feb 21 '22 06:02 hirenreshamwala

Thank you for the hint!

I got it solved now using:

const closeHandler = client.ws.candles('ETHBTC', '1m', candle => {
  console.log(candle);
});

closeHandler({delay: 0, fastClose: true, keepClosed: true});

bennycode avatar Aug 08 '23 12:08 bennycode