From d508655136301def05b317771e7a0fa44425d2a8 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Wed, 18 Dec 2024 14:32:42 +0000 Subject: [PATCH] chore(): refactor ws events into organised dir --- src/types/index.ts | 3 +-- src/types/request/v5-account.ts | 2 +- src/types/request/v5-asset.ts | 2 +- src/types/request/v5-market.ts | 2 +- src/types/request/v5-position.ts | 2 +- src/types/request/v5-pre-upgrade.ts | 2 +- src/types/request/v5-spot-leverage-token.ts | 2 +- src/types/request/v5-trade.ts | 2 +- src/types/request/v5-user.ts | 2 +- src/types/response/v5-account.ts | 2 +- src/types/response/v5-asset.ts | 2 +- src/types/response/v5-market.ts | 2 +- src/types/response/v5-position.ts | 2 +- src/types/response/v5-spot-leverage-token.ts | 2 +- src/types/response/v5-trade.ts | 2 +- src/types/response/v5-user.ts | 2 +- src/types/{v5-shared.ts => shared-v5.ts} | 0 src/types/websockets/index.ts | 2 ++ src/types/websockets/ws-confirmations.ts | 17 +++++++++++++++++ .../ws-events.ts} | 4 ++-- .../{websockets.ts => websockets/ws-general.ts} | 2 +- .../failed-topic-subscription-confirmation.ts | 6 ------ ...succeeded-topic-subscription-confirmation.ts | 6 ------ .../topic-subscription-confirmation.ts | 7 ------- src/util/WsStore.ts | 2 +- src/util/requestUtils.ts | 6 ++++-- src/util/typeGuards.ts | 2 +- src/websocket-client.ts | 4 ++-- 28 files changed, 46 insertions(+), 45 deletions(-) rename src/types/{v5-shared.ts => shared-v5.ts} (100%) create mode 100644 src/types/websockets/index.ts create mode 100644 src/types/websockets/ws-confirmations.ts rename src/types/{websocket.events.ts => websockets/ws-events.ts} (98%) rename src/types/{websockets.ts => websockets/ws-general.ts} (97%) delete mode 100644 src/types/ws-events/failed-topic-subscription-confirmation.ts delete mode 100644 src/types/ws-events/succeeded-topic-subscription-confirmation.ts delete mode 100644 src/types/ws-events/topic-subscription-confirmation.ts diff --git a/src/types/index.ts b/src/types/index.ts index db8ef226..c8094cd8 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,6 +1,5 @@ export * from './response'; export * from './request'; export * from './shared'; -export * from './v5-shared'; +export * from './shared-v5'; export * from './websockets'; -export * from './websocket.events'; diff --git a/src/types/request/v5-account.ts b/src/types/request/v5-account.ts index bb39048f..dccd2892 100644 --- a/src/types/request/v5-account.ts +++ b/src/types/request/v5-account.ts @@ -1,4 +1,4 @@ -import { AccountTypeV5, CategoryV5, TransactionTypeV5 } from '../v5-shared'; +import { AccountTypeV5, CategoryV5, TransactionTypeV5 } from '../shared-v5'; export interface GetWalletBalanceParamsV5 { accountType: AccountTypeV5; diff --git a/src/types/request/v5-asset.ts b/src/types/request/v5-asset.ts index 3de59cdd..c7483d71 100644 --- a/src/types/request/v5-asset.ts +++ b/src/types/request/v5-asset.ts @@ -1,4 +1,4 @@ -import { AccountTypeV5, CategoryV5 } from '../v5-shared'; +import { AccountTypeV5, CategoryV5 } from '../shared-v5'; export interface GetCoinExchangeRecordParamsV5 { fromCoin?: string; diff --git a/src/types/request/v5-market.ts b/src/types/request/v5-market.ts index cd02bc90..f5a3c4be 100644 --- a/src/types/request/v5-market.ts +++ b/src/types/request/v5-market.ts @@ -1,5 +1,5 @@ import { KlineIntervalV3 } from '../shared'; -import { CategoryV5, InstrumentStatusV5, OptionTypeV5 } from '../v5-shared'; +import { CategoryV5, InstrumentStatusV5, OptionTypeV5 } from '../shared-v5'; export interface GetKlineParamsV5 { category: 'spot' | 'linear' | 'inverse'; diff --git a/src/types/request/v5-position.ts b/src/types/request/v5-position.ts index 6f1dac05..6e34eea6 100644 --- a/src/types/request/v5-position.ts +++ b/src/types/request/v5-position.ts @@ -5,7 +5,7 @@ import { OrderTypeV5, PositionIdx, TPSLModeV5, -} from '../v5-shared'; +} from '../shared-v5'; export interface PositionInfoParamsV5 { category: CategoryV5; diff --git a/src/types/request/v5-pre-upgrade.ts b/src/types/request/v5-pre-upgrade.ts index 3cf65ac1..9cc34e26 100644 --- a/src/types/request/v5-pre-upgrade.ts +++ b/src/types/request/v5-pre-upgrade.ts @@ -1,4 +1,4 @@ -import { ExecTypeV5 } from '../v5-shared'; +import { ExecTypeV5 } from '../shared-v5'; export interface GetPreUpgradeOrderHistoryParamsV5 { category: 'linear' | 'inverse'; diff --git a/src/types/request/v5-spot-leverage-token.ts b/src/types/request/v5-spot-leverage-token.ts index 6691dc07..a3a23d95 100644 --- a/src/types/request/v5-spot-leverage-token.ts +++ b/src/types/request/v5-spot-leverage-token.ts @@ -1,4 +1,4 @@ -import { LTOrderTypeV5 } from '../v5-shared'; +import { LTOrderTypeV5 } from '../shared-v5'; export interface PurchaseSpotLeveragedTokenParamsV5 { ltCoin: string; diff --git a/src/types/request/v5-trade.ts b/src/types/request/v5-trade.ts index 123a1a71..437c70c1 100644 --- a/src/types/request/v5-trade.ts +++ b/src/types/request/v5-trade.ts @@ -8,7 +8,7 @@ import { OrderTriggerByV5, OrderTypeV5, PositionIdx, -} from '../v5-shared'; +} from '../shared-v5'; export interface OrderParamsV5 { category: CategoryV5; diff --git a/src/types/request/v5-user.ts b/src/types/request/v5-user.ts index 33dd7ec3..752ed864 100644 --- a/src/types/request/v5-user.ts +++ b/src/types/request/v5-user.ts @@ -1,4 +1,4 @@ -import { PermissionsV5 } from '../v5-shared'; +import { PermissionsV5 } from '../shared-v5'; export interface CreateSubMemberParamsV5 { username: string; diff --git a/src/types/response/v5-account.ts b/src/types/response/v5-account.ts index 002fe2b0..b23884df 100644 --- a/src/types/response/v5-account.ts +++ b/src/types/response/v5-account.ts @@ -4,7 +4,7 @@ import { CategoryV5, TransactionTypeV5, UnifiedUpdateStatusV5, -} from '../v5-shared'; +} from '../shared-v5'; export interface WalletBalanceV5Coin { coin: string; diff --git a/src/types/response/v5-asset.ts b/src/types/response/v5-asset.ts index 9e580652..fe43abfb 100644 --- a/src/types/response/v5-asset.ts +++ b/src/types/response/v5-asset.ts @@ -1,4 +1,4 @@ -import { AccountTypeV5, OrderSideV5, WithdrawalTypeV5 } from '../v5-shared'; +import { AccountTypeV5, OrderSideV5, WithdrawalTypeV5 } from '../shared-v5'; export interface CoinExchangeRecordV5 { fromCoin: string; diff --git a/src/types/response/v5-market.ts b/src/types/response/v5-market.ts index a5529fbf..f622dca3 100644 --- a/src/types/response/v5-market.ts +++ b/src/types/response/v5-market.ts @@ -7,7 +7,7 @@ import { MarginTradingV5, OptionTypeV5, OrderSideV5, -} from '../v5-shared'; +} from '../shared-v5'; /** * OHLCVT candle used by v5 APIs diff --git a/src/types/response/v5-position.ts b/src/types/response/v5-position.ts index 7293bcc2..3500c508 100644 --- a/src/types/response/v5-position.ts +++ b/src/types/response/v5-position.ts @@ -9,7 +9,7 @@ import { StopOrderTypeV5, TPSLModeV5, TradeModeV5, -} from '../v5-shared'; +} from '../shared-v5'; export interface PositionV5 { positionIdx: PositionIdx; diff --git a/src/types/response/v5-spot-leverage-token.ts b/src/types/response/v5-spot-leverage-token.ts index 2c1dd941..23cbc609 100644 --- a/src/types/response/v5-spot-leverage-token.ts +++ b/src/types/response/v5-spot-leverage-token.ts @@ -2,7 +2,7 @@ import { LTOrderStatusV5, LTOrderTypeV5, LeverageTokenStatusV5, -} from '../v5-shared'; +} from '../shared-v5'; export interface LeverageTokenInfoV5 { ltCoin: string; diff --git a/src/types/response/v5-trade.ts b/src/types/response/v5-trade.ts index f33a3094..8e61cfdf 100644 --- a/src/types/response/v5-trade.ts +++ b/src/types/response/v5-trade.ts @@ -10,7 +10,7 @@ import { OrderTypeV5, PositionIdx, StopOrderTypeV5, -} from '../v5-shared'; +} from '../shared-v5'; export interface OrderResultV5 { orderId: string; diff --git a/src/types/response/v5-user.ts b/src/types/response/v5-user.ts index ea8061ee..8b4e48cb 100644 --- a/src/types/response/v5-user.ts +++ b/src/types/response/v5-user.ts @@ -1,4 +1,4 @@ -import { PermissionsV5 } from '../v5-shared'; +import { PermissionsV5 } from '../shared-v5'; export interface CreateSubMemberResultV5 { uid: string; diff --git a/src/types/v5-shared.ts b/src/types/shared-v5.ts similarity index 100% rename from src/types/v5-shared.ts rename to src/types/shared-v5.ts diff --git a/src/types/websockets/index.ts b/src/types/websockets/index.ts new file mode 100644 index 00000000..b3f48dd1 --- /dev/null +++ b/src/types/websockets/index.ts @@ -0,0 +1,2 @@ +export * from './ws-general'; +export * from './ws-events'; diff --git a/src/types/websockets/ws-confirmations.ts b/src/types/websockets/ws-confirmations.ts new file mode 100644 index 00000000..cf23649f --- /dev/null +++ b/src/types/websockets/ws-confirmations.ts @@ -0,0 +1,17 @@ +export interface WebsocketTopicSubscriptionConfirmationEvent { + op: 'subscribe'; + req_id: string; + conn_id: string; + ret_msg: string; + success: boolean; +} + +export interface WebsocketSucceededTopicSubscriptionConfirmationEvent + extends WebsocketTopicSubscriptionConfirmationEvent { + success: true; +} + +export interface WebsocketFailedTopicSubscriptionConfirmationEvent + extends WebsocketTopicSubscriptionConfirmationEvent { + success: false; +} diff --git a/src/types/websocket.events.ts b/src/types/websockets/ws-events.ts similarity index 98% rename from src/types/websocket.events.ts rename to src/types/websockets/ws-events.ts index 8c57f7a3..493559a2 100644 --- a/src/types/websocket.events.ts +++ b/src/types/websockets/ws-events.ts @@ -17,8 +17,8 @@ import { StopOrderTypeV5, TPSLModeV5, TradeModeV5, -} from './v5-shared'; -import { WsKey } from './websockets'; +} from '../shared-v5'; +import { WsKey } from '.'; export interface WSPublicTopicEventV5 { id?: string; diff --git a/src/types/websockets.ts b/src/types/websockets/ws-general.ts similarity index 97% rename from src/types/websockets.ts rename to src/types/websockets/ws-general.ts index 76042b21..cfe77fcd 100644 --- a/src/types/websockets.ts +++ b/src/types/websockets/ws-general.ts @@ -1,4 +1,4 @@ -import { RestClientOptions, WS_KEY_MAP } from '../util'; +import { RestClientOptions, WS_KEY_MAP } from '../../util'; /** For spot markets, spotV3 is recommended */ export type APIMarket = diff --git a/src/types/ws-events/failed-topic-subscription-confirmation.ts b/src/types/ws-events/failed-topic-subscription-confirmation.ts deleted file mode 100644 index c8b95d60..00000000 --- a/src/types/ws-events/failed-topic-subscription-confirmation.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { WebsocketTopicSubscriptionConfirmationEvent } from './topic-subscription-confirmation'; - -export interface WebsocketFailedTopicSubscriptionConfirmationEvent - extends WebsocketTopicSubscriptionConfirmationEvent { - success: false; -} diff --git a/src/types/ws-events/succeeded-topic-subscription-confirmation.ts b/src/types/ws-events/succeeded-topic-subscription-confirmation.ts deleted file mode 100644 index 0fc59905..00000000 --- a/src/types/ws-events/succeeded-topic-subscription-confirmation.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { WebsocketTopicSubscriptionConfirmationEvent } from './topic-subscription-confirmation'; - -export interface WebsocketSucceededTopicSubscriptionConfirmationEvent - extends WebsocketTopicSubscriptionConfirmationEvent { - success: true; -} diff --git a/src/types/ws-events/topic-subscription-confirmation.ts b/src/types/ws-events/topic-subscription-confirmation.ts deleted file mode 100644 index 542e63d8..00000000 --- a/src/types/ws-events/topic-subscription-confirmation.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface WebsocketTopicSubscriptionConfirmationEvent { - op: 'subscribe'; - req_id: string; - conn_id: string; - ret_msg: string; - success: boolean; -} diff --git a/src/util/WsStore.ts b/src/util/WsStore.ts index 9ca4698b..8a257d35 100644 --- a/src/util/WsStore.ts +++ b/src/util/WsStore.ts @@ -38,7 +38,7 @@ interface WsStoredState { subscribedTopics: WsTopicList; } -export default class WsStore { +export class WsStore { private wsState: Record; private logger: typeof DefaultLogger; diff --git a/src/util/requestUtils.ts b/src/util/requestUtils.ts index 2dd199cd..1a07691e 100644 --- a/src/util/requestUtils.ts +++ b/src/util/requestUtils.ts @@ -1,7 +1,9 @@ import { AxiosResponse } from 'axios'; import { APIRateLimit } from '../types'; -import { WebsocketSucceededTopicSubscriptionConfirmationEvent } from '../types/ws-events/succeeded-topic-subscription-confirmation'; -import { WebsocketTopicSubscriptionConfirmationEvent } from '../types/ws-events/topic-subscription-confirmation'; +import { + WebsocketSucceededTopicSubscriptionConfirmationEvent, + WebsocketTopicSubscriptionConfirmationEvent, +} from '../types/websockets/ws-confirmations'; export interface RestClientOptions { /** Your API key */ diff --git a/src/util/typeGuards.ts b/src/util/typeGuards.ts index dbe78ab0..b391930a 100644 --- a/src/util/typeGuards.ts +++ b/src/util/typeGuards.ts @@ -7,7 +7,7 @@ import { WSExecutionEventV5, WSOrderbookEventV5, WSPositionEventV5, -} from '../types/websocket.events'; +} from '../types/websockets/ws-events'; /** * Type guard to detect a V5 orderbook event (delta & snapshots) diff --git a/src/websocket-client.ts b/src/websocket-client.ts index 1a76fc57..f922a66a 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -20,7 +20,6 @@ import { WsKey, WsTopic, } 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'; @@ -42,7 +41,8 @@ import { serializeParams, } from './util'; import { signMessage } from './util/node-support'; -import WsStore from './util/WsStore'; +import { WsStore } from './util/WsStore'; +import { WebsocketTopicSubscriptionConfirmationEvent } from './types/websockets/ws-confirmations'; const loggerCategory = { category: 'bybit-ws' };