From e92c083961eaafd64140431919d56418b54a5045 Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Tue, 10 Dec 2024 17:29:47 +0000 Subject: [PATCH] chore(): run linter fixes --- .eslintrc.cjs | 4 +- src/broker-client.ts | 2 +- src/futures-client.ts | 60 +-- src/index.ts | 10 +- src/rest-client-v2.ts | 190 ++++---- src/spot-client.ts | 38 +- src/types/index.ts | 2 +- src/types/request/index.ts | 22 +- src/types/request/shared.ts | 78 ++-- src/types/request/v1/futuresV1.ts | 2 +- src/types/request/v1/spotV1.ts | 36 +- src/types/request/v2/common.ts | 374 +++++++-------- src/types/request/v2/spot.ts | 702 ++++++++++++++--------------- src/types/response/index.ts | 2 +- src/types/shared.ts | 2 +- src/util/BaseRestClient.ts | 10 +- src/util/BaseWSClient.ts | 12 +- src/util/WsStore.ts | 1 + src/util/browser-support.ts | 1 + src/util/index.ts | 4 +- src/util/logger.ts | 1 + src/util/node-support.ts | 1 + src/util/requestUtils.ts | 2 +- src/util/websocket-util.ts | 1 + src/websocket-client-v2.ts | 10 +- src/websocket-client.ts | 23 +- test/broker/private.read.test.ts | 6 +- test/broker/private.write.test.ts | 8 +- test/futures/private.write.test.ts | 6 +- test/futures/public.test.ts | 8 +- test/spot/private.read.test.ts | 2 +- test/spot/public.test.ts | 5 +- test/ws.private.test.ts | 11 +- test/ws.public.test.ts | 4 +- test/ws.util.ts | 2 + 35 files changed, 817 insertions(+), 825 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 021f68f..71a433c 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -8,12 +8,12 @@ module.exports = { plugins: [ '@typescript-eslint/eslint-plugin', 'simple-import-sort', - 'require-extensions', + // 'require-extensions', // only once moved to ESM ], extends: [ 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', - 'plugin:require-extensions/recommended', + // 'plugin:require-extensions/recommended', // only once moved to ESM ], root: true, env: { diff --git a/src/broker-client.ts b/src/broker-client.ts index bad3bdc..83daf10 100644 --- a/src/broker-client.ts +++ b/src/broker-client.ts @@ -1,9 +1,9 @@ import { APIResponse, BrokerProductType, - BrokerSubWithdrawalRequest, BrokerSubAPIKeyModifyRequest, BrokerSubListRequest, + BrokerSubWithdrawalRequest, } from './types'; import { REST_CLIENT_TYPE_ENUM } from './util'; import BaseRestClient from './util/BaseRestClient'; diff --git a/src/futures-client.ts b/src/futures-client.ts index 6041ddf..7d2cfbb 100644 --- a/src/futures-client.ts +++ b/src/futures-client.ts @@ -1,32 +1,32 @@ import { APIResponse, - FuturesProductType, + CancelFuturesPlanTPSL, + FuturesAccount, FuturesAccountBillRequest, FuturesBusinessBillRequest, - NewFuturesOrder, - NewBatchFuturesOrder, + FuturesCandleData, + FuturesHistoricPositions, + FuturesKlineInterval, + FuturesMarginMode, + FuturesMarketTrade, FuturesPagination, - NewFuturesPlanOrder, + FuturesPlanType, + FuturesPosition, + FuturesProductType, + FuturesSymbolRule, + GetHistoricTradesParams, + HistoricPlanOrderTPSLRequest, + ModifyFuturesOrder, ModifyFuturesPlanOrder, ModifyFuturesPlanOrderTPSL, - NewFuturesPlanPositionTPSL, ModifyFuturesPlanStopOrder, - CancelFuturesPlanTPSL, - HistoricPlanOrderTPSLRequest, + NewBatchFuturesOrder, + NewFuturesOrder, + NewFuturesPlanOrder, + NewFuturesPlanPositionTPSL, NewFuturesPlanStopOrder, - FuturesAccount, - FuturesSymbolRule, - FuturesMarginMode, - FuturesPosition, NewFuturesPlanTrailingStopOrder, VIPFeeRate, - GetHistoricTradesParams, - FuturesMarketTrade, - FuturesPlanType, - FuturesKlineInterval, - FuturesHistoricPositions, - ModifyFuturesOrder, - FuturesCandleData, } from './types'; import { REST_CLIENT_TYPE_ENUM } from './util'; import BaseRestClient from './util/BaseRestClient'; @@ -105,9 +105,9 @@ export class FuturesClient extends BaseRestClient { symbol: string, granularity: FuturesKlineInterval, startTime: string, - endTime: string, + endTime: string, limit?: string, - kLineType?: 'market' | 'mark' | 'index' + kLineType?: 'market' | 'mark' | 'index', ): Promise> { return this.get('/api/mix/v1/market/candles', { symbol, @@ -569,16 +569,16 @@ export class FuturesClient extends BaseRestClient { return this.postPrivate('/api/mix/v1/plan/cancelPlan', params); } - /** Cancel Symbol Plan Order (TPSL) */ - cancelSymbolPlanOrders( - symbol: string, - planType: FuturesPlanType, - ): Promise> { - return this.postPrivate('/api/mix/v1/plan/cancelSymbolPlan', { - symbol, - planType, - }); - } + /** Cancel Symbol Plan Order (TPSL) */ + cancelSymbolPlanOrders( + symbol: string, + planType: FuturesPlanType, + ): Promise> { + return this.postPrivate('/api/mix/v1/plan/cancelSymbolPlan', { + symbol, + planType, + }); + } /** Cancel All Trigger Order (TPSL) */ cancelAllPlanOrders( diff --git a/src/index.ts b/src/index.ts index 771b2dc..c1c41cf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,10 @@ -export * from './rest-client-v2'; export * from './broker-client'; +export * from './constants/enum'; export * from './futures-client'; +export * from './rest-client-v2'; export * from './spot-client'; +export * from './types'; +export * from './util'; +export * from './util/logger'; export * from './websocket-client'; export * from './websocket-client-v2'; -export * from './util/logger'; -export * from './util'; -export * from './types'; -export * from './constants/enum'; diff --git a/src/rest-client-v2.ts b/src/rest-client-v2.ts index 5774191..5b1cef3 100644 --- a/src/rest-client-v2.ts +++ b/src/rest-client-v2.ts @@ -1,111 +1,111 @@ import { APIResponse, - MarginType, + BorrowLoanRequestV2, + CloseFuturesFollowerPositionsRequestV2, + CopyTradingProductTypeV2, FuturesAccountBillRequestV2, + FuturesBatchCancelOrderRequestV2, + FuturesBatchOrderRequestV2, + FuturesCancelAllOrdersRequestV2, + FuturesCancelOrderRequestV2, + FuturesCancelPlanOrderRequestV2, FuturesCandlesRequestV2, - SpotCandlesRequestV2, - SpotAccountBill, - SpotHistoricCandlesRequestV2, - SpotHistoricTradesRequestV2, - SpotOrderRequestV2, - SpotCancelandSubmitOrderRequestV2, - SpotCancelOrderRequestV2, - SpotBatchOrderRequestV2, - SpotBatchCancelOrderRequestV2, - GetSpotOrderInfoRequestV2, - GetSpotOpenOrdersRequestV2, - GetSpotHistoryOrdersRequestV2, - GetSpotFillsRequestV2, - SpotPlanOrderRequestV2, - SpotModifyPlanOrderRequestV2, - GetSpotCurrentPlanOrdersRequestV2, - GetSpotHistoryPlanOrdersRequestV2, - GetSpotAccountBillsRequestV2, - SpotTransferRequestV2, - SpotAccountTypeV2, - SpotSubAccountTransferRequestV2, - SpotWithdrawalRequestV2, - SpotMainSubTransferRecordRequestV2, - GetSpotTransferRecordRequestV2, - GetSpotSubAccountDepositRecordRequestV2, - GetSpotWithdrawalRecordRequestV2, - GetSpotDepositRecordRequestV2, + FuturesFlashClosePositionsRequestV2, + FuturesGetHistoricalFillsRequestV2, + FuturesGetHistoryOrdersRequestV2, + FuturesGetHistoryPlanOrdersRequestV2, + FuturesGetOpenOrdersRequestV2, + FuturesGetOrderFillsRequestV2, + FuturesGetOrderRequestV2, + FuturesGetPlanOrdersRequestV2, + FuturesHistoricalPositionsRequestV2, + FuturesHistoricTradesRequestV2, + FuturesInterestHistoryRequestV2, FuturesMergeDepthRequestV2, + FuturesModifyOrderRequestV2, + FuturesModifyPlanOrderRequestV2, + FuturesModifyTPSLOrderRequestV2, + FuturesOpenCountRequestV2, + FuturesPlaceOrderRequestV2, + FuturesPlanOrderRequestV2, FuturesProductTypeV2, FuturesRecentTradesRequestV2, - FuturesHistoricTradesRequestV2, - FuturesSingleAccountRequestV2, - FuturesInterestHistoryRequestV2, - FuturesOpenCountRequestV2, + FuturesReversalOrderRequestV2, FuturesSetAutoMarginRequestV2, FuturesSetLeverageRequestV2, - FuturesSetPositionMarginRequestV2, FuturesSetMarginModeRequestV2, - FuturesHistoricalPositionsRequestV2, - FuturesPlaceOrderRequestV2, - FuturesReversalOrderRequestV2, - FuturesBatchOrderRequestV2, - FuturesModifyOrderRequestV2, - FuturesCancelOrderRequestV2, - FuturesBatchCancelOrderRequestV2, - FuturesFlashClosePositionsRequestV2, - FuturesGetOrderRequestV2, - FuturesGetOrderFillsRequestV2, - FuturesGetHistoricalFillsRequestV2, - FuturesGetOpenOrdersRequestV2, - FuturesGetHistoryOrdersRequestV2, - FuturesCancelAllOrdersRequestV2, + FuturesSetPositionMarginRequestV2, + FuturesSingleAccountRequestV2, FuturesTPSLOrderRequestV2, - FuturesPlanOrderRequestV2, - FuturesModifyTPSLOrderRequestV2, - FuturesModifyPlanOrderRequestV2, - FuturesGetPlanOrdersRequestV2, - FuturesCancelPlanOrderRequestV2, - FuturesGetHistoryPlanOrdersRequestV2, - GetBorrowHistoryRequestV2, - GetRepayHistoryRequestV2, - GetInterestHistoryRequestV2, - GetLiquidationHistoryRequestV2, - GetFinancialHistoryRequestV2, - MarginPlaceOrderRequestV2, - MarginBatchOrdersRequestV2, - GetMarginCurrentOrdersRequestV2, - GetHistoryOrdersRequestV2, - GetMarginOrderFillsRequestV2, - GetMarginLiquidationOrdersRequestV2, - GetFuturesTraderCurrentOrdersRequestV2, - GetFuturesTraderHistoryOrdersRequestV2, - ModifyFuturesTraderOrderTPSLRequestV2, - GetFuturesTraderProfitShareDetailRequestV2, - CopyTradingProductTypeV2, FuturesTraderSymbolSettingRequestV2, - GetFuturesTraderFollowersRequestV2, - GetFollowerFuturesCurrentTrackingOrdersRequestV2, - GetFollowerFuturesHistoryTrackingOrdersRequestV2, - UpdateFuturesFollowerTPSLRequestV2, - UpdateFuturesFollowerSettingsRequestV2, - GetFuturesFollowerTradersRequestV2, - CloseFuturesFollowerPositionsRequestV2, - GetSpotTraderHistoryProfitRequestV2, - GetSpotTraderHistoryOrdersRequestV2, - GetSpotTraderCurrentOrdersRequestV2, - GetSpotTraderFollowersRequestV2, - SpotFollowerCopyTradeSettingV2, - GetSpotFollowerHistoryOrdersRequestV2, - GetSpotFollowerOpenOrdersRequestV2, + GetBorrowHistoryRequestV2, GetEarnSavingsAssetsRequestV2, GetEarnSavingsRecordsRequestV2, - RedeemSavingsRequestV2, + GetFinancialHistoryRequestV2, + GetFollowerFuturesCurrentTrackingOrdersRequestV2, + GetFollowerFuturesHistoryTrackingOrdersRequestV2, + GetFuturesFollowerTradersRequestV2, + GetFuturesTraderCurrentOrdersRequestV2, + GetFuturesTraderFollowersRequestV2, + GetFuturesTraderHistoryOrdersRequestV2, + GetFuturesTraderProfitShareDetailRequestV2, + GetHistoryOrdersRequestV2, + GetInterestHistoryRequestV2, + GetLiquidationHistoryRequestV2, + GetLiquidationRecordsRequestV2, + GetLoanEstInterestAndBorrowableRequestV2, + GetLoanHistoryRequestV2, + GetLoanPledgeRateHistoryRequestV2, + GetLoanRepayHistoryRequestV2, + GetMarginCurrentOrdersRequestV2, + GetMarginLiquidationOrdersRequestV2, + GetMarginOrderFillsRequestV2, + GetRepayHistoryRequestV2, GetSharkfinAssetsRequestV2, GetSharkfinRecordsRequestV2, - GetLoanEstInterestAndBorrowableRequestV2, - BorrowLoanRequestV2, - RepayLoanRequestV2, - GetLoanRepayHistoryRequestV2, + GetSpotAccountBillsRequestV2, + GetSpotCurrentPlanOrdersRequestV2, + GetSpotDepositRecordRequestV2, + GetSpotFillsRequestV2, + GetSpotFollowerHistoryOrdersRequestV2, + GetSpotFollowerOpenOrdersRequestV2, + GetSpotHistoryOrdersRequestV2, + GetSpotHistoryPlanOrdersRequestV2, + GetSpotOpenOrdersRequestV2, + GetSpotOrderInfoRequestV2, + GetSpotSubAccountDepositRecordRequestV2, + GetSpotTraderCurrentOrdersRequestV2, + GetSpotTraderFollowersRequestV2, + GetSpotTraderHistoryOrdersRequestV2, + GetSpotTraderHistoryProfitRequestV2, + GetSpotTransferRecordRequestV2, + GetSpotWithdrawalRecordRequestV2, + MarginBatchOrdersRequestV2, + MarginPlaceOrderRequestV2, + MarginType, + ModifyFuturesTraderOrderTPSLRequestV2, ModifyLoanPledgeRateRequestV2, - GetLoanPledgeRateHistoryRequestV2, - GetLoanHistoryRequestV2, - GetLiquidationRecordsRequestV2, + RedeemSavingsRequestV2, + RepayLoanRequestV2, + SpotAccountBill, + SpotAccountTypeV2, + SpotBatchCancelOrderRequestV2, + SpotBatchOrderRequestV2, + SpotCancelandSubmitOrderRequestV2, + SpotCancelOrderRequestV2, + SpotCandlesRequestV2, + SpotFollowerCopyTradeSettingV2, + SpotHistoricCandlesRequestV2, + SpotHistoricTradesRequestV2, + SpotMainSubTransferRecordRequestV2, + SpotModifyPlanOrderRequestV2, + SpotOrderRequestV2, + SpotPlanOrderRequestV2, + SpotSubAccountTransferRequestV2, + SpotTransferRequestV2, + SpotWithdrawalRequestV2, + UpdateFuturesFollowerSettingsRequestV2, + UpdateFuturesFollowerTPSLRequestV2, } from './types'; import { CreateSubAccountApiKeyRequestV2, @@ -122,6 +122,7 @@ import { CreateVirtualSubApiKeyRequestV2, CreateVirtualSubRequestV2, GetAnnouncementsRequestV2, + GetConvertBGBHistoryRequestV2, GetConvertHistoryRequestV2, GetFuturesTransactionsRequestV2, GetMarginTransactionsRequestV2, @@ -131,11 +132,10 @@ import { GetP2PTransactionsRequestV2, GetSpotTransactionsRequestV2, GetTradeRateRequestV2, - ModifyVirtualSubRequestV2, ModifyVirtualSubApiKeyRequestV2, - GetConvertBGBHistoryRequestV2, + ModifyVirtualSubRequestV2, } from './types/request/v2/common'; -import { REST_CLIENT_TYPE_ENUM, assertMarginType } from './util'; +import { assertMarginType, REST_CLIENT_TYPE_ENUM } from './util'; import BaseRestClient from './util/BaseRestClient'; /** @@ -188,7 +188,7 @@ export class RestClientV2 extends BaseRestClient { console.log(result); console.log( - `Your approximate latency to exchange server: + `Your approximate latency to exchange server: One way: ${estimatedOneWayLatency}ms. Round trip: ${roundTripTime}ms. `, diff --git a/src/spot-client.ts b/src/spot-client.ts index 975e976..726e36b 100644 --- a/src/spot-client.ts +++ b/src/spot-client.ts @@ -1,27 +1,27 @@ import { + APIResponse, + BatchCancelSpotOrderV2, + CancelSpotOrderV2, + CancelSpotPlanOrderParams, + CoinBalance, + GetHistoricPlanOrdersParams, + GetHistoricTradesParams, + GetSpotPlanOrdersParams, + ModifySpotPlanOrder, NewBatchSpotOrder, NewSpotOrder, - NewWalletTransfer, - Pagination, - APIResponse, - CoinBalance, - SymbolRules, + NewSpotPlanOrder, NewSpotSubTransfer, NewSpotWithdraw, - CancelSpotOrderV2, - BatchCancelSpotOrderV2, - SpotOrderResult, - NewSpotPlanOrder, - ModifySpotPlanOrder, - CancelSpotPlanOrderParams, - GetSpotPlanOrdersParams, - SpotPlanOrder, - GetHistoricPlanOrdersParams, - SpotMarketTrade, - GetHistoricTradesParams, - VIPFeeRate, - SpotKlineInterval, + NewWalletTransfer, + Pagination, SpotCandleData, + SpotKlineInterval, + SpotMarketTrade, + SpotOrderResult, + SpotPlanOrder, + SymbolRules, + VIPFeeRate, } from './types'; import { REST_CLIENT_TYPE_ENUM } from './util'; import BaseRestClient from './util/BaseRestClient'; @@ -112,7 +112,7 @@ export class SpotClient extends BaseRestClient { getCandles( symbol: string, period: SpotKlineInterval, - pagination?: Pagination, + pagination?: Pagination, ): Promise> { return this.get('/api/spot/v1/market/candles', { symbol, diff --git a/src/types/index.ts b/src/types/index.ts index 82b2b91..86329ba 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,4 +1,4 @@ -export * from './response'; export * from './request'; +export * from './response'; export * from './shared'; export * from './websockets'; diff --git a/src/types/request/index.ts b/src/types/request/index.ts index 4c25afa..1cf44db 100644 --- a/src/types/request/index.ts +++ b/src/types/request/index.ts @@ -1,11 +1,11 @@ -export * from './v1/brokerV1'; -export * from './v1/futuresV1'; -export * from './v1/spotV1'; -export * from './v2/futures'; -export * from './v2/spot'; -export * from './v2/broker'; -export * from './v2/margin'; -export * from './v2/copytrading'; -export * from './v2/earn'; -export * from './shared'; -export * from './v2/common'; +export * from './shared'; +export * from './v1/brokerV1'; +export * from './v1/futuresV1'; +export * from './v1/spotV1'; +export * from './v2/broker'; +export * from './v2/common'; +export * from './v2/copytrading'; +export * from './v2/earn'; +export * from './v2/futures'; +export * from './v2/margin'; +export * from './v2/spot'; diff --git a/src/types/request/shared.ts b/src/types/request/shared.ts index 23b4db4..eb03f3b 100644 --- a/src/types/request/shared.ts +++ b/src/types/request/shared.ts @@ -1,39 +1,39 @@ -/** Pagination */ -export interface Pagination { - /** Time after */ - after?: string; - /** Time before */ - before?: string; - /** Elements per page */ - limit?: string; -} - -export type OrderTimeInForce = 'normal' | 'post_only' | 'fok' | 'ioc'; - -export interface GetHistoricTradesParams { - symbol: string; - limit?: string; - tradeId?: string; - startTime?: string; - endTime?: string; -} - -/** - * The margin type, used directly in building the endpoint URL - */ -export type MarginType = 'crossed' | 'isolated'; - -export type FuturesProductTypeV2 = - | 'USDT-FUTURES' - | 'COIN-FUTURES' - | 'USDC-FUTURES' - | 'SUSDT-FUTURES' - | 'SCOIN-FUTURES' - | 'SUSDC-FUTURES'; - -export type FuturesPlanTypeV2 = - | 'profit_plan' - | 'loss_plan' - | 'moving_plan' - | 'pos_profit' - | 'pos_loss'; +/** Pagination */ +export interface Pagination { + /** Time after */ + after?: string; + /** Time before */ + before?: string; + /** Elements per page */ + limit?: string; +} + +export type OrderTimeInForce = 'normal' | 'post_only' | 'fok' | 'ioc'; + +export interface GetHistoricTradesParams { + symbol: string; + limit?: string; + tradeId?: string; + startTime?: string; + endTime?: string; +} + +/** + * The margin type, used directly in building the endpoint URL + */ +export type MarginType = 'crossed' | 'isolated'; + +export type FuturesProductTypeV2 = + | 'USDT-FUTURES' + | 'COIN-FUTURES' + | 'USDC-FUTURES' + | 'SUSDT-FUTURES' + | 'SCOIN-FUTURES' + | 'SUSDC-FUTURES'; + +export type FuturesPlanTypeV2 = + | 'profit_plan' + | 'loss_plan' + | 'moving_plan' + | 'pos_profit' + | 'pos_loss'; diff --git a/src/types/request/v1/futuresV1.ts b/src/types/request/v1/futuresV1.ts index 527e967..0dedc9d 100644 --- a/src/types/request/v1/futuresV1.ts +++ b/src/types/request/v1/futuresV1.ts @@ -226,4 +226,4 @@ export interface HistoricPlanOrderTPSLRequest { * @property {Array[5]} Base currency trading volume * @property {Array[6]} Quote currency trading volume */ -export type FuturesCandleData = string[6]; \ No newline at end of file +export type FuturesCandleData = string[6]; diff --git a/src/types/request/v1/spotV1.ts b/src/types/request/v1/spotV1.ts index 0009c4a..f3f4b85 100644 --- a/src/types/request/v1/spotV1.ts +++ b/src/types/request/v1/spotV1.ts @@ -3,23 +3,23 @@ import { OrderTimeInForce } from '../shared'; export type WalletType = 'spot' | 'mix_usdt' | 'mix_usd'; export type SpotKlineInterval = - | '1min' - | '5min' - | '15min' - | '30min' - | '1h' - | '4h' - | '6h' - | '12h' - | '1day' - | '3day' - | '1week' - | '1M' - | '6Hutc' - | '12Hutc' - | '1Dutc' - | '3Dutc' - | '1Wutc' + | '1min' + | '5min' + | '15min' + | '30min' + | '1h' + | '4h' + | '6h' + | '12h' + | '1day' + | '3day' + | '1week' + | '1M' + | '6Hutc' + | '12Hutc' + | '1Dutc' + | '3Dutc' + | '1Wutc' | '1Mutc'; export interface NewWalletTransfer { @@ -135,4 +135,4 @@ export interface SpotCandleData { baseVol: string; usdtVol: string; ts: string; -} \ No newline at end of file +} diff --git a/src/types/request/v2/common.ts b/src/types/request/v2/common.ts index 051273b..a8f60ec 100644 --- a/src/types/request/v2/common.ts +++ b/src/types/request/v2/common.ts @@ -1,187 +1,187 @@ -import { FuturesProductTypeV2, MarginType } from '../shared'; - -/** - * - * * Common | Notice - * - */ - -export interface GetAnnouncementsRequestV2 { - annType?: string; - startTime?: string; - endTime?: string; - language: string; -} - -/** - * - * * Common | Public - * - */ - -export interface GetTradeRateRequestV2 { - symbol: string; - businessType: string; -} - -/** - * - * * Common | Tax - * - */ - -export interface GetSpotTransactionsRequestV2 { - coin?: string; - startTime: string; - endTime: string; - limit?: string; - idLessThan?: string; -} - -export interface GetFuturesTransactionsRequestV2 { - productType?: FuturesProductTypeV2; - marginCoin?: string; - startTime: string; - endTime: string; - limit?: string; - idLessThan?: string; -} - -export interface GetMarginTransactionsRequestV2 { - marginType?: MarginType; - coin?: string; - startTime: string; - endTime: string; - limit?: string; - idLessThan?: string; -} - -export interface GetP2PTransactionsRequestV2 { - coin?: string; - startTime: string; - endTime: string; - limit?: string; - idLessThan?: string; -} - -/** - * - * * Common | P2P - * - */ - -export interface GetP2PMerchantsRequestV2 { - online?: 'yes' | 'no'; - idLessThan?: string; - limit?: string; -} - -export interface GetMerchantP2POrdersRequestV2 { - startTime: string; - endTime?: string; - idLessThan?: string; - limit?: string; - status?: string; - advNo: string; - side?: string; - coin?: string; - language: string; - fiat?: string; - orderNo?: string; -} - -export interface GetMerchantAdvertisementsRequestV2 { - startTime: string; - endTime?: string; - idLessThan?: string; - limit?: string; - status: string; - advNo?: string; - side: string; - coin: string; - language?: string; - fiat: string; - orderBy?: string; - payMethodId?: string; - sourceType?: string; -} - -/** - * - * * Common | Virtual Subaccount - * - */ - -export interface ModifyVirtualSubRequestV2 { - subAccountUid: string; - permList: string[]; - status: string; -} - -export interface CreateVirtualSubRequestV2 { - subAccountName: string; - passphrase: string; - label: string; - ipList?: string[]; - permList?: string[]; -} - -export interface CreateVirtualSubApiKeyRequestV2 { - subAccountUid: string; - passphrase: string; - label: string; - ipList?: string[]; - permList?: string[]; -} - -export interface ModifyVirtualSubApiKeyRequestV2 { - subAccountUid: string; - subAccountApiKey: string; - passphrase: string; - label: string; - ipList?: string[]; - permList?: string[]; -} - -/** - * - * * Common | Convert - * - */ - -export interface ConvertQuoteRequestV2 { - fromCoin: string; - fromCoinSize?: string; - toCoin: string; - toCoinSize?: string; -} - -export interface ConvertRequestV2 { - fromCoin: string; - fromCoinSize: string; - cnvtPrice: string; - toCoin: string; - toCoinSize: string; - traceId: string; -} - -export interface GetConvertHistoryRequestV2 { - startTime: string; - endTime: string; - limit?: string; - idLessThan?: string; -} - -/** - * - * * Common | BGB Convert - * - */ - -export interface GetConvertBGBHistoryRequestV2 { - orderId?: string; - startTime: string; - endTime: string; - limit?: string; - idLessThan?: string; -} +import { FuturesProductTypeV2, MarginType } from '../shared'; + +/** + * + * * Common | Notice + * + */ + +export interface GetAnnouncementsRequestV2 { + annType?: string; + startTime?: string; + endTime?: string; + language: string; +} + +/** + * + * * Common | Public + * + */ + +export interface GetTradeRateRequestV2 { + symbol: string; + businessType: string; +} + +/** + * + * * Common | Tax + * + */ + +export interface GetSpotTransactionsRequestV2 { + coin?: string; + startTime: string; + endTime: string; + limit?: string; + idLessThan?: string; +} + +export interface GetFuturesTransactionsRequestV2 { + productType?: FuturesProductTypeV2; + marginCoin?: string; + startTime: string; + endTime: string; + limit?: string; + idLessThan?: string; +} + +export interface GetMarginTransactionsRequestV2 { + marginType?: MarginType; + coin?: string; + startTime: string; + endTime: string; + limit?: string; + idLessThan?: string; +} + +export interface GetP2PTransactionsRequestV2 { + coin?: string; + startTime: string; + endTime: string; + limit?: string; + idLessThan?: string; +} + +/** + * + * * Common | P2P + * + */ + +export interface GetP2PMerchantsRequestV2 { + online?: 'yes' | 'no'; + idLessThan?: string; + limit?: string; +} + +export interface GetMerchantP2POrdersRequestV2 { + startTime: string; + endTime?: string; + idLessThan?: string; + limit?: string; + status?: string; + advNo: string; + side?: string; + coin?: string; + language: string; + fiat?: string; + orderNo?: string; +} + +export interface GetMerchantAdvertisementsRequestV2 { + startTime: string; + endTime?: string; + idLessThan?: string; + limit?: string; + status: string; + advNo?: string; + side: string; + coin: string; + language?: string; + fiat: string; + orderBy?: string; + payMethodId?: string; + sourceType?: string; +} + +/** + * + * * Common | Virtual Subaccount + * + */ + +export interface ModifyVirtualSubRequestV2 { + subAccountUid: string; + permList: string[]; + status: string; +} + +export interface CreateVirtualSubRequestV2 { + subAccountName: string; + passphrase: string; + label: string; + ipList?: string[]; + permList?: string[]; +} + +export interface CreateVirtualSubApiKeyRequestV2 { + subAccountUid: string; + passphrase: string; + label: string; + ipList?: string[]; + permList?: string[]; +} + +export interface ModifyVirtualSubApiKeyRequestV2 { + subAccountUid: string; + subAccountApiKey: string; + passphrase: string; + label: string; + ipList?: string[]; + permList?: string[]; +} + +/** + * + * * Common | Convert + * + */ + +export interface ConvertQuoteRequestV2 { + fromCoin: string; + fromCoinSize?: string; + toCoin: string; + toCoinSize?: string; +} + +export interface ConvertRequestV2 { + fromCoin: string; + fromCoinSize: string; + cnvtPrice: string; + toCoin: string; + toCoinSize: string; + traceId: string; +} + +export interface GetConvertHistoryRequestV2 { + startTime: string; + endTime: string; + limit?: string; + idLessThan?: string; +} + +/** + * + * * Common | BGB Convert + * + */ + +export interface GetConvertBGBHistoryRequestV2 { + orderId?: string; + startTime: string; + endTime: string; + limit?: string; + idLessThan?: string; +} diff --git a/src/types/request/v2/spot.ts b/src/types/request/v2/spot.ts index 84eb86c..aec28e7 100644 --- a/src/types/request/v2/spot.ts +++ b/src/types/request/v2/spot.ts @@ -1,351 +1,351 @@ -type SpotKlineIntervalV2 = - | '1min' - | '5min' - | '15min' - | '30min' - | '1h' - | '4h' - | '6h' - | '12h' - | '1day' - | '3day' - | '1week' - | '1M' - | '6Hutc' - | '12Hutc' - | '1Dutc' - | '3Dutc' - | '1Wutc' - | '1Mutc'; - -export interface SpotCandlesRequestV2 { - symbol: string; - granularity: SpotKlineIntervalV2; - startTime?: string; - endTime?: string; - limit?: string; -} - -export interface SpotHistoricCandlesRequestV2 { - symbol: string; - granularity: SpotKlineIntervalV2; - endTime?: string; - limit?: string; -} - -export interface SpotHistoricTradesRequestV2 { - symbol: string; - limit?: string; - idLessThan?: string; - startTime?: string; - endTime?: string; -} - -/** - * - * * Spot | Trade - * - */ - -export type SpotOrderSideV2 = 'buy' | 'sell'; - -export type SpotOrderTypeV2 = 'limit' | 'market'; - -export type SpotOrderForceV2 = 'gtc' | 'post_only' | 'fok' | 'ioc'; - -export type SpotTPSLTypeV2 = 'normal' | 'tpsl'; - -export type SpotSTPModeV2 = - | 'none' - | 'cancel_taker' - | 'cancel_maker' - | 'cancel_both'; - -export type SpotBatchModeV2 = 'single' | 'multiple'; - -export interface SpotOrderRequestV2 { - symbol: string; - side: SpotOrderSideV2; - orderType: SpotOrderTypeV2; - force: SpotOrderForceV2; - price?: string; - size: string; - clientOid?: string; - triggerPrice?: string; - tpslType?: SpotTPSLTypeV2; - requestTime?: string; - receiveWindow?: string; - stpMode?: SpotSTPModeV2; - presetTakeProfitPrice?: string; - executeTakeProfitPrice?: string; - presetStopLossPrice?: string; - executeStopLossPrice?: string; -} - -export interface SpotCancelandSubmitOrderRequestV2 { - symbol: string; - price: string; - size: string; - orderId?: string; - clientOid?: string; - newClientOid?: string; - presetTakeProfitPrice?: string; - executeTakeProfitPrice?: string; - presetStopLossPrice?: string; - executeStopLossPrice?: string; -} - -export interface SpotCancelOrderRequestV2 { - symbol: string; - tpslType?: SpotTPSLTypeV2; - orderId?: string; - clientOid?: string; -} - -export interface SpotBatchOrderRequestItemV2 { - symbol?: string; - side: SpotOrderSideV2; - orderType: SpotOrderTypeV2; - force: SpotOrderForceV2; - price?: string; - size: string; - clientOid?: string; - stpMode?: SpotSTPModeV2; - presetTakeProfitPrice?: string; - executeTakeProfitPrice?: string; - presetStopLossPrice?: string; - executeStopLossPrice?: string; -} - -export interface SpotBatchOrderRequestV2 { - symbol?: string; - batchMode?: SpotBatchModeV2; - orderList: SpotBatchOrderRequestItemV2[]; -} - -export interface SpotBatchCancelOrderRequestV2 { - symbol?: string; - batchMode?: SpotBatchModeV2; - orderList: { - symbol?: string; - orderId?: string; - clientOid?: string; - }[]; -} - -export interface GetSpotOrderInfoRequestV2 { - orderId?: string; - clientOid?: string; - requestTime?: string; - receiveWindow?: string; -} - -export interface GetSpotOpenOrdersRequestV2 { - symbol?: string; - startTime?: string; - endTime?: string; - idLessThan?: string; - limit?: string; - orderId?: string; - tpslType?: SpotTPSLTypeV2; - requestTime?: string; - receiveWindow?: string; -} - -export interface GetSpotHistoryOrdersRequestV2 { - symbol?: string; - startTime?: string; - endTime?: string; - idLessThan?: string; - limit?: string; - orderId?: string; - tpslType?: SpotTPSLTypeV2; - requestTime?: string; - receiveWindow?: string; -} - -export interface GetSpotFillsRequestV2 { - symbol: string; - orderId?: string; - startTime?: string; - endTime?: string; - limit?: string; - idLessThan?: string; -} - -/** - * - * * Spot | Trigger Orders - * - */ - -export type SpotPlanTypeV2 = 'amount' | 'total'; - -export type SpotTriggerTypeV2 = 'fill_price' | 'mark_price'; - -export interface SpotPlanOrderRequestV2 { - symbol: string; - side: SpotOrderSideV2; - triggerPrice: string; - orderType: SpotOrderTypeV2; - executePrice?: string; - planType?: SpotPlanTypeV2; - size: string; - triggerType: SpotTriggerTypeV2; - clientOid?: string; - force?: SpotOrderForceV2; - stpMode?: SpotSTPModeV2; -} - -export interface SpotModifyPlanOrderRequestV2 { - orderId?: string; - clientOid?: string; - triggerPrice: string; - orderType: SpotOrderTypeV2; - executePrice?: string; - size: string; -} - -export interface GetSpotCurrentPlanOrdersRequestV2 { - symbol: string; - limit?: string; - idLessThan?: string; - startTime?: string; - endTime?: string; -} - -export interface GetSpotHistoryPlanOrdersRequestV2 { - symbol: string; - startTime: string; - endTime: string; - limit?: string; -} - -/** - * - * * Spot | Account - * - */ - -export type SpotBillGroupTypeV2 = - | 'deposit' - | 'withdraw' - | 'transaction' - | 'transfer' - | 'other'; - -export type SpotBusinessTypeV2 = - | 'deposit' - | 'withdraw' - | 'buy' - | 'sell' - | 'deduction of handling fee' - | 'transfer-in' - | 'transfer-out' - | 'rebate rewards' - | 'airdrop rewards' - | 'USDT contract rewards' - | 'mix contract rewards' - | 'system lock' - | 'user lock'; - -export type SpotAccountTypeV2 = - | 'spot' - | 'p2p' - | 'coin_futures' - | 'usdt_futures' - | 'usdc_futures' - | 'crossed_margin' - | 'isolated_margin'; - -export interface GetSpotAccountBillsRequestV2 { - coin?: string; - groupType?: SpotBillGroupTypeV2; - businessType?: SpotBusinessTypeV2; - startTime?: string; - endTime?: string; - limit?: string; - idLessThan?: string; -} - -export interface SpotTransferRequestV2 { - fromType: SpotAccountTypeV2; - toType: SpotAccountTypeV2; - amount: string; - coin: string; - symbol: string; - clientOid?: string; -} - -export interface SpotSubAccountTransferRequestV2 { - fromType: SpotAccountTypeV2; - toType: SpotAccountTypeV2; - amount: string; - coin: string; - symbol?: string; - clientOid?: string; - fromUserId: string; - toUserId: string; -} - -export interface SpotWithdrawalRequestV2 { - coin: string; - transferType: 'on_chain' | 'internal_transfer'; - address: string; - chain?: string; - innerToType?: 'email' | 'mobile' | 'uid'; - areaCode?: string; - tag?: string; - size: string; - remark?: string; - clientOid?: string; -} - -export interface SpotMainSubTransferRecordRequestV2 { - coin?: string; - role?: 'initiator' | 'receiver'; - subUid?: string; - startTime?: string; - endTime?: string; - clientOid?: string; - limit?: string; - idLessThan?: string; -} - -export interface GetSpotTransferRecordRequestV2 { - coin: string; - fromType: SpotAccountTypeV2; - startTime?: string; - endTime?: string; - clientOid?: string; - limit?: string; - idLessThan?: string; -} - -export interface GetSpotSubAccountDepositRecordRequestV2 { - subUid: string; - coin?: string; - startTime?: string; - endTime?: string; - idLessThan?: string; - limit?: string; -} - -export interface GetSpotWithdrawalRecordRequestV2 { - coin?: string; - clientOid?: string; - startTime: string; - endTime: string; - idLessThan?: string; - orderId?: string; - limit?: string; -} - -export interface GetSpotDepositRecordRequestV2 { - coin?: string; - orderId?: string; - startTime: string; - endTime: string; - idLessThan?: string; - limit?: string; -} +type SpotKlineIntervalV2 = + | '1min' + | '5min' + | '15min' + | '30min' + | '1h' + | '4h' + | '6h' + | '12h' + | '1day' + | '3day' + | '1week' + | '1M' + | '6Hutc' + | '12Hutc' + | '1Dutc' + | '3Dutc' + | '1Wutc' + | '1Mutc'; + +export interface SpotCandlesRequestV2 { + symbol: string; + granularity: SpotKlineIntervalV2; + startTime?: string; + endTime?: string; + limit?: string; +} + +export interface SpotHistoricCandlesRequestV2 { + symbol: string; + granularity: SpotKlineIntervalV2; + endTime?: string; + limit?: string; +} + +export interface SpotHistoricTradesRequestV2 { + symbol: string; + limit?: string; + idLessThan?: string; + startTime?: string; + endTime?: string; +} + +/** + * + * * Spot | Trade + * + */ + +export type SpotOrderSideV2 = 'buy' | 'sell'; + +export type SpotOrderTypeV2 = 'limit' | 'market'; + +export type SpotOrderForceV2 = 'gtc' | 'post_only' | 'fok' | 'ioc'; + +export type SpotTPSLTypeV2 = 'normal' | 'tpsl'; + +export type SpotSTPModeV2 = + | 'none' + | 'cancel_taker' + | 'cancel_maker' + | 'cancel_both'; + +export type SpotBatchModeV2 = 'single' | 'multiple'; + +export interface SpotOrderRequestV2 { + symbol: string; + side: SpotOrderSideV2; + orderType: SpotOrderTypeV2; + force: SpotOrderForceV2; + price?: string; + size: string; + clientOid?: string; + triggerPrice?: string; + tpslType?: SpotTPSLTypeV2; + requestTime?: string; + receiveWindow?: string; + stpMode?: SpotSTPModeV2; + presetTakeProfitPrice?: string; + executeTakeProfitPrice?: string; + presetStopLossPrice?: string; + executeStopLossPrice?: string; +} + +export interface SpotCancelandSubmitOrderRequestV2 { + symbol: string; + price: string; + size: string; + orderId?: string; + clientOid?: string; + newClientOid?: string; + presetTakeProfitPrice?: string; + executeTakeProfitPrice?: string; + presetStopLossPrice?: string; + executeStopLossPrice?: string; +} + +export interface SpotCancelOrderRequestV2 { + symbol: string; + tpslType?: SpotTPSLTypeV2; + orderId?: string; + clientOid?: string; +} + +export interface SpotBatchOrderRequestItemV2 { + symbol?: string; + side: SpotOrderSideV2; + orderType: SpotOrderTypeV2; + force: SpotOrderForceV2; + price?: string; + size: string; + clientOid?: string; + stpMode?: SpotSTPModeV2; + presetTakeProfitPrice?: string; + executeTakeProfitPrice?: string; + presetStopLossPrice?: string; + executeStopLossPrice?: string; +} + +export interface SpotBatchOrderRequestV2 { + symbol?: string; + batchMode?: SpotBatchModeV2; + orderList: SpotBatchOrderRequestItemV2[]; +} + +export interface SpotBatchCancelOrderRequestV2 { + symbol?: string; + batchMode?: SpotBatchModeV2; + orderList: { + symbol?: string; + orderId?: string; + clientOid?: string; + }[]; +} + +export interface GetSpotOrderInfoRequestV2 { + orderId?: string; + clientOid?: string; + requestTime?: string; + receiveWindow?: string; +} + +export interface GetSpotOpenOrdersRequestV2 { + symbol?: string; + startTime?: string; + endTime?: string; + idLessThan?: string; + limit?: string; + orderId?: string; + tpslType?: SpotTPSLTypeV2; + requestTime?: string; + receiveWindow?: string; +} + +export interface GetSpotHistoryOrdersRequestV2 { + symbol?: string; + startTime?: string; + endTime?: string; + idLessThan?: string; + limit?: string; + orderId?: string; + tpslType?: SpotTPSLTypeV2; + requestTime?: string; + receiveWindow?: string; +} + +export interface GetSpotFillsRequestV2 { + symbol: string; + orderId?: string; + startTime?: string; + endTime?: string; + limit?: string; + idLessThan?: string; +} + +/** + * + * * Spot | Trigger Orders + * + */ + +export type SpotPlanTypeV2 = 'amount' | 'total'; + +export type SpotTriggerTypeV2 = 'fill_price' | 'mark_price'; + +export interface SpotPlanOrderRequestV2 { + symbol: string; + side: SpotOrderSideV2; + triggerPrice: string; + orderType: SpotOrderTypeV2; + executePrice?: string; + planType?: SpotPlanTypeV2; + size: string; + triggerType: SpotTriggerTypeV2; + clientOid?: string; + force?: SpotOrderForceV2; + stpMode?: SpotSTPModeV2; +} + +export interface SpotModifyPlanOrderRequestV2 { + orderId?: string; + clientOid?: string; + triggerPrice: string; + orderType: SpotOrderTypeV2; + executePrice?: string; + size: string; +} + +export interface GetSpotCurrentPlanOrdersRequestV2 { + symbol: string; + limit?: string; + idLessThan?: string; + startTime?: string; + endTime?: string; +} + +export interface GetSpotHistoryPlanOrdersRequestV2 { + symbol: string; + startTime: string; + endTime: string; + limit?: string; +} + +/** + * + * * Spot | Account + * + */ + +export type SpotBillGroupTypeV2 = + | 'deposit' + | 'withdraw' + | 'transaction' + | 'transfer' + | 'other'; + +export type SpotBusinessTypeV2 = + | 'deposit' + | 'withdraw' + | 'buy' + | 'sell' + | 'deduction of handling fee' + | 'transfer-in' + | 'transfer-out' + | 'rebate rewards' + | 'airdrop rewards' + | 'USDT contract rewards' + | 'mix contract rewards' + | 'system lock' + | 'user lock'; + +export type SpotAccountTypeV2 = + | 'spot' + | 'p2p' + | 'coin_futures' + | 'usdt_futures' + | 'usdc_futures' + | 'crossed_margin' + | 'isolated_margin'; + +export interface GetSpotAccountBillsRequestV2 { + coin?: string; + groupType?: SpotBillGroupTypeV2; + businessType?: SpotBusinessTypeV2; + startTime?: string; + endTime?: string; + limit?: string; + idLessThan?: string; +} + +export interface SpotTransferRequestV2 { + fromType: SpotAccountTypeV2; + toType: SpotAccountTypeV2; + amount: string; + coin: string; + symbol: string; + clientOid?: string; +} + +export interface SpotSubAccountTransferRequestV2 { + fromType: SpotAccountTypeV2; + toType: SpotAccountTypeV2; + amount: string; + coin: string; + symbol?: string; + clientOid?: string; + fromUserId: string; + toUserId: string; +} + +export interface SpotWithdrawalRequestV2 { + coin: string; + transferType: 'on_chain' | 'internal_transfer'; + address: string; + chain?: string; + innerToType?: 'email' | 'mobile' | 'uid'; + areaCode?: string; + tag?: string; + size: string; + remark?: string; + clientOid?: string; +} + +export interface SpotMainSubTransferRecordRequestV2 { + coin?: string; + role?: 'initiator' | 'receiver'; + subUid?: string; + startTime?: string; + endTime?: string; + clientOid?: string; + limit?: string; + idLessThan?: string; +} + +export interface GetSpotTransferRecordRequestV2 { + coin: string; + fromType: SpotAccountTypeV2; + startTime?: string; + endTime?: string; + clientOid?: string; + limit?: string; + idLessThan?: string; +} + +export interface GetSpotSubAccountDepositRecordRequestV2 { + subUid: string; + coin?: string; + startTime?: string; + endTime?: string; + idLessThan?: string; + limit?: string; +} + +export interface GetSpotWithdrawalRecordRequestV2 { + coin?: string; + clientOid?: string; + startTime: string; + endTime: string; + idLessThan?: string; + orderId?: string; + limit?: string; +} + +export interface GetSpotDepositRecordRequestV2 { + coin?: string; + orderId?: string; + startTime: string; + endTime: string; + idLessThan?: string; + limit?: string; +} diff --git a/src/types/response/index.ts b/src/types/response/index.ts index 0c86356..e42f90e 100644 --- a/src/types/response/index.ts +++ b/src/types/response/index.ts @@ -1,3 +1,3 @@ +export * from './futures'; export * from './shared'; export * from './spot'; -export * from './futures'; diff --git a/src/types/shared.ts b/src/types/shared.ts index b125ec3..6c9e9a9 100644 --- a/src/types/shared.ts +++ b/src/types/shared.ts @@ -27,4 +27,4 @@ export type KlineInterval = | '1Mutc'; export type RestClientType = - typeof REST_CLIENT_TYPE_ENUM[keyof typeof REST_CLIENT_TYPE_ENUM]; + (typeof REST_CLIENT_TYPE_ENUM)[keyof typeof REST_CLIENT_TYPE_ENUM]; diff --git a/src/util/BaseRestClient.ts b/src/util/BaseRestClient.ts index 4e74d74..beba6f9 100644 --- a/src/util/BaseRestClient.ts +++ b/src/util/BaseRestClient.ts @@ -1,15 +1,15 @@ import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios'; -import { RestClientType } from '../types'; +import { RestClientType } from '../types'; import { signMessage } from './node-support'; import { + getRestBaseUrl, RestClientOptions, serializeParams, - getRestBaseUrl, } from './requestUtils'; import { neverGuard } from './websocket-util'; -interface SignedRequest { +interface SignedRequest { originalParams: T; paramsWithSign?: T & { sign: string }; serializedParams: string; @@ -19,7 +19,7 @@ interface SignedRequest { recvWindow: number; } -interface UnsignedRequest { +interface UnsignedRequest { originalParams: T; paramsWithSign: T; } @@ -229,7 +229,7 @@ export default abstract class BaseRestClient { /** * @private sign request and set recv window */ - private async signRequest( + private async signRequest( data: T, endpoint: string, method: Method, diff --git a/src/util/BaseWSClient.ts b/src/util/BaseWSClient.ts index 32d79df..e4f55e5 100644 --- a/src/util/BaseWSClient.ts +++ b/src/util/BaseWSClient.ts @@ -5,12 +5,12 @@ import WebSocket from 'isomorphic-ws'; import { WebsocketClientOptions, WSClientConfigurableOptions, -} from '../types/index.js'; -import { DefaultLogger } from './logger.js'; -import { isWsPong } from './requestUtils.js'; -import { getWsAuthSignature } from './websocket-util.js'; -import WsStore from './WsStore.js'; -import { WsConnectionStateEnum } from './WsStore.types.js'; +} from '../types/index'; +import { DefaultLogger } from './logger'; +import { isWsPong } from './requestUtils'; +import { getWsAuthSignature } from './websocket-util'; +import WsStore from './WsStore'; +import { WsConnectionStateEnum } from './WsStore.types'; interface WSClientEventMap { /** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */ diff --git a/src/util/WsStore.ts b/src/util/WsStore.ts index 19f990d..9a609dc 100644 --- a/src/util/WsStore.ts +++ b/src/util/WsStore.ts @@ -1,4 +1,5 @@ import WebSocket from 'isomorphic-ws'; + import { DefaultLogger } from './logger'; import { WsConnectionStateEnum, WsStoredState } from './WsStore.types'; diff --git a/src/util/browser-support.ts b/src/util/browser-support.ts index 3633549..f4a4fd2 100644 --- a/src/util/browser-support.ts +++ b/src/util/browser-support.ts @@ -40,6 +40,7 @@ export async function signMessage( return _arrayBufferToBase64(signature); } default: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars ((x: never) => {})(method); throw new Error(`Unhandled sign method: ${method}`); } diff --git a/src/util/index.ts b/src/util/index.ts index fd92581..6c491bd 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -1,6 +1,6 @@ export * from './BaseRestClient'; -export * from './requestUtils'; -export * from './WsStore'; export * from './logger'; +export * from './requestUtils'; export * from './type-guards'; export * from './websocket-util'; +export * from './WsStore'; diff --git a/src/util/logger.ts b/src/util/logger.ts index a0b2379..d5a585c 100644 --- a/src/util/logger.ts +++ b/src/util/logger.ts @@ -1,6 +1,7 @@ export type LogParams = null | any; export const DefaultLogger = { + // eslint-disable-next-line @typescript-eslint/no-unused-vars silly: (...params: LogParams): void => { // console.log(params); }, diff --git a/src/util/node-support.ts b/src/util/node-support.ts index 4afe4b6..7472e15 100644 --- a/src/util/node-support.ts +++ b/src/util/node-support.ts @@ -16,6 +16,7 @@ export async function signMessage( return hmac.digest().toString('base64'); } default: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars ((x: never) => {})(method); throw new Error(`Unhandled sign method: ${method}`); } diff --git a/src/util/requestUtils.ts b/src/util/requestUtils.ts index 6f831f0..90ea006 100644 --- a/src/util/requestUtils.ts +++ b/src/util/requestUtils.ts @@ -34,7 +34,7 @@ export interface RestClientOptions { parseExceptions?: boolean; } -export function serializeParams( +export function serializeParams( params: T, strict_validation = false, encodeValues: boolean = true, diff --git a/src/util/websocket-util.ts b/src/util/websocket-util.ts index 36ffc27..ac9c956 100644 --- a/src/util/websocket-util.ts +++ b/src/util/websocket-util.ts @@ -95,6 +95,7 @@ export function isPrivateChannel( export function getWsKeyForTopic( subscribeEvent: WsTopicSubscribeEventArgs, + // eslint-disable-next-line @typescript-eslint/no-unused-vars isPrivate?: boolean, ): WsKey { const instType = subscribeEvent.instType.toUpperCase() as BitgetInstType; diff --git a/src/websocket-client-v2.ts b/src/websocket-client-v2.ts index c124d28..6d0c6af 100644 --- a/src/websocket-client-v2.ts +++ b/src/websocket-client-v2.ts @@ -12,17 +12,15 @@ import { WsTopicSubscribePrivateInstIdArgsV2, WsTopicV2, } from './types'; - import { - WS_AUTH_ON_CONNECT_KEYS, - WS_KEY_MAP, DefaultLogger, - WS_BASE_URL_MAP, - neverGuard, getMaxTopicsPerSubscribeEvent, isPrivateChannel, + neverGuard, + WS_AUTH_ON_CONNECT_KEYS, + WS_BASE_URL_MAP, + WS_KEY_MAP, } from './util'; - import { BaseWebsocketClient } from './util/BaseWSClient'; const LOGGER_CATEGORY = { category: 'bitget-ws' }; diff --git a/src/websocket-client.ts b/src/websocket-client.ts index cf7ab28..d12b870 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -1,8 +1,7 @@ +/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ import { EventEmitter } from 'events'; import WebSocket from 'isomorphic-ws'; -import WsStore from './util/WsStore'; - import { BitgetInstType, WebsocketClientOptions, @@ -11,19 +10,19 @@ import { WsTopic, WsTopicSubscribeEventArgs, } from './types'; - import { - isWsPong, - WS_AUTH_ON_CONNECT_KEYS, - WS_KEY_MAP, DefaultLogger, - WS_BASE_URL_MAP, - getWsKeyForTopic, - neverGuard, getMaxTopicsPerSubscribeEvent, - isPrivateChannel, getWsAuthSignature, + getWsKeyForTopic, + isPrivateChannel, + isWsPong, + neverGuard, + WS_AUTH_ON_CONNECT_KEYS, + WS_BASE_URL_MAP, + WS_KEY_MAP, } from './util'; +import WsStore from './util/WsStore'; import { WsConnectionStateEnum } from './util/WsStore.types'; const LOGGER_CATEGORY = { category: 'bitget-ws' }; @@ -387,7 +386,7 @@ export class WebsocketClient extends EventEmitter { this.logger.silly( `Subscribing to topics in batches of ${maxTopicsPerEvent}`, ); - for (var i = 0; i < topics.length; i += maxTopicsPerEvent) { + for (let i = 0; i < topics.length; i += maxTopicsPerEvent) { const batch = topics.slice(i, i + maxTopicsPerEvent); this.logger.silly(`Subscribing to batch of ${batch.length}`); this.requestSubscribeTopics(wsKey, batch); @@ -422,7 +421,7 @@ export class WebsocketClient extends EventEmitter { this.logger.silly( `Unsubscribing to topics in batches of ${maxTopicsPerEvent}`, ); - for (var i = 0; i < topics.length; i += maxTopicsPerEvent) { + for (let i = 0; i < topics.length; i += maxTopicsPerEvent) { const batch = topics.slice(i, i + maxTopicsPerEvent); this.logger.silly(`Unsubscribing to batch of ${batch.length}`); this.requestUnsubscribeTopics(wsKey, batch); diff --git a/test/broker/private.read.test.ts b/test/broker/private.read.test.ts index cb92c57..f881293 100644 --- a/test/broker/private.read.test.ts +++ b/test/broker/private.read.test.ts @@ -20,9 +20,9 @@ describe('Private Broker REST API GET Endpoints', () => { const coin = 'BTC'; const subUid = '123456'; - const timestampOneHourAgo = new Date().getTime() - 1000 * 60 * 60; - const from = timestampOneHourAgo.toFixed(0); - const to = String(Number(from) + 1000 * 60 * 30); // 30 minutes + // const timestampOneHourAgo = new Date().getTime() - 1000 * 60 * 60; + // const from = timestampOneHourAgo.toFixed(0); + // const to = String(Number(from) + 1000 * 60 * 30); // 30 minutes it('getBrokerInfo()', async () => { try { diff --git a/test/broker/private.write.test.ts b/test/broker/private.write.test.ts index 32d8c3a..8fb7448 100644 --- a/test/broker/private.write.test.ts +++ b/test/broker/private.write.test.ts @@ -18,11 +18,11 @@ describe('Private Broker REST API POST Endpoints', () => { apiPass: API_PASS, }); - const coin = 'BTC'; + // const coin = 'BTC'; const subUid = '123456'; - const timestampOneHourAgo = new Date().getTime() - 1000 * 60 * 60; - const from = timestampOneHourAgo.toFixed(0); - const to = String(Number(from) + 1000 * 60 * 30); // 30 minutes + // const timestampOneHourAgo = new Date().getTime() - 1000 * 60 * 60; + // const from = timestampOneHourAgo.toFixed(0); + // const to = String(Number(from) + 1000 * 60 * 30); // 30 minutes it('createSubAccount()', async () => { try { diff --git a/test/futures/private.write.test.ts b/test/futures/private.write.test.ts index 497f631..7ded747 100644 --- a/test/futures/private.write.test.ts +++ b/test/futures/private.write.test.ts @@ -22,9 +22,9 @@ describe('Private Futures REST API POST Endpoints', () => { const symbol = 'BTCUSDT_UMCBL'; const marginCoin = 'USDT'; - const timestampOneHourAgo = new Date().getTime() - 1000 * 60 * 60; - const from = timestampOneHourAgo.toFixed(0); - const to = String(Number(from) + 1000 * 60 * 30); // 30 minutes + // const timestampOneHourAgo = new Date().getTime() - 1000 * 60 * 60; + // const from = timestampOneHourAgo.toFixed(0); + // const to = String(Number(from) + 1000 * 60 * 30); // 30 minutes it('setLeverage()', async () => { try { diff --git a/test/futures/public.test.ts b/test/futures/public.test.ts index ba1ea96..1b497e1 100644 --- a/test/futures/public.test.ts +++ b/test/futures/public.test.ts @@ -1,9 +1,5 @@ -import { API_ERROR_CODE, FuturesClient } from '../../src'; -import { - notAuthenticatedError, - successResponseString, - sucessEmptyResponseObject, -} from '../response.util'; +import { FuturesClient } from '../../src'; +import { sucessEmptyResponseObject } from '../response.util'; describe('Public Spot REST API Endpoints', () => { const api = new FuturesClient(); diff --git a/test/spot/private.read.test.ts b/test/spot/private.read.test.ts index 8815caa..761a4a6 100644 --- a/test/spot/private.read.test.ts +++ b/test/spot/private.read.test.ts @@ -1,4 +1,4 @@ -import { API_ERROR_CODE, SpotClient } from '../../src'; +import { SpotClient } from '../../src'; import { sucessEmptyResponseObject } from '../response.util'; describe('Private Spot REST API GET Endpoints', () => { diff --git a/test/spot/public.test.ts b/test/spot/public.test.ts index b802a1e..29eed0c 100644 --- a/test/spot/public.test.ts +++ b/test/spot/public.test.ts @@ -1,6 +1,5 @@ -import { API_ERROR_CODE, SpotClient } from '../../src'; +import { SpotClient } from '../../src'; import { - notAuthenticatedError, successResponseString, sucessEmptyResponseObject, } from '../response.util'; @@ -9,8 +8,6 @@ describe('Public Spot REST API Endpoints', () => { const api = new SpotClient(); const symbol = 'BTCUSDT_SPBL'; - const timestampOneHourAgo = new Date().getTime() / 1000 - 1000 * 60 * 60; - const from = Number(timestampOneHourAgo.toFixed(0)); // it('should throw for unauthenticated private calls', async () => { // expect(() => api.getOpenOrders()).rejects.toMatchObject( diff --git a/test/ws.private.test.ts b/test/ws.private.test.ts index 6c75ecd..c62fd95 100644 --- a/test/ws.private.test.ts +++ b/test/ws.private.test.ts @@ -1,15 +1,10 @@ import { WebsocketClient, - WSClientConfigurableOptions, WS_ERROR_ENUM, WS_KEY_MAP, + WSClientConfigurableOptions, } from '../src'; -import { - getSilentLogger, - listenToSocketEvents, - logAllEvents, - waitForSocketEvent, -} from './ws.util'; +import { getSilentLogger, logAllEvents, waitForSocketEvent } from './ws.util'; describe.skip('Private Spot Websocket Client', () => { const API_KEY = process.env.API_KEY_COM; @@ -50,7 +45,7 @@ describe.skip('Private Spot Websocket Client', () => { try { await Promise.all([wsResponsePromise]); } catch (e) { - // console.error() + console.error(e); } badClient.closeAll(); }); diff --git a/test/ws.public.test.ts b/test/ws.public.test.ts index 0b6539b..63c4c7f 100644 --- a/test/ws.public.test.ts +++ b/test/ws.public.test.ts @@ -1,9 +1,9 @@ import { WebsocketClient, - WSClientConfigurableOptions, WS_KEY_MAP, + WSClientConfigurableOptions, } from '../src'; -import { logAllEvents, getSilentLogger, waitForSocketEvent } from './ws.util'; +import { getSilentLogger, logAllEvents, waitForSocketEvent } from './ws.util'; describe('Public Spot Websocket Client', () => { let wsClient: WebsocketClient; diff --git a/test/ws.util.ts b/test/ws.util.ts index 2e3e449..223880d 100644 --- a/test/ws.util.ts +++ b/test/ws.util.ts @@ -1,5 +1,7 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { WebsocketClient } from '../src'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars export function getSilentLogger(logHint?: string) { return { silly: () => {},