chore(): fix and run linter, bump node version to LTS
This commit is contained in:
@@ -20,7 +20,7 @@ module.exports = {
|
||||
node: true,
|
||||
jest: true,
|
||||
},
|
||||
ignorePatterns: ['.eslintrc.js'],
|
||||
ignorePatterns: ['.eslintrc.js', 'webpack.config.js'],
|
||||
rules: {
|
||||
'@typescript-eslint/interface-name-prefix': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
@@ -30,5 +30,24 @@ module.exports = {
|
||||
'@typescript-eslint/ban-types': 'off',
|
||||
'simple-import-sort/imports': 'error',
|
||||
'simple-import-sort/exports': 'error',
|
||||
'array-bracket-spacing': ['error', 'never'],
|
||||
'linebreak-style': ['error', 'unix'],
|
||||
'lines-between-class-members': ['warn', 'always'],
|
||||
semi: ['error', 'always'],
|
||||
'new-cap': 'off',
|
||||
'no-console': 'off',
|
||||
'no-debugger': 'off',
|
||||
'no-mixed-spaces-and-tabs': 2,
|
||||
'no-use-before-define': [2, 'nofunc'],
|
||||
'no-unreachable': ['warn'],
|
||||
// 'no-unused-vars': ['warn'],
|
||||
'no-extra-parens': ['off'],
|
||||
'no-mixed-operators': ['off'],
|
||||
quotes: [2, 'single', 'avoid-escape'],
|
||||
'block-scoped-var': 2,
|
||||
'brace-style': [2, '1tbs', { allowSingleLine: true }],
|
||||
'computed-property-spacing': [2, 'never'],
|
||||
'keyword-spacing': 2,
|
||||
'space-unary-ops': 2,
|
||||
},
|
||||
};
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -27,3 +27,4 @@ restClientRegex.ts
|
||||
localtest.sh
|
||||
privaterepotracker
|
||||
testfile.ts
|
||||
dist
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"test/**/*.*",
|
||||
"examples/**/*.*",
|
||||
".eslintrc.cjs",
|
||||
"jest.config.ts"
|
||||
"jest.config.ts",
|
||||
"webpack/webpack.config.ts"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const webpack = require('webpack');
|
||||
const path = require('path');
|
||||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
||||
const BundleAnalyzerPlugin =
|
||||
require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
||||
|
||||
function generateConfig(name) {
|
||||
var config = {
|
||||
@@ -10,27 +10,29 @@ function generateConfig(name) {
|
||||
filename: name + '.js',
|
||||
sourceMapFilename: name + '.map',
|
||||
library: name,
|
||||
libraryTarget: 'umd'
|
||||
libraryTarget: 'umd',
|
||||
},
|
||||
devtool: "source-map",
|
||||
devtool: 'source-map',
|
||||
mode: 'production',
|
||||
|
||||
resolve: {
|
||||
// Add '.ts' and '.tsx' as resolvable extensions.
|
||||
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"],
|
||||
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js'],
|
||||
alias: {
|
||||
[path.resolve(__dirname, "../lib/util/node-support.js")]:
|
||||
path.resolve(__dirname, "../lib/util/browser-support.js"),
|
||||
}
|
||||
[path.resolve(__dirname, '../lib/util/node-support.js')]: path.resolve(
|
||||
__dirname,
|
||||
'../lib/util/browser-support.js',
|
||||
),
|
||||
},
|
||||
},
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
// All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
|
||||
{ test: /\.tsx?$/, loader: "ts-loader" },
|
||||
{ test: /\.tsx?$/, loader: 'ts-loader' },
|
||||
|
||||
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
|
||||
{ test: /\.js$/, loader: "source-map-loader" },
|
||||
{ test: /\.js$/, loader: 'source-map-loader' },
|
||||
|
||||
{
|
||||
test: /\.m?js$/,
|
||||
@@ -38,28 +40,30 @@ function generateConfig(name) {
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
presets: [['@babel/preset-env', {
|
||||
'targets': {
|
||||
'node': 'current'
|
||||
}
|
||||
}]]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
targets: {
|
||||
node: 'current',
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
config.plugins = [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
||||
}),
|
||||
new BundleAnalyzerPlugin({
|
||||
defaultSizes: 'stat',
|
||||
analyzerMode: 'static',
|
||||
reportFilename: '../doc/bundleReport.html',
|
||||
openAnalyzer: false,
|
||||
})
|
||||
}),
|
||||
];
|
||||
|
||||
return config;
|
||||
|
||||
Reference in New Issue
Block a user