chore(): refactor ws events into organised dir

This commit is contained in:
tiagosiebler
2024-12-18 14:32:42 +00:00
parent b897826634
commit d508655136
28 changed files with 46 additions and 45 deletions

View File

@@ -1,6 +1,5 @@
export * from './response'; export * from './response';
export * from './request'; export * from './request';
export * from './shared'; export * from './shared';
export * from './v5-shared'; export * from './shared-v5';
export * from './websockets'; export * from './websockets';
export * from './websocket.events';

View File

@@ -1,4 +1,4 @@
import { AccountTypeV5, CategoryV5, TransactionTypeV5 } from '../v5-shared'; import { AccountTypeV5, CategoryV5, TransactionTypeV5 } from '../shared-v5';
export interface GetWalletBalanceParamsV5 { export interface GetWalletBalanceParamsV5 {
accountType: AccountTypeV5; accountType: AccountTypeV5;

View File

@@ -1,4 +1,4 @@
import { AccountTypeV5, CategoryV5 } from '../v5-shared'; import { AccountTypeV5, CategoryV5 } from '../shared-v5';
export interface GetCoinExchangeRecordParamsV5 { export interface GetCoinExchangeRecordParamsV5 {
fromCoin?: string; fromCoin?: string;

View File

@@ -1,5 +1,5 @@
import { KlineIntervalV3 } from '../shared'; import { KlineIntervalV3 } from '../shared';
import { CategoryV5, InstrumentStatusV5, OptionTypeV5 } from '../v5-shared'; import { CategoryV5, InstrumentStatusV5, OptionTypeV5 } from '../shared-v5';
export interface GetKlineParamsV5 { export interface GetKlineParamsV5 {
category: 'spot' | 'linear' | 'inverse'; category: 'spot' | 'linear' | 'inverse';

View File

@@ -5,7 +5,7 @@ import {
OrderTypeV5, OrderTypeV5,
PositionIdx, PositionIdx,
TPSLModeV5, TPSLModeV5,
} from '../v5-shared'; } from '../shared-v5';
export interface PositionInfoParamsV5 { export interface PositionInfoParamsV5 {
category: CategoryV5; category: CategoryV5;

View File

@@ -1,4 +1,4 @@
import { ExecTypeV5 } from '../v5-shared'; import { ExecTypeV5 } from '../shared-v5';
export interface GetPreUpgradeOrderHistoryParamsV5 { export interface GetPreUpgradeOrderHistoryParamsV5 {
category: 'linear' | 'inverse'; category: 'linear' | 'inverse';

View File

@@ -1,4 +1,4 @@
import { LTOrderTypeV5 } from '../v5-shared'; import { LTOrderTypeV5 } from '../shared-v5';
export interface PurchaseSpotLeveragedTokenParamsV5 { export interface PurchaseSpotLeveragedTokenParamsV5 {
ltCoin: string; ltCoin: string;

View File

@@ -8,7 +8,7 @@ import {
OrderTriggerByV5, OrderTriggerByV5,
OrderTypeV5, OrderTypeV5,
PositionIdx, PositionIdx,
} from '../v5-shared'; } from '../shared-v5';
export interface OrderParamsV5 { export interface OrderParamsV5 {
category: CategoryV5; category: CategoryV5;

View File

@@ -1,4 +1,4 @@
import { PermissionsV5 } from '../v5-shared'; import { PermissionsV5 } from '../shared-v5';
export interface CreateSubMemberParamsV5 { export interface CreateSubMemberParamsV5 {
username: string; username: string;

View File

@@ -4,7 +4,7 @@ import {
CategoryV5, CategoryV5,
TransactionTypeV5, TransactionTypeV5,
UnifiedUpdateStatusV5, UnifiedUpdateStatusV5,
} from '../v5-shared'; } from '../shared-v5';
export interface WalletBalanceV5Coin { export interface WalletBalanceV5Coin {
coin: string; coin: string;

View File

@@ -1,4 +1,4 @@
import { AccountTypeV5, OrderSideV5, WithdrawalTypeV5 } from '../v5-shared'; import { AccountTypeV5, OrderSideV5, WithdrawalTypeV5 } from '../shared-v5';
export interface CoinExchangeRecordV5 { export interface CoinExchangeRecordV5 {
fromCoin: string; fromCoin: string;

View File

@@ -7,7 +7,7 @@ import {
MarginTradingV5, MarginTradingV5,
OptionTypeV5, OptionTypeV5,
OrderSideV5, OrderSideV5,
} from '../v5-shared'; } from '../shared-v5';
/** /**
* OHLCVT candle used by v5 APIs * OHLCVT candle used by v5 APIs

View File

@@ -9,7 +9,7 @@ import {
StopOrderTypeV5, StopOrderTypeV5,
TPSLModeV5, TPSLModeV5,
TradeModeV5, TradeModeV5,
} from '../v5-shared'; } from '../shared-v5';
export interface PositionV5 { export interface PositionV5 {
positionIdx: PositionIdx; positionIdx: PositionIdx;

View File

@@ -2,7 +2,7 @@ import {
LTOrderStatusV5, LTOrderStatusV5,
LTOrderTypeV5, LTOrderTypeV5,
LeverageTokenStatusV5, LeverageTokenStatusV5,
} from '../v5-shared'; } from '../shared-v5';
export interface LeverageTokenInfoV5 { export interface LeverageTokenInfoV5 {
ltCoin: string; ltCoin: string;

View File

@@ -10,7 +10,7 @@ import {
OrderTypeV5, OrderTypeV5,
PositionIdx, PositionIdx,
StopOrderTypeV5, StopOrderTypeV5,
} from '../v5-shared'; } from '../shared-v5';
export interface OrderResultV5 { export interface OrderResultV5 {
orderId: string; orderId: string;

View File

@@ -1,4 +1,4 @@
import { PermissionsV5 } from '../v5-shared'; import { PermissionsV5 } from '../shared-v5';
export interface CreateSubMemberResultV5 { export interface CreateSubMemberResultV5 {
uid: string; uid: string;

View File

@@ -0,0 +1,2 @@
export * from './ws-general';
export * from './ws-events';

View File

@@ -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;
}

View File

@@ -17,8 +17,8 @@ import {
StopOrderTypeV5, StopOrderTypeV5,
TPSLModeV5, TPSLModeV5,
TradeModeV5, TradeModeV5,
} from './v5-shared'; } from '../shared-v5';
import { WsKey } from './websockets'; import { WsKey } from '.';
export interface WSPublicTopicEventV5<TTopic extends string, TType, TData> { export interface WSPublicTopicEventV5<TTopic extends string, TType, TData> {
id?: string; id?: string;

View File

@@ -1,4 +1,4 @@
import { RestClientOptions, WS_KEY_MAP } from '../util'; import { RestClientOptions, WS_KEY_MAP } from '../../util';
/** For spot markets, spotV3 is recommended */ /** For spot markets, spotV3 is recommended */
export type APIMarket = export type APIMarket =

View File

@@ -1,6 +0,0 @@
import { WebsocketTopicSubscriptionConfirmationEvent } from './topic-subscription-confirmation';
export interface WebsocketFailedTopicSubscriptionConfirmationEvent
extends WebsocketTopicSubscriptionConfirmationEvent {
success: false;
}

View File

@@ -1,6 +0,0 @@
import { WebsocketTopicSubscriptionConfirmationEvent } from './topic-subscription-confirmation';
export interface WebsocketSucceededTopicSubscriptionConfirmationEvent
extends WebsocketTopicSubscriptionConfirmationEvent {
success: true;
}

View File

@@ -1,7 +0,0 @@
export interface WebsocketTopicSubscriptionConfirmationEvent {
op: 'subscribe';
req_id: string;
conn_id: string;
ret_msg: string;
success: boolean;
}

View File

@@ -38,7 +38,7 @@ interface WsStoredState {
subscribedTopics: WsTopicList; subscribedTopics: WsTopicList;
} }
export default class WsStore { export class WsStore {
private wsState: Record<string, WsStoredState>; private wsState: Record<string, WsStoredState>;
private logger: typeof DefaultLogger; private logger: typeof DefaultLogger;

View File

@@ -1,7 +1,9 @@
import { AxiosResponse } from 'axios'; import { AxiosResponse } from 'axios';
import { APIRateLimit } from '../types'; import { APIRateLimit } from '../types';
import { WebsocketSucceededTopicSubscriptionConfirmationEvent } from '../types/ws-events/succeeded-topic-subscription-confirmation'; import {
import { WebsocketTopicSubscriptionConfirmationEvent } from '../types/ws-events/topic-subscription-confirmation'; WebsocketSucceededTopicSubscriptionConfirmationEvent,
WebsocketTopicSubscriptionConfirmationEvent,
} from '../types/websockets/ws-confirmations';
export interface RestClientOptions { export interface RestClientOptions {
/** Your API key */ /** Your API key */

View File

@@ -7,7 +7,7 @@ import {
WSExecutionEventV5, WSExecutionEventV5,
WSOrderbookEventV5, WSOrderbookEventV5,
WSPositionEventV5, WSPositionEventV5,
} from '../types/websocket.events'; } from '../types/websockets/ws-events';
/** /**
* Type guard to detect a V5 orderbook event (delta & snapshots) * Type guard to detect a V5 orderbook event (delta & snapshots)

View File

@@ -20,7 +20,6 @@ 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 { UnifiedMarginClient } from './unified-margin-client';
import { USDCOptionClient } from './usdc-option-client'; import { USDCOptionClient } from './usdc-option-client';
import { USDCPerpetualClient } from './usdc-perpetual-client'; import { USDCPerpetualClient } from './usdc-perpetual-client';
@@ -42,7 +41,8 @@ import {
serializeParams, serializeParams,
} from './util'; } from './util';
import { signMessage } from './util/node-support'; 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' }; const loggerCategory = { category: 'bybit-ws' };