bybit-api
Advanced tools
Comparing version 2.2.2 to 2.3.0
@@ -35,3 +35,3 @@ import { AxiosRequestConfig } from 'axios'; | ||
/** | ||
* Trigger time sync and store promise | ||
* Trigger time sync and store promise. Use force: true, if automatic time sync is disabled | ||
*/ | ||
@@ -38,0 +38,0 @@ private syncTime; |
@@ -24,6 +24,8 @@ "use strict"; | ||
this.options = Object.assign({ recv_window: 5000, | ||
// how often to sync time drift with bybit servers | ||
sync_interval_ms: 3600000, | ||
// if true, we'll throw errors if any params are undefined | ||
strict_param_validation: false }, options); | ||
/** Throw errors if any params are undefined */ | ||
strict_param_validation: false, | ||
/** Disable time sync by default */ | ||
enable_time_sync: false, | ||
/** How often to sync time drift with bybit servers (if time sync is enabled) */ | ||
sync_interval_ms: 3600000 }, options); | ||
this.globalRequestOptions = Object.assign(Object.assign({ | ||
@@ -38,3 +40,3 @@ // in ms == 5 minutes by default | ||
} | ||
if (this.options.disable_time_sync !== true) { | ||
if (this.options.enable_time_sync) { | ||
this.syncTime(); | ||
@@ -168,6 +170,7 @@ setInterval(this.syncTime.bind(this), +this.options.sync_interval_ms); | ||
/** | ||
* Trigger time sync and store promise | ||
* Trigger time sync and store promise. Use force: true, if automatic time sync is disabled | ||
*/ | ||
syncTime() { | ||
if (this.options.disable_time_sync === true) { | ||
syncTime(force) { | ||
if (!force && !this.options.enable_time_sync) { | ||
this.timeOffset = 0; | ||
return Promise.resolve(false); | ||
@@ -174,0 +177,0 @@ } |
export interface RestClientOptions { | ||
/** Override the max size of the request window (in ms) */ | ||
recv_window?: number; | ||
/** @deprecated Time sync is now disabled by default. To re-enable it, use enable_time_sync instead. */ | ||
disable_time_sync?: boolean; | ||
/** Disabled by default. This can help on machines with consistent latency problems. */ | ||
enable_time_sync?: boolean; | ||
/** How often to sync time drift with bybit servers */ | ||
sync_interval_ms?: number | string; | ||
disable_time_sync?: boolean; | ||
/** Default: false. If true, we'll throw errors if any params are undefined */ | ||
strict_param_validation?: boolean; | ||
/** | ||
* Optionally override API protocol + domain | ||
* e.g baseUrl: 'https://api.bytick.com' | ||
**/ | ||
baseUrl?: string; | ||
/** Default: true. whether to try and post-process request exceptions. */ | ||
parse_exceptions?: boolean; | ||
@@ -8,0 +19,0 @@ } |
@@ -40,2 +40,4 @@ /// <reference types="node" /> | ||
wsUrl?: string; | ||
/** If true, fetch server time before trying to authenticate (disabled by default) */ | ||
fetchTimeOffsetBeforeAuth?: boolean; | ||
} | ||
@@ -42,0 +44,0 @@ export interface WebsocketClientOptions extends WSClientConfigurableOptions { |
@@ -21,2 +21,3 @@ "use strict"; | ||
const logger_1 = require("./logger"); | ||
const spot_client_1 = require("./spot-client"); | ||
const node_support_1 = require("./util/node-support"); | ||
@@ -111,3 +112,3 @@ const requestUtils_1 = require("./util/requestUtils"); | ||
this.wsStore = new WsStore_1.default(this.logger); | ||
this.options = Object.assign({ livenet: false, pongTimeout: 1000, pingInterval: 10000, reconnectTimeout: 500 }, options); | ||
this.options = Object.assign({ livenet: false, pongTimeout: 1000, pingInterval: 10000, reconnectTimeout: 500, fetchTimeOffsetBeforeAuth: false }, options); | ||
if (!this.options.market) { | ||
@@ -120,4 +121,3 @@ this.options.market = resolveMarket(this.options); | ||
else if (this.isSpot()) { | ||
// TODO: spot client | ||
this.restClient = new linear_client_1.LinearClient(undefined, undefined, this.isLivenet(), this.options.restOptions, this.options.requestOptions); | ||
this.restClient = new spot_client_1.SpotClient(undefined, undefined, this.isLivenet(), this.options.restOptions, this.options.requestOptions); | ||
this.connectPublic(); | ||
@@ -270,3 +270,5 @@ } | ||
this.logger.debug("Getting auth'd request params", Object.assign(Object.assign({}, loggerCategory), { wsKey })); | ||
const timeOffset = yield this.restClient.fetchTimeOffset(); | ||
const timeOffset = this.options.fetchTimeOffsetBeforeAuth | ||
? yield this.restClient.fetchTimeOffset() | ||
: 0; | ||
const params = { | ||
@@ -273,0 +275,0 @@ api_key: this.options.key, |
{ | ||
"name": "bybit-api", | ||
"version": "2.2.2", | ||
"version": "2.3.0", | ||
"description": "Node.js connector for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -67,6 +67,6 @@ # bybit-api | ||
// how often to sync time drift with bybit servers | ||
sync_interval_ms?: number | string; | ||
sync_interval_ms?: number; | ||
// Default: false. Disable above sync mechanism if true. | ||
disable_time_sync?: boolean; | ||
enable_time_sync?: boolean; | ||
@@ -73,0 +73,0 @@ // Default: false. If true, we'll throw errors if any params are undefined |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
174467
3023