bybit-api 3.7.0 → 3.7.1-beta.0

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.
Files changed (70) hide show
  1. package/lib/util/websocket-util.d.ts +2 -1
  2. package/lib/util/websocket-util.js +2 -2
  3. package/lib/util/websocket-util.js.map +1 -1
  4. package/lib/websocket-client.js +1 -1
  5. package/lib/websocket-client.js.map +1 -1
  6. package/package.json +13 -1
  7. package/src/account-asset-client-v3.ts +310 -0
  8. package/src/account-asset-client.ts +149 -0
  9. package/src/constants/enum.ts +105 -0
  10. package/src/contract-client.ts +360 -0
  11. package/src/copy-trading-client.ts +159 -0
  12. package/src/index.ts +18 -0
  13. package/src/inverse-client.ts +337 -0
  14. package/src/inverse-futures-client.ts +403 -0
  15. package/src/linear-client.ts +387 -0
  16. package/src/rest-client-v5.ts +1638 -0
  17. package/src/spot-client-v3.ts +303 -0
  18. package/src/spot-client.ts +180 -0
  19. package/src/types/index.ts +5 -0
  20. package/src/types/request/account-asset.ts +258 -0
  21. package/src/types/request/contract.ts +139 -0
  22. package/src/types/request/copy-trading.ts +53 -0
  23. package/src/types/request/index.ts +18 -0
  24. package/src/types/request/inverse.ts +135 -0
  25. package/src/types/request/linear.ts +201 -0
  26. package/src/types/request/spot.ts +89 -0
  27. package/src/types/request/unified-margin.ts +247 -0
  28. package/src/types/request/usdc-options.ts +134 -0
  29. package/src/types/request/usdc-perp.ts +100 -0
  30. package/src/types/request/usdc-shared.ts +39 -0
  31. package/src/types/request/v5-account.ts +40 -0
  32. package/src/types/request/v5-asset.ts +133 -0
  33. package/src/types/request/v5-market.ts +127 -0
  34. package/src/types/request/v5-position.ts +107 -0
  35. package/src/types/request/v5-pre-upgrade.ts +37 -0
  36. package/src/types/request/v5-spot-leverage-token.ts +23 -0
  37. package/src/types/request/v5-trade.ts +133 -0
  38. package/src/types/request/v5-user.ts +21 -0
  39. package/src/types/response/account-asset.ts +236 -0
  40. package/src/types/response/contract.ts +74 -0
  41. package/src/types/response/index.ts +13 -0
  42. package/src/types/response/shared.ts +19 -0
  43. package/src/types/response/spot.ts +17 -0
  44. package/src/types/response/unified-margin.ts +71 -0
  45. package/src/types/response/usdt-perp.ts +58 -0
  46. package/src/types/response/v5-account.ts +122 -0
  47. package/src/types/response/v5-asset.ts +170 -0
  48. package/src/types/response/v5-market.ts +271 -0
  49. package/src/types/response/v5-position.ts +118 -0
  50. package/src/types/response/v5-spot-leverage-token.ts +70 -0
  51. package/src/types/response/v5-trade.ts +103 -0
  52. package/src/types/response/v5-user.ts +58 -0
  53. package/src/types/shared.ts +175 -0
  54. package/src/types/v5-shared.ts +213 -0
  55. package/src/types/websockets.ts +115 -0
  56. package/src/types/ws-events/failed-topic-subscription-confirmation.ts +6 -0
  57. package/src/types/ws-events/succeeded-topic-subscription-confirmation.ts +6 -0
  58. package/src/types/ws-events/topic-subscription-confirmation.ts +7 -0
  59. package/src/unified-margin-client.ts +400 -0
  60. package/src/usdc-option-client.ts +333 -0
  61. package/src/usdc-perpetual-client.ts +312 -0
  62. package/src/util/BaseRestClient.ts +502 -0
  63. package/src/util/WsStore.ts +160 -0
  64. package/src/util/browser-support.ts +29 -0
  65. package/src/util/index.ts +5 -0
  66. package/src/util/logger.ts +26 -0
  67. package/src/util/node-support.ts +9 -0
  68. package/src/util/requestUtils.ts +171 -0
  69. package/src/util/websocket-util.ts +550 -0
  70. package/src/websocket-client.ts +1262 -0
