From 6b1863c289942cd6ace64c39e32b0ddda08bfeb2 Mon Sep 17 00:00:00 2001 From: Morphling <283893159@qq.com> Date: Tue, 18 Apr 2023 04:37:11 +0800 Subject: [PATCH] Add syncTimeBeforePrivateRequest option Add syncTimeBeforePrivateRequest option to determines whether to perform time synchronization before sending private requests --- src/util/BaseRestClient.ts | 6 ++++++ src/util/requestUtils.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/util/BaseRestClient.ts b/src/util/BaseRestClient.ts index 5ad441e..a71c478 100644 --- a/src/util/BaseRestClient.ts +++ b/src/util/BaseRestClient.ts @@ -113,6 +113,8 @@ export default abstract class BaseRestClient { enable_time_sync: false, /** How often to sync time drift with bybit servers (if time sync is enabled) */ sync_interval_ms: 3600000, + /** Determines whether to perform time synchronization before sending private requests */ + syncTimeBeforePrivateRequests: false, /** Request parameter values are now URI encoded by default during signing. Set to false to override this behaviour. */ encodeSerialisedValues: true, ...restOptions, @@ -203,6 +205,10 @@ export default abstract class BaseRestClient { await this.syncTime(); } + if (this.options.syncTimeBeforePrivateRequests) { + this.timeOffset = await this.fetchTimeOffset(); + } + return this.signRequest(params || {}, method, signMethod); } diff --git a/src/util/requestUtils.ts b/src/util/requestUtils.ts index 9526ab5..9661060 100644 --- a/src/util/requestUtils.ts +++ b/src/util/requestUtils.ts @@ -22,6 +22,9 @@ export interface RestClientOptions { /** How often to sync time drift with bybit servers */ sync_interval_ms?: number | string; + /** Determines whether to perform time synchronization before sending private requests */ + syncTimeBeforePrivateRequests?: false; + /** Default: false. If true, we'll throw errors if any params are undefined */ strict_param_validation?: boolean;