chore(): fix and run linter, bump node version to LTS
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -28,15 +28,6 @@ export interface WsSnapshotPositionsEvent extends WsBaseEvent<'snapshot'> {
|
||||
};
|
||||
}
|
||||
|
||||
export interface WsAccountSnapshotUMCBL extends WsBaseEvent<'snapshot'> {
|
||||
arg: {
|
||||
instType: 'umcbl';
|
||||
channel: 'account';
|
||||
instId: string;
|
||||
};
|
||||
data: WsAccountSnapshotDataUMCBL[];
|
||||
}
|
||||
|
||||
export interface WsAccountSnapshotDataUMCBL {
|
||||
marginCoin: string;
|
||||
locked: string;
|
||||
@@ -47,13 +38,13 @@ export interface WsAccountSnapshotDataUMCBL {
|
||||
usdtEquity: string;
|
||||
}
|
||||
|
||||
export interface WSPositionSnapshotUMCBL extends WsBaseEvent<'snapshot'> {
|
||||
export interface WsAccountSnapshotUMCBL extends WsBaseEvent<'snapshot'> {
|
||||
arg: {
|
||||
instType: 'umcbl';
|
||||
channel: 'positions';
|
||||
channel: 'account';
|
||||
instId: string;
|
||||
};
|
||||
data: WsPositionSnapshotDataUMCBL[];
|
||||
data: WsAccountSnapshotDataUMCBL[];
|
||||
}
|
||||
|
||||
export interface WsPositionSnapshotDataUMCBL {
|
||||
@@ -80,3 +71,12 @@ export interface WsPositionSnapshotDataUMCBL {
|
||||
uTime: string;
|
||||
markPrice: string;
|
||||
}
|
||||
|
||||
export interface WSPositionSnapshotUMCBL extends WsBaseEvent<'snapshot'> {
|
||||
arg: {
|
||||
instType: 'umcbl';
|
||||
channel: 'positions';
|
||||
instId: string;
|
||||
};
|
||||
data: WsPositionSnapshotDataUMCBL[];
|
||||
}
|
||||
|
||||
@@ -70,10 +70,15 @@ if (ENABLE_HTTP_TRACE) {
|
||||
|
||||
export default abstract class BaseRestClient {
|
||||
private options: RestClientOptions;
|
||||
|
||||
private baseUrl: string;
|
||||
|
||||
private globalRequestOptions: AxiosRequestConfig;
|
||||
|
||||
private apiKey: string | undefined;
|
||||
|
||||
private apiSecret: string | undefined;
|
||||
|
||||
private apiPass: string | undefined;
|
||||
|
||||
/** Defines the client type (affecting how requests & signatures behave) */
|
||||
@@ -292,6 +297,7 @@ export default abstract class BaseRestClient {
|
||||
params?: TParams,
|
||||
isPublicApi?: true,
|
||||
): Promise<UnsignedRequest<TParams>>;
|
||||
|
||||
private async prepareSignParams<TParams extends object | undefined>(
|
||||
method: Method,
|
||||
endpoint: string,
|
||||
@@ -299,6 +305,7 @@ export default abstract class BaseRestClient {
|
||||
params?: TParams,
|
||||
isPublicApi?: false | undefined,
|
||||
): Promise<SignedRequest<TParams>>;
|
||||
|
||||
private async prepareSignParams<TParams extends object | undefined>(
|
||||
method: Method,
|
||||
endpoint: string,
|
||||
|
||||
@@ -57,6 +57,7 @@ export abstract class BaseWebsocketClient<
|
||||
private wsStore: WsStore<TWSKey, TWSTopicSubscribeEventArgs>;
|
||||
|
||||
protected logger: typeof DefaultLogger;
|
||||
|
||||
protected options: WebsocketClientOptions;
|
||||
|
||||
constructor(
|
||||
@@ -87,7 +88,9 @@ export abstract class BaseWebsocketClient<
|
||||
): boolean;
|
||||
|
||||
protected abstract shouldAuthOnConnect(wsKey: TWSKey): boolean;
|
||||
|
||||
protected abstract getWsUrl(wsKey: TWSKey): string;
|
||||
|
||||
protected abstract getMaxTopicsPerSubscribeEvent(
|
||||
wsKey: TWSKey,
|
||||
): number | null;
|
||||
@@ -280,7 +283,7 @@ export abstract class BaseWebsocketClient<
|
||||
recvWindow,
|
||||
);
|
||||
|
||||
this.logger.info(`Sending auth request...`, {
|
||||
this.logger.info('Sending auth request...', {
|
||||
...LOGGER_CATEGORY,
|
||||
wsKey,
|
||||
});
|
||||
@@ -441,7 +444,7 @@ export abstract class BaseWebsocketClient<
|
||||
|
||||
public tryWsSend(wsKey: TWSKey, wsMessage: string) {
|
||||
try {
|
||||
this.logger.silly(`Sending upstream ws message: `, {
|
||||
this.logger.silly('Sending upstream ws message: ', {
|
||||
...LOGGER_CATEGORY,
|
||||
wsMessage,
|
||||
wsKey,
|
||||
@@ -459,7 +462,7 @@ export abstract class BaseWebsocketClient<
|
||||
}
|
||||
ws.send(wsMessage);
|
||||
} catch (e) {
|
||||
this.logger.error(`Failed to send WS message`, {
|
||||
this.logger.error('Failed to send WS message', {
|
||||
...LOGGER_CATEGORY,
|
||||
wsMessage,
|
||||
wsKey,
|
||||
@@ -552,7 +555,7 @@ export abstract class BaseWebsocketClient<
|
||||
if (typeof msg === 'object') {
|
||||
if (typeof msg['code'] === 'number') {
|
||||
if (msg.event === 'login' && msg.code === 0) {
|
||||
this.logger.info(`Successfully authenticated WS client`, {
|
||||
this.logger.info('Successfully authenticated WS client', {
|
||||
...LOGGER_CATEGORY,
|
||||
wsKey,
|
||||
});
|
||||
@@ -565,7 +568,7 @@ export abstract class BaseWebsocketClient<
|
||||
|
||||
if (msg['event']) {
|
||||
if (msg.event === 'error') {
|
||||
this.logger.error(`WS Error received`, {
|
||||
this.logger.error('WS Error received', {
|
||||
...LOGGER_CATEGORY,
|
||||
wsKey,
|
||||
message: msg || 'no message',
|
||||
|
||||
@@ -18,6 +18,7 @@ export default class WsStore<
|
||||
> {
|
||||
private wsState: Record<string, WsStoredState<TWSTopicSubscribeEventArgs>> =
|
||||
{};
|
||||
|
||||
private logger: typeof DefaultLogger;
|
||||
|
||||
constructor(logger: typeof DefaultLogger) {
|
||||
@@ -29,10 +30,12 @@ export default class WsStore<
|
||||
key: WsKey,
|
||||
createIfMissing?: true,
|
||||
): WsStoredState<TWSTopicSubscribeEventArgs>;
|
||||
|
||||
get(
|
||||
key: WsKey,
|
||||
createIfMissing?: false,
|
||||
): WsStoredState<TWSTopicSubscribeEventArgs> | undefined;
|
||||
|
||||
get(
|
||||
key: WsKey,
|
||||
createIfMissing?: boolean,
|
||||
|
||||
@@ -78,7 +78,7 @@ export function isWsFuturesPositionsSnapshotEvent(
|
||||
*/
|
||||
export function assertMarginType(marginType: string): marginType is MarginType {
|
||||
if (marginType !== 'isolated' && marginType !== 'crossed') {
|
||||
throw new Error(`MarginType should be one of: crossed | isolated`);
|
||||
throw new Error('MarginType should be one of: crossed | isolated');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ export function getMaxTopicsPerSubscribeEvent(wsKey: WsKey): number | null {
|
||||
return 15;
|
||||
}
|
||||
default: {
|
||||
throw neverGuard(wsKey, `getWsKeyForTopic(): Unhandled wsKey`);
|
||||
throw neverGuard(wsKey, 'getWsKeyForTopic(): Unhandled wsKey');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,7 +162,7 @@ export async function getWsAuthSignature(
|
||||
}> {
|
||||
if (!apiKey || !apiSecret || !apiPass) {
|
||||
throw new Error(
|
||||
`Cannot auth - missing api key, secret or passcode in config`,
|
||||
'Cannot auth - missing api key, secret or passcode in config',
|
||||
);
|
||||
}
|
||||
const signatureExpiresAt = ((Date.now() + recvWindow) / 1000).toFixed(0);
|
||||
|
||||
@@ -36,6 +36,7 @@ export class WebsocketClientV2 extends BaseWebsocketClient<
|
||||
WsTopicSubscribeEventArgsV2
|
||||
> {
|
||||
protected logger: typeof DefaultLogger;
|
||||
|
||||
protected options: WebsocketClientOptions;
|
||||
|
||||
protected getWsKeyForTopic(
|
||||
@@ -68,7 +69,7 @@ export class WebsocketClientV2 extends BaseWebsocketClient<
|
||||
case WS_KEY_MAP.spotv1:
|
||||
case WS_KEY_MAP.mixv1: {
|
||||
throw new Error(
|
||||
`Use the WebsocketClient instead of WebsocketClientV2 for V1 websockets`,
|
||||
'Use the WebsocketClient instead of WebsocketClientV2 for V1 websockets',
|
||||
);
|
||||
}
|
||||
case WS_KEY_MAP.v2Private: {
|
||||
@@ -82,7 +83,7 @@ export class WebsocketClientV2 extends BaseWebsocketClient<
|
||||
...LOGGER_CATEGORY,
|
||||
wsKey,
|
||||
});
|
||||
throw neverGuard(wsKey, `getWsUrl(): Unhandled wsKey`);
|
||||
throw neverGuard(wsKey, 'getWsUrl(): Unhandled wsKey');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,9 @@ export declare interface WebsocketClient {
|
||||
*/
|
||||
export class WebsocketClient extends EventEmitter {
|
||||
private logger: typeof DefaultLogger;
|
||||
|
||||
private options: WebsocketClientOptions;
|
||||
|
||||
private wsStore: WsStore<WsKey, WsTopicSubscribeEventArgs>;
|
||||
|
||||
constructor(
|
||||
@@ -144,6 +146,7 @@ export class WebsocketClient extends EventEmitter {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe from topics & remove them from memory. They won't be re-subscribed to if the connection reconnects.
|
||||
* @param wsTopics topic or list of topics
|
||||
@@ -281,7 +284,7 @@ export class WebsocketClient extends EventEmitter {
|
||||
recvWindow,
|
||||
);
|
||||
|
||||
this.logger.info(`Sending auth request...`, {
|
||||
this.logger.info('Sending auth request...', {
|
||||
...LOGGER_CATEGORY,
|
||||
wsKey,
|
||||
});
|
||||
@@ -442,7 +445,7 @@ export class WebsocketClient extends EventEmitter {
|
||||
|
||||
public tryWsSend(wsKey: WsKey, wsMessage: string) {
|
||||
try {
|
||||
this.logger.silly(`Sending upstream ws message: `, {
|
||||
this.logger.silly('Sending upstream ws message: ', {
|
||||
...LOGGER_CATEGORY,
|
||||
wsMessage,
|
||||
wsKey,
|
||||
@@ -460,7 +463,7 @@ export class WebsocketClient extends EventEmitter {
|
||||
}
|
||||
ws.send(wsMessage);
|
||||
} catch (e) {
|
||||
this.logger.error(`Failed to send WS message`, {
|
||||
this.logger.error('Failed to send WS message', {
|
||||
...LOGGER_CATEGORY,
|
||||
wsMessage,
|
||||
wsKey,
|
||||
@@ -553,7 +556,7 @@ export class WebsocketClient extends EventEmitter {
|
||||
if (typeof msg === 'object') {
|
||||
if (typeof msg['code'] === 'number') {
|
||||
if (msg.event === 'login' && msg.code === 0) {
|
||||
this.logger.info(`Successfully authenticated WS client`, {
|
||||
this.logger.info('Successfully authenticated WS client', {
|
||||
...LOGGER_CATEGORY,
|
||||
wsKey,
|
||||
});
|
||||
@@ -566,7 +569,7 @@ export class WebsocketClient extends EventEmitter {
|
||||
|
||||
if (msg['event']) {
|
||||
if (msg.event === 'error') {
|
||||
this.logger.error(`WS Error received`, {
|
||||
this.logger.error('WS Error received', {
|
||||
...LOGGER_CATEGORY,
|
||||
wsKey,
|
||||
message: msg || 'no message',
|
||||
@@ -648,14 +651,14 @@ export class WebsocketClient extends EventEmitter {
|
||||
}
|
||||
case WS_KEY_MAP.v2Private:
|
||||
case WS_KEY_MAP.v2Public: {
|
||||
throw new Error(`Use the WebsocketClientV2 for V2 websockets`);
|
||||
throw new Error('Use the WebsocketClientV2 for V2 websockets');
|
||||
}
|
||||
default: {
|
||||
this.logger.error('getWsUrl(): Unhandled wsKey: ', {
|
||||
...LOGGER_CATEGORY,
|
||||
wsKey,
|
||||
});
|
||||
throw neverGuard(wsKey, `getWsUrl(): Unhandled wsKey`);
|
||||
throw neverGuard(wsKey, 'getWsUrl(): Unhandled wsKey');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user