v2.2.1: fix ws & rest authentication issues caused by time-sync mechanism

This commit is contained in:
tiagosiebler
2022-05-28 20:39:37 +01:00
parent 9eda2f2bd9
commit 18977499f8
5 changed files with 70 additions and 4 deletions

View File

@@ -288,9 +288,10 @@ export default abstract class BaseRestClient {
}
const end = Date.now();
const severTimeMs = serverTime * 1000;
const avgDrift = (end - start) / 2;
return Math.ceil(serverTime - end + avgDrift);
return Math.ceil(severTimeMs - end + avgDrift);
} catch (e) {
console.error('Failed to fetch get time offset: ', e);
return 0;

View File

@@ -6,7 +6,11 @@ import { LinearClient } from './linear-client';
import { DefaultLogger } from './logger';
import { KlineInterval } from './types/shared';
import { signMessage } from './util/node-support';
import { serializeParams, isWsPong } from './util/requestUtils';
import {
serializeParams,
isWsPong,
RestClientOptions,
} from './util/requestUtils';
import WsStore from './util/WsStore';
@@ -141,7 +145,7 @@ export interface WSClientConfigurableOptions {
pongTimeout?: number;
pingInterval?: number;
reconnectTimeout?: number;
restOptions?: any;
restOptions?: RestClientOptions;
requestOptions?: any;
wsUrl?: string;
}