chore(): run linter, after fixing config

This commit is contained in:
tiagosiebler
2024-11-08 13:11:24 +00:00
parent 7023b0aa75
commit 9f20a00ecc
14 changed files with 76 additions and 50 deletions

View File

@@ -7,7 +7,7 @@ module.exports = {
}, },
plugins: [ plugins: [
'@typescript-eslint/eslint-plugin', '@typescript-eslint/eslint-plugin',
'simple-import-sort', // 'simple-import-sort',
// 'require-extensions', // 'require-extensions',
], ],
extends: [ extends: [
@@ -78,7 +78,7 @@ module.exports = {
'@typescript-eslint/interface-name-prefix': 'off', '@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off',
'simple-import-sort/imports': 'error', // 'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error', // 'simple-import-sort/exports': 'error',
}, },
}; };

View File

@@ -86,7 +86,10 @@ export class CopyTradingClient extends BaseRestClient {
); );
} }
/** Close Order. This endpoint's rate_limit will decrease by 10 per request; ie, one request to this endpoint consumes 10 from the limit allowed per minute. */ /** Close Order.
* This endpoint's rate_limit will decrease by 10 per request;
* ie, one request to this endpoint consumes 10 from the limit allowed per minute.
*/
closeOrder( closeOrder(
params: CopyTradingCloseOrderRequest, params: CopyTradingCloseOrderRequest,
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<any>> {

View File

@@ -1,3 +1,4 @@
/* eslint-disable max-len */
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
import { import {
APIResponseV3, APIResponseV3,

View File

@@ -53,7 +53,7 @@ export class SpotClientV3 extends BaseRestClient {
getMergedOrderBook( getMergedOrderBook(
symbol: string, symbol: string,
scale?: number, scale?: number,
limit?: number limit?: number,
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<any>> {
return this.get('/spot/v3/public/quote/depth/merged', { return this.get('/spot/v3/public/quote/depth/merged', {
symbol, symbol,
@@ -73,7 +73,7 @@ export class SpotClientV3 extends BaseRestClient {
interval: KlineInterval, interval: KlineInterval,
limit?: number, limit?: number,
startTime?: number, startTime?: number,
endTime?: number endTime?: number,
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<any>> {
return this.get('/spot/v3/public/quote/kline', { return this.get('/spot/v3/public/quote/kline', {
symbol, symbol,
@@ -124,7 +124,7 @@ export class SpotClientV3 extends BaseRestClient {
/** Batch cancel orders */ /** Batch cancel orders */
cancelOrderBatch( cancelOrderBatch(
params: SpotCancelOrderBatchRequest params: SpotCancelOrderBatchRequest,
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<any>> {
const orderTypes = params.orderTypes const orderTypes = params.orderTypes
? params.orderTypes.join(',') ? params.orderTypes.join(',')
@@ -149,7 +149,7 @@ export class SpotClientV3 extends BaseRestClient {
symbol?: string, symbol?: string,
orderId?: string, orderId?: string,
limit?: number, limit?: number,
orderCategory?: 0 | 1 orderCategory?: 0 | 1,
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<any>> {
return this.getPrivate('/spot/v3/private/open-orders', { return this.getPrivate('/spot/v3/private/open-orders', {
symbol, symbol,
@@ -164,7 +164,7 @@ export class SpotClientV3 extends BaseRestClient {
symbol?: string, symbol?: string,
orderId?: string, orderId?: string,
limit?: number, limit?: number,
orderCategory?: 0 | 1 orderCategory?: 0 | 1,
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<any>> {
return this.getPrivate('/spot/v3/private/history-orders', { return this.getPrivate('/spot/v3/private/history-orders', {
symbol, symbol,
@@ -224,7 +224,7 @@ export class SpotClientV3 extends BaseRestClient {
purchaseLeveragedToken( purchaseLeveragedToken(
ltCode: string, ltCode: string,
ltAmount: string, ltAmount: string,
serialNo?: string serialNo?: string,
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<any>> {
return this.postPrivate('/spot/v3/private/purchase', { return this.postPrivate('/spot/v3/private/purchase', {
ltCode, ltCode,
@@ -237,7 +237,7 @@ export class SpotClientV3 extends BaseRestClient {
redeemLeveragedToken( redeemLeveragedToken(
ltCode: string, ltCode: string,
ltAmount: string, ltAmount: string,
serialNo?: string serialNo?: string,
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<any>> {
return this.postPrivate('/spot/v3/private/redeem', { return this.postPrivate('/spot/v3/private/redeem', {
ltCode, ltCode,
@@ -248,7 +248,7 @@ export class SpotClientV3 extends BaseRestClient {
/** Get leveraged token purchase/redemption history */ /** Get leveraged token purchase/redemption history */
getLeveragedTokenPRHistory( getLeveragedTokenPRHistory(
params?: SpotLeveragedTokenPRHistoryRequest params?: SpotLeveragedTokenPRHistoryRequest,
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<any>> {
return this.getPrivate('/spot/v3/private/record', params); return this.getPrivate('/spot/v3/private/record', params);
} }
@@ -262,7 +262,7 @@ export class SpotClientV3 extends BaseRestClient {
/** Borrow margin loan */ /** Borrow margin loan */
borrowCrossMarginLoan( borrowCrossMarginLoan(
coin: string, coin: string,
qty: string qty: string,
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<any>> {
return this.postPrivate('/spot/v3/private/cross-margin-loan', { return this.postPrivate('/spot/v3/private/cross-margin-loan', {
coin, coin,
@@ -280,7 +280,7 @@ export class SpotClientV3 extends BaseRestClient {
/** Query borrowing info */ /** Query borrowing info */
getCrossMarginBorrowingInfo( getCrossMarginBorrowingInfo(
params?: SpotCrossMarginBorrowingInfoRequest params?: SpotCrossMarginBorrowingInfoRequest,
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<any>> {
return this.getPrivate('/spot/v3/private/cross-margin-orders', params); return this.getPrivate('/spot/v3/private/cross-margin-orders', params);
} }
@@ -297,11 +297,11 @@ export class SpotClientV3 extends BaseRestClient {
/** Query repayment history */ /** Query repayment history */
getCrossMarginRepaymentHistory( getCrossMarginRepaymentHistory(
params?: SpotCrossMarginRepaymentHistoryRequest params?: SpotCrossMarginRepaymentHistoryRequest,
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<any>> {
return this.getPrivate( return this.getPrivate(
'/spot/v3/private/cross-margin-repay-history', '/spot/v3/private/cross-margin-repay-history',
params params,
); );
} }
} }

View File

@@ -133,12 +133,12 @@ export interface LinearSetMarginSwitchRequest {
export interface LinearSetPositionModeRequest { export interface LinearSetPositionModeRequest {
symbol: string; symbol: string;
mode: typeof linearPositionModeEnum[keyof typeof linearPositionModeEnum]; mode: (typeof linearPositionModeEnum)[keyof typeof linearPositionModeEnum];
} }
export interface LinearSetPositionTpSlModeRequest { export interface LinearSetPositionTpSlModeRequest {
symbol: string; symbol: string;
tp_sl_mode: typeof positionTpSlModeEnum[keyof typeof positionTpSlModeEnum]; tp_sl_mode: (typeof positionTpSlModeEnum)[keyof typeof positionTpSlModeEnum];
} }
export interface LinearSetAddReduceMarginRequest { export interface LinearSetAddReduceMarginRequest {

View File

@@ -12,7 +12,6 @@ export type InstrumentStatusV5 =
| 'Delivering' | 'Delivering'
| 'Closed'; | 'Closed';
export type MarginTradingV5 = 'none' | 'both' | 'utaOnly' | 'normalSpotOnly'; export type MarginTradingV5 = 'none' | 'both' | 'utaOnly' | 'normalSpotOnly';
export type OrderFilterV5 = 'Order' | 'tpslOrder' | 'StopOrder'; export type OrderFilterV5 = 'Order' | 'tpslOrder' | 'StopOrder';
@@ -175,7 +174,10 @@ export type OptionTypeV5 = 'Call' | 'Put';
export type TradeModeV5 = 0 | 1; export type TradeModeV5 = 0 | 1;
export type TPSLModeV5 = 'Full' | 'Partial'; export type TPSLModeV5 = 'Full' | 'Partial';
export type AccountMarginModeV5 = 'ISOLATED_MARGIN' | 'REGULAR_MARGIN' | 'PORTFOLIO_MARGIN'; export type AccountMarginModeV5 =
| 'ISOLATED_MARGIN'
| 'REGULAR_MARGIN'
| 'PORTFOLIO_MARGIN';
export type UnifiedUpdateStatusV5 = 'FAIL' | 'PROCESS' | 'SUCCESS'; export type UnifiedUpdateStatusV5 = 'FAIL' | 'PROCESS' | 'SUCCESS';
export type AccountTypeV5 = export type AccountTypeV5 =

View File

@@ -60,7 +60,11 @@ export interface WSOrderbookV5 {
seq: number; seq: number;
} }
export type WSOrderbookEventV5 = WSPublicTopicEventV5<string, 'delta' | 'snapshot', WSOrderbookV5[]>; export type WSOrderbookEventV5 = WSPublicTopicEventV5<
string,
'delta' | 'snapshot',
WSOrderbookV5[]
>;
export interface WSPositionV5 { export interface WSPositionV5 {
category: string; category: string;
@@ -103,7 +107,10 @@ export interface WSPositionV5 {
seq: number; seq: number;
} }
export type WSPositionEventV5 = WSPrivateTopicEventV5<'position', WSPositionV5[]>; export type WSPositionEventV5 = WSPrivateTopicEventV5<
'position',
WSPositionV5[]
>;
export interface WSAccountOrderV5 { export interface WSAccountOrderV5 {
category: CategoryV5; category: CategoryV5;
@@ -155,7 +162,10 @@ export interface WSAccountOrderV5 {
updatedTime: string; updatedTime: string;
} }
export type WSAccountOrderEventV5 = WSPrivateTopicEventV5<'order', WSAccountOrderV5[]>; export type WSAccountOrderEventV5 = WSPrivateTopicEventV5<
'order',
WSAccountOrderV5[]
>;
export interface WSExecutionV5 { export interface WSExecutionV5 {
category: CategoryV5; category: CategoryV5;
@@ -190,4 +200,7 @@ export interface WSExecutionV5 {
marketUnit: string; marketUnit: string;
} }
export type WSExecutionEventV5 = WSPrivateTopicEventV5<'execution', WSExecutionV5[]>; export type WSExecutionEventV5 = WSPrivateTopicEventV5<
'execution',
WSExecutionV5[]
>;

View File

@@ -1,3 +1,4 @@
/* eslint-disable max-len */
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
import { import {
APIResponseV3, APIResponseV3,

View File

@@ -1,3 +1,4 @@
/* eslint-disable max-len */
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
import { import {
APIResponseV3, APIResponseV3,
@@ -133,7 +134,10 @@ export class USDCPerpetualClient extends BaseRestClient {
); );
} }
/** Active order parameters (such as quantity, price) and stop order parameters cannot be modified in one request at the same time. Please request modification separately. */ /**
* Active order parameters (such as quantity, price) and stop order parameters cannot be modified in one request at the same time.
* Please request modification separately.
*/
modifyOrder(params: USDCPerpModifyOrderRequest): Promise<APIResponseV3<any>> { modifyOrder(params: USDCPerpModifyOrderRequest): Promise<APIResponseV3<any>> {
return this.postPrivate( return this.postPrivate(
'/perpetual/usdc/openapi/private/v1/replace-order', '/perpetual/usdc/openapi/private/v1/replace-order',

View File

@@ -71,7 +71,7 @@ export default class WsStore {
if (this.hasExistingActiveConnection(key)) { if (this.hasExistingActiveConnection(key)) {
this.logger.warning( this.logger.warning(
'WsStore setConnection() overwriting existing open connection: ', 'WsStore setConnection() overwriting existing open connection: ',
this.getWs(key) this.getWs(key),
); );
} }
this.wsState[key] = { this.wsState[key] = {
@@ -86,7 +86,7 @@ export default class WsStore {
const ws = this.getWs(key); const ws = this.getWs(key);
this.logger.warning( this.logger.warning(
'WsStore deleting state for connection still open: ', 'WsStore deleting state for connection still open: ',
ws ws,
); );
ws?.close(); ws?.close();
} }
@@ -107,7 +107,7 @@ export default class WsStore {
if (this.isWsOpen(key)) { if (this.isWsOpen(key)) {
this.logger.warning( this.logger.warning(
'WsStore setConnection() overwriting existing open connection: ', 'WsStore setConnection() overwriting existing open connection: ',
this.getWs(key) this.getWs(key),
); );
} }
this.get(key, true)!.ws = wsConnection; this.get(key, true)!.ws = wsConnection;

View File

@@ -1,6 +1,6 @@
export async function signMessage( export async function signMessage(
message: string, message: string,
secret: string secret: string,
): Promise<string> { ): Promise<string> {
const encoder = new TextEncoder(); const encoder = new TextEncoder();
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
@@ -9,21 +9,21 @@ export async function signMessage(
encoder.encode(secret), encoder.encode(secret),
{ name: 'HMAC', hash: { name: 'SHA-256' } }, { name: 'HMAC', hash: { name: 'SHA-256' } },
false, false,
['sign'] ['sign'],
); );
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const signature = await window.crypto.subtle.sign( const signature = await window.crypto.subtle.sign(
'HMAC', 'HMAC',
key, key,
encoder.encode(message) encoder.encode(message),
); );
return Array.prototype.map return Array.prototype.map
.call( .call(
new Uint8Array(signature), new Uint8Array(signature),
(x: { toString: (arg0: number) => string }) => (x: { toString: (arg0: number) => string }) =>
('00' + x.toString(16)).slice(-2) ('00' + x.toString(16)).slice(-2),
) )
.join(''); .join('');
} }

View File

@@ -3,7 +3,7 @@ import { createHmac } from 'crypto';
/** This is async because the browser version uses a promise (browser-support) */ /** This is async because the browser version uses a promise (browser-support) */
export async function signMessage( export async function signMessage(
message: string, message: string,
secret: string secret: string,
): Promise<string> { ): Promise<string> {
return createHmac('sha256', secret).update(message).digest('hex'); return createHmac('sha256', secret).update(message).digest('hex');
} }

View File

@@ -2,7 +2,12 @@
* Use type guards to narrow down types with minimal efforts. * Use type guards to narrow down types with minimal efforts.
*/ */
import { WSAccountOrderEventV5, WSExecutionEventV5, WSOrderbookEventV5, WSPositionEventV5 } from '../types/websocket.events'; import {
WSAccountOrderEventV5,
WSExecutionEventV5,
WSOrderbookEventV5,
WSPositionEventV5,
} from '../types/websocket.events';
/** /**
* Type guard to detect a V5 orderbook event (delta & snapshots) * Type guard to detect a V5 orderbook event (delta & snapshots)

View File

@@ -4,18 +4,12 @@
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import WebSocket from 'isomorphic-ws'; import WebSocket from 'isomorphic-ws';
import { ContractClient } from './contract-client';
import { InverseClient } from './inverse-client'; import { InverseClient } from './inverse-client';
import { LinearClient } from './linear-client'; import { LinearClient } from './linear-client';
import { SpotClientV3 } from './spot-client-v3'; import { RestClientV5 } from './rest-client-v5';
import { SpotClient } from './spot-client'; import { SpotClient } from './spot-client';
import { USDCOptionClient } from './usdc-option-client'; import { SpotClientV3 } from './spot-client-v3';
import { USDCPerpetualClient } from './usdc-perpetual-client';
import { UnifiedMarginClient } from './unified-margin-client';
import { ContractClient } from './contract-client';
import { signMessage } from './util/node-support';
import WsStore from './util/WsStore';
import { import {
APIMarket, APIMarket,
CategoryV5, CategoryV5,
@@ -26,7 +20,10 @@ import {
WsKey, WsKey,
WsTopic, WsTopic,
} from './types'; } from './types';
import { WebsocketTopicSubscriptionConfirmationEvent } from './types/ws-events/topic-subscription-confirmation';
import { UnifiedMarginClient } from './unified-margin-client';
import { USDCOptionClient } from './usdc-option-client';
import { USDCPerpetualClient } from './usdc-perpetual-client';
import { import {
DefaultLogger, DefaultLogger,
PUBLIC_WS_KEYS, PUBLIC_WS_KEYS,
@@ -44,8 +41,8 @@ import {
safeTerminateWs, safeTerminateWs,
serializeParams, serializeParams,
} from './util'; } from './util';
import { RestClientV5 } from './rest-client-v5'; import { signMessage } from './util/node-support';
import { WebsocketTopicSubscriptionConfirmationEvent } from './types/ws-events/topic-subscription-confirmation'; import WsStore from './util/WsStore';
const loggerCategory = { category: 'bybit-ws' }; const loggerCategory = { category: 'bybit-ws' };