From d26e756fa29ac94e33772283bbab3f1a9b1bcd66 Mon Sep 17 00:00:00 2001 From: JJ-Cro Date: Tue, 15 Jul 2025 12:37:35 +0200 Subject: [PATCH] feat(v4.1.16): add keepAlive, add lint script, edit lint errors --- package-lock.json | 4 ++-- package.json | 5 +++-- src/types/index.ts | 1 - src/util/BaseRestClient.ts | 8 ++++++++ src/websocket-client.ts | 1 + 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 85802d4..5b40d1e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bybit-api", - "version": "4.1.15", + "version": "4.1.16", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bybit-api", - "version": "4.1.15", + "version": "4.1.16", "license": "MIT", "dependencies": { "axios": "^1.7.9", diff --git a/package.json b/package.json index a49b471..18321ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bybit-api", - "version": "4.1.15", + "version": "4.1.16", "description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -17,7 +17,8 @@ "build:watch": "npm run clean && tsc --project tsconfig.build.json --watch", "pack": "webpack --config webpack/webpack.config.js", "prepublish": "npm run build:clean", - "betapublish": "npm publish --tag beta" + "betapublish": "npm publish --tag beta", + "lint": "eslint src" }, "author": "Tiago Siebler (https://github.com/tiagosiebler)", "contributors": [], diff --git a/src/types/index.ts b/src/types/index.ts index 5f8a7a0..537ead8 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -5,4 +5,3 @@ export * from './response/v5-spreadtrading'; export * from './shared'; export * from './shared-v5'; export * from './websockets'; - diff --git a/src/util/BaseRestClient.ts b/src/util/BaseRestClient.ts index d7e639a..6da2156 100644 --- a/src/util/BaseRestClient.ts +++ b/src/util/BaseRestClient.ts @@ -138,9 +138,17 @@ export default abstract class BaseRestClient { // If enabled, configure a https agent with keepAlive enabled if (this.options.keepAlive) { + // Extract existing https agent parameters, if provided, to prevent the keepAlive flag from overwriting + // an existing https agent completely + const existingHttpsAgent = this.globalRequestOptions.httpsAgent as + | https.Agent + | undefined; + const existingAgentOptions = existingHttpsAgent?.options || {}; + // For more advanced configuration, raise an issue on GitHub or use the "networkOptions" // parameter to define a custom httpsAgent with the desired properties this.globalRequestOptions.httpsAgent = new https.Agent({ + ...existingAgentOptions, keepAlive: true, keepAliveMsecs: this.options.keepAliveMsecs, }); diff --git a/src/websocket-client.ts b/src/websocket-client.ts index 2497320..dc287a6 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -751,6 +751,7 @@ export class WebsocketClient extends BaseWebsocketClient< if (!reqId) { this.logger.error( + // eslint-disable-next-line max-len 'WS API response is missing reqId - promisified workflow could get stuck. If this happens, please get in touch with steps to reproduce. Trace:', { wsKey,