Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.10.18: feat(#368) add config for HTTP keep alive via axios #371

Merged
merged 1 commit into from
Sep 9, 2024
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
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": "bybit-api",
"version": "3.10.17",
"version": "3.10.18",
"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",
Expand Down
11 changes: 11 additions & 0 deletions src/util/BaseRestClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
import https from 'https';

import {
APIID,
Expand Down Expand Up @@ -137,6 +138,16 @@ export default abstract class BaseRestClient {
},
};

// If enabled, configure a https agent with keepAlive enabled
if (this.options.keepAlive) {
// 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({
keepAlive: true,
keepAliveMsecs: this.options.keepAliveMsecs,
});
}

this.baseUrl = getRestBaseUrl(!!this.options.testnet, restOptions);
this.key = this.options.key;
this.secret = this.options.secret;
Expand Down
13 changes: 13 additions & 0 deletions src/util/requestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ export interface RestClientOptions {
*/
enable_time_sync?: boolean;

/**
* Enable keep alive for REST API requests (via axios).
* See: https://github.com/tiagosiebler/bybit-api/issues/368
*/
keepAlive?: boolean;

/**
* When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
* Only relevant if keepAlive is set to true.
* Default: 1000 (defaults comes from https agent)
*/
keepAliveMsecs?: number;

/** How often to sync time drift with bybit servers */
sync_interval_ms?: number | string;

Expand Down