Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ localtest.ts
repomix.sh
doc
*.pem
.env
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "binance",
"version": "3.6.10",
"version": "3.6.11",
"description": "Professional Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & end-to-end tests.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
5 changes: 5 additions & 0 deletions src/util/BaseWSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ export abstract class BaseWebsocketClient<
*/
protected abstract isAuthOnConnectWsKey(wsKey: TWSKey): boolean;

/** Release resources owned by the concrete client after intentional socket closure. */
protected abstract onWsCloseCleanup(wsKey: TWSKey): void;

protected abstract isCustomReconnectionNeeded(wsKey: TWSKey): boolean;

protected abstract triggerCustomReconnectionWorkflow(
Expand Down Expand Up @@ -1323,6 +1326,8 @@ export abstract class BaseWebsocketClient<
this.emit('reconnecting', { wsKey, event });
} else {
// intentional close - clean up
this.onWsCloseCleanup(wsKey);

// clean up any pending promises for this connection
this.logger.trace(
`onWsClose(${wsKey}): rejecting all deferred promises...`,
Expand Down
3 changes: 3 additions & 0 deletions src/util/typeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export function isWsFuturesConnection(data: WsFormattedMessage): boolean {
}

export function isWSAPIWsKey(wsKey: WsKey): wsKey is WSAPIWsKey {
// Listen-key subscriptions use derived keys rather than the static WsKey names.
if (wsKey.includes('_userData_')) return false;

switch (wsKey) {
case 'mainWSAPITestnet':
case 'mainWSAPI':
Expand Down
9 changes: 9 additions & 0 deletions src/websocket-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ export class WebsocketClient extends BaseWebsocketClient<
});
}

protected onWsCloseCleanup(wsKey: WsKey): void {
const context = getLegacyWsKeyContext(wsKey);
if (context && context?.listenKey) {
this.getUserDataStreamManager().teardownUserDataListenKey(
context.listenKey,
);
}
}

private getUserDataStreamManager(): UserDataStreamManager {
return this.userDataStreamManager;
}
Expand Down
Loading