bybit-api 3.10.0 → 3.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,7 @@ class RestClientV5 extends BaseRestClient_1.default {
31
31
  });
32
32
  }
33
33
  getServerTime() {
34
- return this.get('/v3/public/time');
34
+ return this.get('/v5/market/time');
35
35
  }
36
36
  requestDemoTradingFunds() {
37
37
  return this.postPrivate('/v5/account/demo-apply-money');
@@ -1,19 +1,19 @@
1
- import { CategoryV5, ExecTypeV5, OrderSideV5, OrderTypeV5, PositionIdx, StopOrderTypeV5, TPSLModeV5, TradeModeV5 } from '../v5-shared';
1
+ import { CategoryV5, ExecTypeV5, OrderSideV5, OrderTypeV5, PositionIdx, PositionSideV5, PositionStatusV5, StopOrderTypeV5, TPSLModeV5, TradeModeV5 } from '../v5-shared';
2
2
  export interface PositionV5 {
3
3
  positionIdx: PositionIdx;
4
4
  riskId: number;
5
5
  riskLimitValue: string;
6
6
  symbol: string;
7
- side: 'Buy' | 'Sell' | 'None';
7
+ side: PositionSideV5;
8
8
  size: string;
9
9
  avgPrice: string;
10
10
  positionValue: string;
11
11
  tradeMode: TradeModeV5;
12
12
  autoAddMargin?: number;
13
- positionStatus: 'Normal' | 'Liq' | 'Adl';
13
+ positionStatus: PositionStatusV5;
14
14
  leverage?: string;
15
15
  markPrice: string;
16
- liqPrice: string;
16
+ liqPrice: string | '';
17
17
  bustPrice?: string;
18
18
  positionIM?: string;
19
19
  positionMM?: string;
@@ -21,10 +21,21 @@ export interface PositionV5 {
21
21
  takeProfit?: string;
22
22
  stopLoss?: string;
23
23
  trailingStop?: string;
24
+ sessionAvgPrice: string | '';
25
+ delta?: string;
26
+ gamma?: string;
27
+ vega?: string;
28
+ theta?: string;
24
29
  unrealisedPnl: string;
30
+ curRealisedPnl: string;
25
31
  cumRealisedPnl: string;
32
+ adlRankIndicator: number;
33
+ isReduceOnly: boolean;
34
+ mmrSysUpdatedTime: string | '';
35
+ leverageSysUpdatedTime: string | '';
26
36
  createdTime: string;
27
37
  updatedTime: string;
38
+ seq: number;
28
39
  }
29
40
  export interface SetRiskLimitResultV5 {
30
41
  category: CategoryV5;
@@ -45,7 +56,7 @@ export interface AddOrReduceMarginResultV5 {
45
56
  positionValue: string;
46
57
  leverage: string;
47
58
  autoAddMargin: 0 | 1;
48
- positionStatus: 'Normal' | 'Liq' | 'Adl';
59
+ positionStatus: PositionStatusV5;
49
60
  positionIM: string;
50
61
  positionMM: string;
51
62
  takeProfit: string;
@@ -63,7 +63,9 @@ export type OrderCreateTypeV5 =
63
63
  /** Order created by Ice berg strategy - web/app. */
64
64
  | 'CreateByIceBerg'
65
65
  /** Order created by arbitrage - web/app. */
66
- | 'CreateByArbitrage';
66
+ | 'CreateByArbitrage'
67
+ /** Option dynamic delta hedge order - web/app */
68
+ | 'CreateByDdh';
67
69
  export type OrderCancelTypeV5 = 'CancelByUser' | 'CancelByReduceOnly' | 'CancelByPrepareLiq' | 'CancelAllBeforeLiq' | 'CancelByPrepareAdl' | 'CancelAllBeforeAdl' | 'CancelByAdmin' | 'CancelByTpSlTsClear' | 'CancelByPzSideCh' | 'UNKNOWN';
68
70
  export type OrderRejectReasonV5 = 'EC_NoError' | 'EC_Others' | 'EC_UnknownMessageType' | 'EC_MissingClOrdID' | 'EC_MissingOrigClOrdID' | 'EC_ClOrdIDOrigClOrdIDAreTheSame' | 'EC_DuplicatedClOrdID' | 'EC_OrigClOrdIDDoesNotExist' | 'EC_TooLateToCancel' | 'EC_UnknownOrderType' | 'EC_UnknownSide' | 'EC_UnknownTimeInForce' | 'EC_WronglyRouted' | 'EC_MarketOrderPriceIsNotZero' | 'EC_LimitOrderInvalidPrice' | 'EC_NoEnoughQtyToFill' | 'EC_NoImmediateQtyToFill' | 'EC_PerCancelRequest' | 'EC_MarketOrderCannotBePostOnly' | 'EC_PostOnlyWillTakeLiquidity' | 'EC_CancelReplaceOrder' | 'EC_InvalidSymbolStatus';
69
71
  export type StopOrderTypeV5 = 'TakeProfit' | 'StopLoss' | 'TrailingStop' | 'Stop' | 'PartialTakeProfit' | 'PartialStopLoss' | 'tpslOrder';
@@ -75,6 +77,15 @@ export type StopOrderTypeV5 = 'TakeProfit' | 'StopLoss' | 'TrailingStop' | 'Stop
75
77
  * - 2 Sell side of hedge-mode position
76
78
  */
77
79
  export type PositionIdx = 0 | 1 | 2;
80
+ /**
81
+ * Position status.
82
+ *
83
+ * - 'Normal'
84
+ * - 'Liq' in the liquidation progress
85
+ * - 'Adl' in the auto-deleverage progress
86
+ */
87
+ export type PositionStatusV5 = 'Normal' | 'Liq' | 'Adl';
88
+ export type PositionSideV5 = 'Buy' | 'Sell' | 'None' | '';
78
89
  export type OptionTypeV5 = 'Call' | 'Put';
79
90
  /**
80
91
  * Trade mode.
@@ -107,7 +118,7 @@ export type LTOrderTypeV5 = '1' | '2';
107
118
  * Leveraged token order status: '1': completed, '2': in progress, '3': failed
108
119
  */
109
120
  export type LTOrderStatusV5 = '1' | '2' | '3';
110
- export type ExecTypeV5 = 'Trade' | 'AdlTrade' | 'Funding' | 'BustTrade' | 'Settle';
121
+ export type ExecTypeV5 = 'Trade' | 'AdlTrade' | 'Funding' | 'BustTrade' | 'Settle' | 'BlockTrade' | 'MovePosition' | 'UNKNOWN';
111
122
  /**
112
123
  * Withdraw type. 0(default): on chain. 1: off chain. 2: all.
113
124
  */
@@ -1,24 +1,14 @@
1
- import { CategoryV5, OCOTriggerTypeV5, OrderRejectReasonV5, OrderSMPTypeV5, OrderSideV5, OrderStatusV5, OrderTimeInForceV5, OrderTriggerByV5, OrderTypeV5, StopOrderTypeV5, TPSLModeV5 } from './v5-shared';
1
+ import { CategoryV5, ExecTypeV5, OCOTriggerTypeV5, OrderCancelTypeV5, OrderCreateTypeV5, OrderRejectReasonV5, OrderSMPTypeV5, OrderSideV5, OrderStatusV5, OrderTimeInForceV5, OrderTriggerByV5, OrderTypeV5, PositionIdx, PositionSideV5, PositionStatusV5, StopOrderTypeV5, TPSLModeV5, TradeModeV5 } from './v5-shared';
2
2
  import { WsKey } from './websockets';
3
- export interface WSOrderbookEventV5 {
4
- topic: string;
3
+ export interface WSPublicTopicEventV5<TTopic extends string, TType, TData> {
4
+ id?: string;
5
+ topic: TTopic;
6
+ type: TType;
7
+ /** Cross sequence */
8
+ cs?: number;
5
9
  /** Event timestamp */
6
10
  ts: number;
7
- type: 'delta' | 'snapshot';
8
- data: {
9
- /** Symbol */
10
- s: string;
11
- /** [price, qty][] */
12
- b: [string, string][];
13
- /** [price, qty][] */
14
- a: [string, string][];
15
- /** Update ID */
16
- u: number;
17
- /**
18
- * Cross sequence
19
- */
20
- seq: number;
21
- };
11
+ data: TData;
22
12
  /**
23
13
  * matching engine timestamp (correlated with T from public trade channel)
24
14
  */
@@ -28,56 +18,146 @@ export interface WSOrderbookEventV5 {
28
18
  */
29
19
  wsKey: WsKey;
30
20
  }
31
- export interface WSAccountOrderV5 {
32
- qty: string;
33
- price: string;
21
+ export interface WSPrivateTopicEventV5<TTopic extends string, TData> {
22
+ id?: string;
23
+ topic: TTopic;
24
+ creationTime: number;
25
+ data: TData;
26
+ wsKey: WsKey;
27
+ }
28
+ export interface WSOrderbookV5 {
29
+ /** Symbol */
30
+ s: string;
31
+ /** [price, qty][] */
32
+ b: [string, string][];
33
+ /** [price, qty][] */
34
+ a: [string, string][];
35
+ /** Update ID */
36
+ u: number;
37
+ /** Cross sequence */
38
+ seq: number;
39
+ }
40
+ export type WSOrderbookEventV5 = WSPublicTopicEventV5<string, 'delta' | 'snapshot', WSOrderbookV5[]>;
41
+ export interface WSPositionV5 {
42
+ category: string;
34
43
  symbol: string;
35
- orderId: string;
36
- orderIv: string;
44
+ side: PositionSideV5;
45
+ size: string;
46
+ positionIdx: PositionIdx;
47
+ tradeMode: TradeModeV5;
48
+ positionValue: string;
49
+ riskId: number;
50
+ riskLimitValue: string;
51
+ entryPrice: string;
52
+ markPrice: string;
53
+ leverage: string;
54
+ positionBalance: string;
55
+ autoAddMargin: number;
56
+ positionMM: string;
57
+ positionIM: string;
58
+ liqPrice: string;
59
+ bustPrice: string;
60
+ tpslMode: string;
61
+ takeProfit: string;
37
62
  stopLoss: string;
38
- smpGroup: number;
63
+ trailingStop: string;
64
+ unrealisedPnl: string;
65
+ curRealisedPnl: string;
66
+ sessionAvgPrice: string;
67
+ delta: string;
68
+ gamma: string;
69
+ vega: string;
70
+ theta: string;
71
+ cumRealisedPnl: string;
72
+ positionStatus: PositionStatusV5;
73
+ adlRankIndicator: number;
74
+ isReduceOnly: boolean;
75
+ mmrSysUpdatedTime: string;
76
+ leverageSysUpdatedTime: string;
77
+ createdTime: string;
78
+ updatedTime: string;
79
+ seq: number;
80
+ }
81
+ export type WSPositionEventV5 = WSPrivateTopicEventV5<'position', WSPositionV5[]>;
82
+ export interface WSAccountOrderV5 {
83
+ category: CategoryV5;
84
+ orderId: string;
85
+ orderLinkId: string;
86
+ isLeverage: string;
87
+ blockTradeId: string;
88
+ symbol: string;
89
+ price: string;
90
+ qty: string;
39
91
  side: OrderSideV5;
40
- placeType: string;
92
+ positionIdx: PositionIdx;
93
+ orderStatus: OrderStatusV5;
94
+ createType: OrderCreateTypeV5;
95
+ cancelType: OrderCancelTypeV5;
96
+ rejectReason?: OrderRejectReasonV5;
41
97
  avgPrice?: string;
42
98
  leavesQty?: string;
43
- isLeverage: string;
44
- cancelType: string;
99
+ leavesValue?: string;
45
100
  cumExecQty: string;
101
+ cumExecValue: string;
46
102
  cumExecFee: string;
47
- smpOrderId: string;
103
+ feeCurrency: string;
104
+ timeInForce: OrderTimeInForceV5;
105
+ orderType: OrderTypeV5;
106
+ stopOrderType: StopOrderTypeV5;
107
+ ocoTriggerType?: OCOTriggerTypeV5;
108
+ orderIv: string;
109
+ marketUnit?: 'baseCoin' | 'quoteCoin';
110
+ triggerPrice: string;
48
111
  takeProfit: string;
49
- reduceOnly: boolean;
50
- orderLinkId: string;
51
- positionIdx: number;
112
+ stopLoss: string;
113
+ tpslMode?: TPSLModeV5;
114
+ tpLimitPrice?: string;
115
+ slLimitPrice?: string;
52
116
  tpTriggerBy: string;
53
117
  slTriggerBy: string;
118
+ triggerDirection: number;
119
+ triggerBy: OrderTriggerByV5;
120
+ lastPriceOnCreated: string;
121
+ reduceOnly: boolean;
122
+ closeOnTrigger: boolean;
123
+ placeType: string;
124
+ smpType: OrderSMPTypeV5;
125
+ smpGroup: number;
126
+ smpOrderId: string;
54
127
  createdTime: string;
55
128
  updatedTime: string;
56
- feeCurrency: string;
57
- triggerPrice: string;
129
+ }
130
+ export type WSAccountOrderEventV5 = WSPrivateTopicEventV5<'order', WSAccountOrderV5[]>;
131
+ export interface WSExecutionV5 {
58
132
  category: CategoryV5;
59
- cumExecValue: string;
60
- blockTradeId: string;
61
- leavesValue?: string;
62
- slLimitPrice?: string;
63
- tpLimitPrice?: string;
64
- tpslMode?: TPSLModeV5;
133
+ symbol: string;
134
+ isLeverage: string;
135
+ orderId: string;
136
+ orderLinkId: string;
137
+ side: OrderSideV5;
138
+ orderPrice: string;
139
+ orderQty: string;
140
+ leavesQty: string;
141
+ createType: OrderCreateTypeV5;
65
142
  orderType: OrderTypeV5;
66
- smpType: OrderSMPTypeV5;
67
- closeOnTrigger: boolean;
68
- triggerDirection: number;
69
- orderStatus: OrderStatusV5;
70
- lastPriceOnCreated: string;
71
- triggerBy: OrderTriggerByV5;
72
143
  stopOrderType: StopOrderTypeV5;
73
- timeInForce: OrderTimeInForceV5;
74
- ocoTriggerType?: OCOTriggerTypeV5;
75
- rejectReason?: OrderRejectReasonV5;
76
- }
77
- export interface WSAccountOrderEventV5 {
78
- id: string;
79
- wsKey: WsKey;
80
- topic: 'order';
81
- creationTime: number;
82
- data: WSAccountOrderV5[];
144
+ execFee: string;
145
+ execId: string;
146
+ execPrice: string;
147
+ execQty: string;
148
+ execType: ExecTypeV5;
149
+ execValue: string;
150
+ execTime: string;
151
+ isMaker: boolean;
152
+ feeRate: string;
153
+ tradeIv: string;
154
+ markIv: string;
155
+ markPrice: string;
156
+ indexPrice: string;
157
+ underlyingPrice: string;
158
+ blockTradeId: string;
159
+ closedSize: string;
160
+ seq: number;
161
+ marketUnit: string;
83
162
  }
163
+ export type WSExecutionEventV5 = WSPrivateTopicEventV5<'execution', WSExecutionV5[]>;
@@ -25,7 +25,7 @@ export interface RestClientOptions {
25
25
  /** How often to sync time drift with bybit servers */
26
26
  sync_interval_ms?: number | string;
27
27
  /** Determines whether to perform time synchronization before sending private requests */
28
- syncTimeBeforePrivateRequests?: false;
28
+ syncTimeBeforePrivateRequests?: boolean;
29
29
  /** Default: false. If true, we'll throw errors if any params are undefined */
30
30
  strict_param_validation?: boolean;
31
31
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Use type guards to narrow down types with minimal efforts.
3
3
  */
4
- import { WSOrderbookEventV5 } from '../types/websocket.events';
4
+ import { WSAccountOrderEventV5, WSExecutionEventV5, WSOrderbookEventV5, WSPositionEventV5 } from '../types/websocket.events';
5
5
  /**
6
6
  * Type guard to detect a V5 orderbook event (delta & snapshots)
7
7
  *
@@ -9,3 +9,24 @@ import { WSOrderbookEventV5 } from '../types/websocket.events';
9
9
  * @returns
10
10
  */
11
11
  export declare function isWsOrderbookEventV5(event: unknown): event is WSOrderbookEventV5;
12
+ /**
13
+ * Type guard to detect a V5 position event.
14
+ *
15
+ * @param event
16
+ * @returns
17
+ */
18
+ export declare function isWsPositionEventV5(event: unknown): event is WSPositionEventV5;
19
+ /**
20
+ * Type guard to detect a V5 order event.
21
+ *
22
+ * @param event
23
+ * @returns
24
+ */
25
+ export declare function isWsAccountOrderEventV5(event: unknown): event is WSAccountOrderEventV5;
26
+ /**
27
+ * Type guard to detect a V5 execution event.
28
+ *
29
+ * @param event
30
+ * @returns
31
+ */
32
+ export declare function isWsExecutionEventV5(event: unknown): event is WSExecutionEventV5;
@@ -3,7 +3,7 @@
3
3
  * Use type guards to narrow down types with minimal efforts.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isWsOrderbookEventV5 = void 0;
6
+ exports.isWsExecutionEventV5 = exports.isWsAccountOrderEventV5 = exports.isWsPositionEventV5 = exports.isWsOrderbookEventV5 = void 0;
7
7
  /**
8
8
  * Type guard to detect a V5 orderbook event (delta & snapshots)
9
9
  *
@@ -21,4 +21,49 @@ function isWsOrderbookEventV5(event) {
21
21
  event['topic'].startsWith('orderbook'));
22
22
  }
23
23
  exports.isWsOrderbookEventV5 = isWsOrderbookEventV5;
24
+ /**
25
+ * Type guard to detect a V5 position event.
26
+ *
27
+ * @param event
28
+ * @returns
29
+ */
30
+ function isWsPositionEventV5(event) {
31
+ if (typeof event !== 'object' ||
32
+ !event ||
33
+ typeof event['topic'] !== 'string') {
34
+ return false;
35
+ }
36
+ return event['topic'] === 'position';
37
+ }
38
+ exports.isWsPositionEventV5 = isWsPositionEventV5;
39
+ /**
40
+ * Type guard to detect a V5 order event.
41
+ *
42
+ * @param event
43
+ * @returns
44
+ */
45
+ function isWsAccountOrderEventV5(event) {
46
+ if (typeof event !== 'object' ||
47
+ !event ||
48
+ typeof event['topic'] !== 'string') {
49
+ return false;
50
+ }
51
+ return event['topic'] === 'order';
52
+ }
53
+ exports.isWsAccountOrderEventV5 = isWsAccountOrderEventV5;
54
+ /**
55
+ * Type guard to detect a V5 execution event.
56
+ *
57
+ * @param event
58
+ * @returns
59
+ */
60
+ function isWsExecutionEventV5(event) {
61
+ if (typeof event !== 'object' ||
62
+ !event ||
63
+ typeof event['topic'] !== 'string') {
64
+ return false;
65
+ }
66
+ return event['topic'] === 'execution';
67
+ }
68
+ exports.isWsExecutionEventV5 = isWsExecutionEventV5;
24
69
  //# sourceMappingURL=typeGuards.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeGuards.js","sourceRoot":"","sources":["../../src/util/typeGuards.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIH;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,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KAAK,QAAQ;QACzB,CAAC,KAAK;QACN,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ,EAClC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC;AACpC,CAAC;AAZD,0DAYC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,KAAK;QACN,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ,EAClC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,WAAW,CAAC;AACxC,CAAC;AAZD,oDAYC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bybit-api",
3
- "version": "3.10.0",
3
+ "version": "3.10.2",
4
4
  "description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",