Skip to content

Commit

Permalink
chore(): refactor ws events into organised dir
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagosiebler committed Dec 18, 2024
1 parent b897826 commit d508655
Show file tree
Hide file tree
Showing 28 changed files with 46 additions and 45 deletions.
3 changes: 1 addition & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion src/types/request/v5-account.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountTypeV5, CategoryV5, TransactionTypeV5 } from '../v5-shared';
import { AccountTypeV5, CategoryV5, TransactionTypeV5 } from '../shared-v5';

export interface GetWalletBalanceParamsV5 {
accountType: AccountTypeV5;
Expand Down
2 changes: 1 addition & 1 deletion src/types/request/v5-asset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountTypeV5, CategoryV5 } from '../v5-shared';
import { AccountTypeV5, CategoryV5 } from '../shared-v5';

export interface GetCoinExchangeRecordParamsV5 {
fromCoin?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/types/request/v5-market.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/types/request/v5-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
OrderTypeV5,
PositionIdx,
TPSLModeV5,
} from '../v5-shared';
} from '../shared-v5';

export interface PositionInfoParamsV5 {
category: CategoryV5;
Expand Down
2 changes: 1 addition & 1 deletion src/types/request/v5-pre-upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExecTypeV5 } from '../v5-shared';
import { ExecTypeV5 } from '../shared-v5';

export interface GetPreUpgradeOrderHistoryParamsV5 {
category: 'linear' | 'inverse';
Expand Down
2 changes: 1 addition & 1 deletion src/types/request/v5-spot-leverage-token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LTOrderTypeV5 } from '../v5-shared';
import { LTOrderTypeV5 } from '../shared-v5';

export interface PurchaseSpotLeveragedTokenParamsV5 {
ltCoin: string;
Expand Down
2 changes: 1 addition & 1 deletion src/types/request/v5-trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
OrderTriggerByV5,
OrderTypeV5,
PositionIdx,
} from '../v5-shared';
} from '../shared-v5';

export interface OrderParamsV5 {
category: CategoryV5;
Expand Down
2 changes: 1 addition & 1 deletion src/types/request/v5-user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PermissionsV5 } from '../v5-shared';
import { PermissionsV5 } from '../shared-v5';

export interface CreateSubMemberParamsV5 {
username: string;
Expand Down
2 changes: 1 addition & 1 deletion src/types/response/v5-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CategoryV5,
TransactionTypeV5,
UnifiedUpdateStatusV5,
} from '../v5-shared';
} from '../shared-v5';

export interface WalletBalanceV5Coin {
coin: string;
Expand Down
2 changes: 1 addition & 1 deletion src/types/response/v5-asset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountTypeV5, OrderSideV5, WithdrawalTypeV5 } from '../v5-shared';
import { AccountTypeV5, OrderSideV5, WithdrawalTypeV5 } from '../shared-v5';

export interface CoinExchangeRecordV5 {
fromCoin: string;
Expand Down
2 changes: 1 addition & 1 deletion src/types/response/v5-market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
MarginTradingV5,
OptionTypeV5,
OrderSideV5,
} from '../v5-shared';
} from '../shared-v5';

/**
* OHLCVT candle used by v5 APIs
Expand Down
2 changes: 1 addition & 1 deletion src/types/response/v5-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
StopOrderTypeV5,
TPSLModeV5,
TradeModeV5,
} from '../v5-shared';
} from '../shared-v5';

export interface PositionV5 {
positionIdx: PositionIdx;
Expand Down
2 changes: 1 addition & 1 deletion src/types/response/v5-spot-leverage-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
LTOrderStatusV5,
LTOrderTypeV5,
LeverageTokenStatusV5,
} from '../v5-shared';
} from '../shared-v5';

export interface LeverageTokenInfoV5 {
ltCoin: string;
Expand Down
2 changes: 1 addition & 1 deletion src/types/response/v5-trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
OrderTypeV5,
PositionIdx,
StopOrderTypeV5,
} from '../v5-shared';
} from '../shared-v5';

export interface OrderResultV5 {
orderId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/types/response/v5-user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PermissionsV5 } from '../v5-shared';
import { PermissionsV5 } from '../shared-v5';

export interface CreateSubMemberResultV5 {
uid: string;
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/types/websockets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ws-general';
export * from './ws-events';
17 changes: 17 additions & 0 deletions src/types/websockets/ws-confirmations.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
StopOrderTypeV5,
TPSLModeV5,
TradeModeV5,
} from './v5-shared';
import { WsKey } from './websockets';
} from '../shared-v5';
import { WsKey } from '.';

export interface WSPublicTopicEventV5<TTopic extends string, TType, TData> {
id?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down
6 changes: 0 additions & 6 deletions src/types/ws-events/failed-topic-subscription-confirmation.ts

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions src/types/ws-events/topic-subscription-confirmation.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/util/WsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface WsStoredState {
subscribedTopics: WsTopicList;
}

export default class WsStore {
export class WsStore {
private wsState: Record<string, WsStoredState>;

private logger: typeof DefaultLogger;
Expand Down
6 changes: 4 additions & 2 deletions src/util/requestUtils.ts
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/util/typeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/websocket-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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' };

Expand Down

0 comments on commit d508655

Please sign in to comment.