@@ -0,0 +1,133 @@
1
+ import {
2
+ CategoryV5,
3
+ OrderFilterV5,
4
+ OrderSMPTypeV5,
5
+ OrderSideV5,
6
+ OrderStatusV5,
7
+ OrderTimeInForceV5,
8
+ OrderTriggerByV5,
9
+ OrderTypeV5,
10
+ PositionIdx,
11
+ } from '../v5-shared';
12
+
13
+ export interface OrderParamsV5 {
14
+ category: CategoryV5;
15
+ symbol: string;
16
+ isLeverage?: 0 | 1;
17
+ side: OrderSideV5;
18
+ orderType: OrderTypeV5;
19
+ qty: string;
20
+ price?: string;
21
+ triggerDirection?: 1 | 2;
22
+ orderFilter?: 'Order' | 'tpslOrder';
23
+ triggerPrice?: string;
24
+ triggerBy?: OrderTriggerByV5;
25
+ orderIv?: string;
26
+ timeInForce?: OrderTimeInForceV5;
27
+ positionIdx?: PositionIdx;
28
+ orderLinkId?: string;
29
+ takeProfit?: string;
30
+ stopLoss?: string;
31
+ tpTriggerBy?: OrderTriggerByV5;
32
+ slTriggerBy?: OrderTriggerByV5;
33
+ reduceOnly?: boolean;
34
+ closeOnTrigger?: boolean;
35
+ smpType?: OrderSMPTypeV5;
36
+ mmp?: boolean;
37
+ tpslMode?: 'Full' | 'Partial';
38
+ tpLimitPrice?: string;
39
+ slLimitPrice?: string;
40
+ tpOrderType?: OrderTypeV5;
41
+ slOrderType?: OrderTypeV5;
42
+ }
43
+
44
+ export interface AmendOrderParamsV5 {
45
+ category: CategoryV5;
46
+ symbol: string;
47
+ orderId?: string;
48
+ orderLinkId?: string;
49
+ orderIv?: string;
50
+ triggerPrice?: string;
51
+ qty?: string;
52
+ price?: string;
53
+ takeProfit?: string;
54
+ stopLoss?: string;
55
+ tpTriggerBy?: OrderTriggerByV5;
56
+ slTriggerBy?: OrderTriggerByV5;
57
+ triggerBy?: OrderTriggerByV5;
58
+ tpLimitPrice?: string;
59
+ slLimitPrice?: string;
60
+ }
61
+
62
+ export interface CancelOrderParamsV5 {
63
+ category: CategoryV5;
64
+ symbol: string;
65
+ orderId?: string;
66
+ orderLinkId?: string;
67
+ orderFilter?: OrderFilterV5;
68
+ }
69
+
70
+ export interface GetAccountOrdersParams {
71
+ category: CategoryV5;
72
+ symbol?: string;
73
+ baseCoin?: string;
74
+ settleCoin?: string;
75
+ orderId?: string;
76
+ orderLinkId?: string;
77
+ openOnly?: 0 | 1 | 2;
78
+ orderFilter?: OrderFilterV5;
79
+ orderStatus?: OrderStatusV5;
80
+ limit?: number;
81
+ cursor?: string;
82
+ }
83
+
84
+ export interface GetAccountHistoricOrdersPArams {
85
+ category: CategoryV5;
86
+ symbol?: string;
87
+ baseCoin?: string;
88
+ orderId?: string;
89
+ orderLinkId?: string;
90
+ orderFilter?: OrderFilterV5;
91
+ orderStatus?: OrderStatusV5;
92
+ startTime?: number;
93
+ endTime?: number;
94
+ limit?: number;
95
+ cursor?: string;
96
+ }
97
+
98
+ export interface CancelAllOrdersParamsV5 {
99
+ category: CategoryV5;
100
+ symbol?: string;
101
+ baseCoin?: string;
102
+ settleCoin?: string;
103
+ orderFilter?: OrderFilterV5;
104
+ }
105
+
106
+ export interface BatchOrderParamsV5 {
107
+ symbol: string;
108
+ side: OrderSideV5;
109
+ orderType: OrderTypeV5;
110
+ qty: string;
111
+ price?: string;
112
+ orderIv?: string;
113
+ timeInForce?: OrderTimeInForceV5;
114
+ orderLinkId: string;
115
+ reduceOnly?: boolean;
116
+ mmp?: boolean;
117
+ smpType?: OrderSMPTypeV5;
118
+ }
119
+
120
+ export interface BatchAmendOrderParamsV5 {
121
+ symbol: string;
122
+ orderId?: string;
123
+ orderLinkId?: string;
124
+ qty?: string;
125
+ price?: string;
126
+ orderIv?: string;
127
+ }
128
+
129
+ export interface BatchCancelOrderParamsV5 {
130
+ symbol: string;
131
+ orderId?: string;
132
+ orderLinkId?: string;
133
+ }
@@ -0,0 +1,21 @@
1
+ import { PermissionsV5 } from '../v5-shared';
2
+
3
+ export interface CreateSubApiKeyParamsV5 {
4
+ subuid: number;
5
+ note?: string;
6
+ readOnly: 0 | 1;
7
+ ips?: string[];
8
+ permissions: PermissionsV5;
9
+ }
10
+
11
+ export interface UpdateApiKeyParamsV5 {
12
+ readOnly?: 0 | 1;
13
+ ips?: string[];
14
+ permissions: PermissionsV5;
15
+ }
16
+
17
+ export interface UpdateSubApiKeyUpdateParamsV5 {
18
+ readOnly?: number;
19
+ ips?: string[];
20
+ permissions: PermissionsV5;
21
+ }
@@ -0,0 +1,236 @@
1
+ export interface UniversalTransferCreateResponse {
2
+ transferId: string;
3
+ }
4
+
5
+ export interface UniversalTransferListResponseV3 {
6
+ list: {
7
+ transferId: string;
8
+ coin: string;
9
+ amount: string;
10
+ timestamp: string;
11
+ status: string;
12
+ fromAccountType: string;
13
+ toAccountType: string;
14
+ fromMemberId: string;
15
+ toMemberId: string;
16
+ }[];
17
+ nextPageCursor: string;
18
+ }
19
+
20
+ export interface QueryInternalTransferSResponseV3 {
21
+ list: {
22
+ transferId: string;
23
+ coin: string;
24
+ amount: string;
25
+ fromAccountType: string;
26
+ toAccountType: string;
27
+ timestamp: string;
28
+ status: string;
29
+ }[];
30
+ nextPageCursor: string;
31
+ }
32
+
33
+ export interface SubAccountTransferResponseV3 {
34
+ list: {
35
+ transferId: string;
36
+ coin: string;
37
+ amount: string;
38
+ memberId: number;
39
+ subMemberId: number;
40
+ timestamp: string;
41
+ status: string;
42
+ type: 'IN' | 'OUT';
43
+ }[];
44
+ nextPageCursor: string;
45
+ }
46
+
47
+ export interface AccountCoinBalanceResponseV3 {
48
+ accountType: string;
49
+ bizType: number;
50
+ accountId: string;
51
+ memberId: string;
52
+ balance: {
53
+ coin: string;
54
+ walletBalance: string;
55
+ transferBalance: string;
56
+ bonus: string;
57
+ };
58
+ }
59
+
60
+ export interface AccountCoinBalancesResponseV3 {
61
+ accountType: string;
62
+ memberId: string;
63
+ balance: {
64
+ coin: string;
65
+ walletBalance: string;
66
+ transferBalance: string;
67
+ bonus: string;
68
+ }[];
69
+ }
70
+
71
+ export interface AssetInfoResponseV3 {
72
+ spot: {
73
+ status: 'ACCOUNT_STATUS_NORMAL' | 'ACCOUNT_STATUS_UNSPECIFIED';
74
+ assets: {
75
+ coin: string;
76
+ frozen: string;
77
+ free: string;
78
+ withdraw: string;
79
+ }[];
80
+ };
81
+ }
82
+
83
+ interface SupportedDepositV3 {
84
+ coin: string;
85
+ chain: string;
86
+ coinShowName: string;
87
+ chainType: string;
88
+ blockConfirmNumber: number;
89
+ minDepositAmount: string;
90
+ }
91
+
92
+ export interface SupportedDepositListResponseV3 {
93
+ configList: SupportedDepositV3[];
94
+ nextPageCursor: string;
95
+ }
96
+
97
+ interface DepositRecordV3 {
98
+ coin: string;
99
+ chain: string;
100
+ amount: string;
101
+ txID: string;
102
+ status: number;
103
+ toAddress: string;
104
+ tag: string;
105
+ depositFee: string;
106
+ successAt: string;
107
+ confirmations: string;
108
+ txIndex: string;
109
+ blockHash: string;
110
+ }
111
+
112
+ export interface DepositRecordQueryResponseV3 {
113
+ rows: DepositRecordV3[];
114
+ nextPageCursor: string;
115
+ }
116
+
117
+ export interface WithdrawRecordsQueryResponseV3 {
118
+ rows: {
119
+ coin: string;
120
+ chain: string;
121
+ amount: string;
122
+ txID: string;
123
+ status: number;
124
+ toAddress: string;
125
+ tag: string;
126
+ withdrawFee: string;
127
+ createTime: string;
128
+ updateTime: string;
129
+ withdrawId: string;
130
+ withdrawType: number;
131
+ }[];
132
+ nextPageCursor: string;
133
+ }
134
+
135
+ export interface CoinInfoV3 {
136
+ name: string;
137
+ coin: string;
138
+ remainAmount: string;
139
+ chains: {
140
+ chainType: string;
141
+ confirmation: string;
142
+ withdrawFee: string;
143
+ depositMin: string;
144
+ withdrawMin: string;
145
+ chain: string;
146
+ chainDeposit: string;
147
+ chainWithdraw: string;
148
+ minAccuracy: string;
149
+ }[];
150
+ }
151
+
152
+ export interface CoinInfoQueryResponseV3 {
153
+ rows: CoinInfoV3[];
154
+ }
155
+
156
+ export interface DepositAddressChainV3 {
157
+ chainType: string;
158
+ addressDeposit: string;
159
+ tagDeposit: string;
160
+ chain: string;
161
+ }
162
+
163
+ export interface DepositAddressResponseV3 {
164
+ coin: string;
165
+ chains: DepositAddressChainV3[];
166
+ }
167
+
168
+ export interface CreateSubMemberResponseV3 {
169
+ uid: number;
170
+ username: string;
171
+ memberType: 1 | 6;
172
+ switch: 0 | 1;
173
+ note: string;
174
+ }
175
+
176
+ export interface CreateSubAPIKeyResponseV3 {
177
+ id: string;
178
+ note: string;
179
+ apiKey: string;
180
+ readOnly: string;
181
+ secret: string;
182
+ permissions: {
183
+ ContractTrade: string[];
184
+ Spot: string[];
185
+ Wallet: string[];
186
+ Options: string[];
187
+ Derivatives: string[];
188
+ CopyTrading: string[];
189
+ BlockTrade: string[];
190
+ Exchange: string[];
191
+ NFT: string[];
192
+ };
193
+ }
194
+
195
+ export interface SubMemberV3 {
196
+ uid: string;
197
+ username: string;
198
+ memberType: 1 | 6;
199
+ status: 1 | 2 | 4;
200
+ remark: string;
201
+ }
202
+
203
+ export interface SubMemberResponseV3 {
204
+ subMembers: SubMemberV3[];
205
+ }
206
+
207
+ export interface APIKeyInfoV3 {
208
+ id: string;
209
+ note: string;
210
+ apiKey: string;
211
+ readOnly: string;
212
+ secret: string;
213
+ permissions: {
214
+ ContractTrade: string[];
215
+ Spot: string[];
216
+ Wallet: string[];
217
+ Options: string[];
218
+ Derivatives: string[];
219
+ CopyTrading: string[];
220
+ BlockTrade: string[];
221
+ Exchange: string[];
222
+ NFT: string[];
223
+ };
224
+ ips: string[];
225
+ type: number;
226
+ deadlineDay: number;
227
+ expiredAt: string;
228
+ createdAt: string;
229
+ unified: number;
230
+ uta: number;
231
+ userID: number;
232
+ inviterID: number;
233
+ vipLevel: string;
234
+ mktMakerLevel: string;
235
+ affiliateID: number;
236
+ }
@@ -0,0 +1,74 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ export interface PaginatedResult<TList = any> {
3
+ nextPageCursor: string;
4
+ list: TList[];
5
+ }
6
+ export interface ContractListResult<TList = any> {
7
+ category: string;
8
+ list: TList[];
9
+ }
10
+
11
+ export interface ContractHistoricOrder {
12
+ symbol: string;
13
+ orderId: string;
14
+ orderLinkId: string;
15
+ side: string;
16
+ orderType: string;
17
+ price: string;
18
+ iv: string;
19
+ qty: string;
20
+ timeInForce: string;
21
+ orderStatus: string;
22
+ positionIdx: number;
23
+ lastPriceOnCreated: string;
24
+ createdTime: string;
25
+ updatedTime: string;
26
+ cancelType: string;
27
+ rejectReason: string;
28
+ stopOrderType: string;
29
+ triggerDirection: number;
30
+ triggerBy: string;
31
+ triggerPrice: string;
32
+ cumExecValue: string;
33
+ cumExecFee: string;
34
+ cumExecQty: string;
35
+ leavesValue: string;
36
+ leavesQty: string;
37
+ takeProfit: string;
38
+ stopLoss: string;
39
+ tpslMode: string;
40
+ tpLimitPrice: string;
41
+ slLimitPrice: string;
42
+ tpTriggerBy: string;
43
+ slTriggerBy: string;
44
+ reduceOnly: boolean;
45
+ closeOnTrigger: boolean;
46
+ blockTradeId: string;
47
+ smpType: string;
48
+ smpGroup: number;
49
+ smpOrderId: string;
50
+ }
51
+
52
+ export interface ContractSymbolTicker {
53
+ symbol: string;
54
+ bidPrice: string;
55
+ askPrice: string;
56
+ lastPrice: string;
57
+ lastTickDirection: string;
58
+ prevPrice24h: string;
59
+ price24hPcnt: string;
60
+ highPrice24h: string;
61
+ lowPrice24h: string;
62
+ prevPrice1h: string;
63
+ markPrice: string;
64
+ indexPrice: string;
65
+ openInterest: string;
66
+ turnover24h: string;
67
+ volume24h: string;
68
+ fundingRate: string;
69
+ nextFundingTime: string;
70
+ predictedDeliveryPrice: string;
71
+ basisRate: string;
72
+ deliveryFeeRate: string;
73
+ deliveryTime: string;
74
+ }
@@ -0,0 +1,13 @@
1
+ export * from './account-asset';
2
+ export * from './contract';
3
+ export * from './shared';
4
+ export * from './spot';
5
+ export * from './usdt-perp';
6
+ export * from './unified-margin';
7
+ export * from './v5-account';
8
+ export * from './v5-asset';
9
+ export * from './v5-market';
10
+ export * from './v5-position';
11
+ export * from './v5-trade';
12
+ export * from './v5-user';
13
+ export * from './v5-spot-leverage-token';
@@ -0,0 +1,19 @@
1
+ export interface SymbolWalletBalance {
2
+ equity: number;
3
+ available_balance: number;
4
+ used_margin: number;
5
+ order_margin: number;
6
+ position_margin: number;
7
+ occ_closing_fee: number;
8
+ occ_funding_fee: number;
9
+ wallet_balance: number;
10
+ realised_pnl: number;
11
+ unrealised_pnl: number;
12
+ cum_realised_pnl: number;
13
+ given_cash: number;
14
+ service_cash: number;
15
+ }
16
+
17
+ export interface WalletBalances {
18
+ [symbol: string]: SymbolWalletBalance | undefined;
19
+ }
@@ -0,0 +1,17 @@
1
+ export interface SpotBalance {
2
+ coin: string;
3
+ coinId: string;
4
+ coinName: string;
5
+ total: string;
6
+ free: string;
7
+ locked: string;
8
+ }
9
+
10
+ export interface SpotBalances {
11
+ balances: SpotBalance[];
12
+ }
13
+
14
+ export interface SpotLastPrice {
15
+ symbol: string;
16
+ price: string;
17
+ }
@@ -0,0 +1,71 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export interface UMPaginatedResult<List = any> {
3
+ nextPageCursor: string;
4
+ category: string;
5
+ list: List[];
6
+ }
7
+
8
+ export interface UMLeverageFilter {
9
+ minLeverage: string;
10
+ maxLeverage: string;
11
+ leverageStep: string;
12
+ }
13
+
14
+ export interface UMPriceFilter {
15
+ minPrice: string;
16
+ maxPrice: string;
17
+ tickSize: string;
18
+ }
19
+
20
+ export interface UMLotSizeFilter {
21
+ maxTradingQty: string;
22
+ minTradingQty: string;
23
+ qtyStep: string;
24
+ }
25
+
26
+ export interface UMInstrumentInfo {
27
+ symbol: string;
28
+ contractType: string;
29
+ status: string;
30
+ baseCoin: string;
31
+ quoteCoin: string;
32
+ launchTime: string;
33
+ deliveryTime: string;
34
+ deliveryFeeRate: string;
35
+ priceScale: string;
36
+ leverageFilter: UMLeverageFilter;
37
+ priceFilter: UMPriceFilter;
38
+ lotSizeFilter: UMLotSizeFilter;
39
+ }
40
+
41
+ export interface UMHistoricOrder {
42
+ symbol: string;
43
+ orderType: string;
44
+ orderLinkId: string;
45
+ orderId: string;
46
+ stopOrderType: string;
47
+ orderStatus: string;
48
+ takeProfit: string;
49
+ cumExecValue: string;
50
+ blockTradeId: string;
51
+ rejectReason: string;
52
+ price: string;
53
+ createdTime: number;
54
+ tpTriggerBy: string;
55
+ timeInForce: string;
56
+ basePrice: string;
57
+ leavesValue: string;
58
+ updatedTime: number;
59
+ side: string;
60
+ triggerPrice: string;
61
+ cumExecFee: string;
62
+ slTriggerBy: string;
63
+ leavesQty: string;
64
+ closeOnTrigger: boolean;
65
+ cumExecQty: string;
66
+ reduceOnly: boolean;
67
+ qty: string;
68
+ stopLoss: string;
69
+ triggerBy: string;
70
+ orderIM: string;
71
+ }
@@ -0,0 +1,58 @@
1
+ export interface PerpPosition {
2
+ user_id: number;
3
+ symbol: string;
4
+ side: string;
5
+ size: number;
6
+ position_value: number;
7
+ entry_price: number;
8
+ liq_price: number;
9
+ bust_price: number;
10
+ leverage: number;
11
+ auto_add_margin: number;
12
+ is_isolated: boolean;
13
+ position_margin: number;
14
+ occ_closing_fee: number;
15
+ realised_pnl: number;
16
+ cum_realised_pnl: number;
17
+ free_qty: number;
18
+ tp_sl_mode: string;
19
+ unrealised_pnl: number;
20
+ deleverage_indicator: number;
21
+ risk_id: number;
22
+ stop_loss: number;
23
+ take_profit: number;
24
+ trailing_stop: number;
25
+ position_idx: number;
26
+ mode: string;
27
+ }
28
+
29
+ export interface PerpPositionRoot {
30
+ data: PerpPosition;
31
+ is_valid: boolean;
32
+ }
33
+
34
+ export interface LinearOrder {
35
+ order_id: string;
36
+ user_id: number;
37
+ symbol: string;
38
+ side: string;
39
+ order_type: string;
40
+ price: number;
41
+ qty: number;
42
+ time_in_force: string;
43
+ order_status: string;
44
+ last_exec_price: number;
45
+ cum_exec_qty: number;
46
+ cum_exec_value: number;
47
+ cum_exec_fee: number;
48
+ reduce_only: boolean;
49
+ close_on_trigger: boolean;
50
+ order_link_id: string;
51
+ created_time: string;
52
+ updated_time: string;
53
+ take_profit: number;
54
+ stop_loss: number;
55
+ tp_trigger_by: string;
56
+ sl_trigger_by: string;
57
+ position_idx: number;
58
+ }