bybit-api 3.6.1 → 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 (93) hide show
  1. package/lib/contract-client.d.ts +17 -3
  2. package/lib/contract-client.js +17 -3
  3. package/lib/contract-client.js.map +1 -1
  4. package/lib/rest-client-v5.d.ts +259 -10
  5. package/lib/rest-client-v5.js +196 -7
  6. package/lib/rest-client-v5.js.map +1 -1
  7. package/lib/types/request/contract.d.ts +21 -11
  8. package/lib/types/request/index.d.ts +1 -0
  9. package/lib/types/request/index.js +1 -0
  10. package/lib/types/request/index.js.map +1 -1
  11. package/lib/types/request/v5-account.d.ts +5 -0
  12. package/lib/types/request/v5-market.d.ts +10 -2
  13. package/lib/types/request/v5-position.d.ts +13 -2
  14. package/lib/types/request/v5-pre-upgrade.d.ts +34 -0
  15. package/lib/types/request/v5-pre-upgrade.js +3 -0
  16. package/lib/types/request/v5-pre-upgrade.js.map +1 -0
  17. package/lib/types/request/v5-trade.d.ts +24 -1
  18. package/lib/types/response/contract.d.ts +22 -12
  19. package/lib/types/response/v5-account.d.ts +1 -0
  20. package/lib/types/response/v5-market.d.ts +6 -0
  21. package/lib/types/response/v5-position.d.ts +26 -0
  22. package/lib/types/response/v5-trade.d.ts +7 -0
  23. package/lib/types/v5-shared.d.ts +4 -1
  24. package/lib/util/websocket-util.d.ts +2 -1
  25. package/lib/util/websocket-util.js +2 -2
  26. package/lib/util/websocket-util.js.map +1 -1
  27. package/lib/websocket-client.js +1 -1
  28. package/lib/websocket-client.js.map +1 -1
  29. package/package.json +13 -1
  30. package/src/account-asset-client-v3.ts +310 -0
  31. package/src/account-asset-client.ts +149 -0
  32. package/src/constants/enum.ts +105 -0
  33. package/src/contract-client.ts +360 -0
  34. package/src/copy-trading-client.ts +159 -0
  35. package/src/index.ts +18 -0
  36. package/src/inverse-client.ts +337 -0
  37. package/src/inverse-futures-client.ts +403 -0
  38. package/src/linear-client.ts +387 -0
  39. package/src/rest-client-v5.ts +1638 -0
  40. package/src/spot-client-v3.ts +303 -0
  41. package/src/spot-client.ts +180 -0
  42. package/src/types/index.ts +5 -0
  43. package/src/types/request/account-asset.ts +258 -0
  44. package/src/types/request/contract.ts +139 -0
  45. package/src/types/request/copy-trading.ts +53 -0
  46. package/src/types/request/index.ts +18 -0
  47. package/src/types/request/inverse.ts +135 -0
  48. package/src/types/request/linear.ts +201 -0
  49. package/src/types/request/spot.ts +89 -0
  50. package/src/types/request/unified-margin.ts +247 -0
  51. package/src/types/request/usdc-options.ts +134 -0
  52. package/src/types/request/usdc-perp.ts +100 -0
  53. package/src/types/request/usdc-shared.ts +39 -0
  54. package/src/types/request/v5-account.ts +40 -0
  55. package/src/types/request/v5-asset.ts +133 -0
  56. package/src/types/request/v5-market.ts +127 -0
  57. package/src/types/request/v5-position.ts +107 -0
  58. package/src/types/request/v5-pre-upgrade.ts +37 -0
  59. package/src/types/request/v5-spot-leverage-token.ts +23 -0
  60. package/src/types/request/v5-trade.ts +133 -0
  61. package/src/types/request/v5-user.ts +21 -0
  62. package/src/types/response/account-asset.ts +236 -0
  63. package/src/types/response/contract.ts +74 -0
  64. package/src/types/response/index.ts +13 -0
  65. package/src/types/response/shared.ts +19 -0
  66. package/src/types/response/spot.ts +17 -0
  67. package/src/types/response/unified-margin.ts +71 -0
  68. package/src/types/response/usdt-perp.ts +58 -0
  69. package/src/types/response/v5-account.ts +122 -0
  70. package/src/types/response/v5-asset.ts +170 -0
  71. package/src/types/response/v5-market.ts +271 -0
  72. package/src/types/response/v5-position.ts +118 -0
  73. package/src/types/response/v5-spot-leverage-token.ts +70 -0
  74. package/src/types/response/v5-trade.ts +103 -0
  75. package/src/types/response/v5-user.ts +58 -0
  76. package/src/types/shared.ts +175 -0
  77. package/src/types/v5-shared.ts +213 -0
  78. package/src/types/websockets.ts +115 -0
  79. package/src/types/ws-events/failed-topic-subscription-confirmation.ts +6 -0
  80. package/src/types/ws-events/succeeded-topic-subscription-confirmation.ts +6 -0
  81. package/src/types/ws-events/topic-subscription-confirmation.ts +7 -0
  82. package/src/unified-margin-client.ts +400 -0
  83. package/src/usdc-option-client.ts +333 -0
  84. package/src/usdc-perpetual-client.ts +312 -0
  85. package/src/util/BaseRestClient.ts +502 -0
  86. package/src/util/WsStore.ts +160 -0
  87. package/src/util/browser-support.ts +29 -0
  88. package/src/util/index.ts +5 -0
  89. package/src/util/logger.ts +26 -0
  90. package/src/util/node-support.ts +9 -0
  91. package/src/util/requestUtils.ts +171 -0
  92. package/src/util/websocket-util.ts +550 -0
  93. package/src/websocket-client.ts +1262 -0
@@ -0,0 +1,403 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { REST_CLIENT_TYPE_ENUM } from './util/requestUtils';
3
+ import {
4
+ APIResponseWithTime,
5
+ AssetExchangeRecordsReq,
6
+ CoinParam,
7
+ SymbolInfo,
8
+ SymbolIntervalFromLimitParam,
9
+ SymbolLimitParam,
10
+ SymbolParam,
11
+ SymbolPeriodLimitParam,
12
+ WalletFundRecordsReq,
13
+ WithdrawRecordsReq,
14
+ } from './types/shared';
15
+ import BaseRestClient from './util/BaseRestClient';
16
+
17
+ /**
18
+ * REST API client for Inverse Futures APIs (e.g. quarterly futures) (v2)
19
+ */
20
+ export class InverseFuturesClient extends BaseRestClient {
21
+ getClientType() {
22
+ return REST_CLIENT_TYPE_ENUM.inverseFutures;
23
+ }
24
+
25
+ async fetchServerTime(): Promise<number> {
26
+ const res = await this.getServerTime();
27
+ return Number(res.time_now);
28
+ }
29
+
30
+ /**
31
+ *
32
+ * Market Data Endpoints
33
+ *
34
+ */
35
+
36
+ getOrderBook(params: SymbolParam): Promise<APIResponseWithTime<any[]>> {
37
+ return this.get('v2/public/orderBook/L2', params);
38
+ }
39
+
40
+ getKline(
41
+ params: SymbolIntervalFromLimitParam
42
+ ): Promise<APIResponseWithTime<any[]>> {
43
+ return this.get('v2/public/kline/list', params);
44
+ }
45
+
46
+ /**
47
+ * Get latest information for symbol
48
+ */
49
+ getTickers(
50
+ params?: Partial<SymbolParam>
51
+ ): Promise<APIResponseWithTime<any[]>> {
52
+ return this.get('v2/public/tickers', params);
53
+ }
54
+
55
+ /**
56
+ * Public trading records
57
+ */
58
+ getTrades(params: SymbolLimitParam): Promise<APIResponseWithTime<any[]>> {
59
+ return this.get('v2/public/trading-records', params);
60
+ }
61
+
62
+ getSymbols(): Promise<APIResponseWithTime<SymbolInfo[]>> {
63
+ return this.get('v2/public/symbols');
64
+ }
65
+
66
+ getMarkPriceKline(
67
+ params: SymbolIntervalFromLimitParam
68
+ ): Promise<APIResponseWithTime<any[]>> {
69
+ return this.get('v2/public/mark-price-kline', params);
70
+ }
71
+
72
+ getIndexPriceKline(
73
+ params: SymbolIntervalFromLimitParam
74
+ ): Promise<APIResponseWithTime<any[]>> {
75
+ return this.get('v2/public/index-price-kline', params);
76
+ }
77
+
78
+ getPremiumIndexKline(
79
+ params: SymbolIntervalFromLimitParam
80
+ ): Promise<APIResponseWithTime<any[]>> {
81
+ return this.get('v2/public/premium-index-kline', params);
82
+ }
83
+
84
+ /**
85
+ *
86
+ * Market Data : Advanced
87
+ *
88
+ */
89
+
90
+ getOpenInterest(
91
+ params: SymbolPeriodLimitParam
92
+ ): Promise<APIResponseWithTime<any[]>> {
93
+ return this.get('v2/public/open-interest', params);
94
+ }
95
+
96
+ getLatestBigDeal(
97
+ params: SymbolLimitParam
98
+ ): Promise<APIResponseWithTime<any[]>> {
99
+ return this.get('v2/public/big-deal', params);
100
+ }
101
+
102
+ getLongShortRatio(
103
+ params: SymbolPeriodLimitParam
104
+ ): Promise<APIResponseWithTime<any[]>> {
105
+ return this.get('v2/public/account-ratio', params);
106
+ }
107
+
108
+ /**
109
+ *
110
+ * Account Data Endpoints
111
+ *
112
+ */
113
+
114
+ getApiKeyInfo(): Promise<APIResponseWithTime<any>> {
115
+ return this.getPrivate('v2/private/account/api-key');
116
+ }
117
+
118
+ /**
119
+ *
120
+ * Wallet Data Endpoints
121
+ *
122
+ */
123
+
124
+ getWalletBalance(
125
+ params?: Partial<CoinParam>
126
+ ): Promise<APIResponseWithTime<any>> {
127
+ return this.getPrivate('v2/private/wallet/balance', params);
128
+ }
129
+
130
+ getWalletFundRecords(
131
+ params?: WalletFundRecordsReq
132
+ ): Promise<APIResponseWithTime<any>> {
133
+ return this.getPrivate('v2/private/wallet/fund/records', params);
134
+ }
135
+
136
+ getWithdrawRecords(
137
+ params?: WithdrawRecordsReq
138
+ ): Promise<APIResponseWithTime<any>> {
139
+ return this.getPrivate('v2/private/wallet/withdraw/list', params);
140
+ }
141
+
142
+ getAssetExchangeRecords(
143
+ params?: AssetExchangeRecordsReq
144
+ ): Promise<APIResponseWithTime<any>> {
145
+ return this.getPrivate('v2/private/exchange-order/list', params);
146
+ }
147
+
148
+ /**
149
+ *
150
+ * API Data Endpoints
151
+ *
152
+ */
153
+
154
+ getServerTime(): Promise<APIResponseWithTime<{}>> {
155
+ return this.get('v2/public/time');
156
+ }
157
+
158
+ getApiAnnouncements(): Promise<APIResponseWithTime<any>> {
159
+ return this.get('v2/public/announcement');
160
+ }
161
+
162
+ /**
163
+ *
164
+ * Account Data Endpoints
165
+ *
166
+ */
167
+
168
+ /**
169
+ * Active orders
170
+ */
171
+
172
+ placeActiveOrder(orderRequest: {
173
+ side: string;
174
+ symbol: string;
175
+ order_type: string;
176
+ qty: number;
177
+ price?: number;
178
+ time_in_force: string;
179
+ take_profit?: number;
180
+ stop_loss?: number;
181
+ reduce_only?: boolean;
182
+ close_on_trigger?: boolean;
183
+ order_link_id?: string;
184
+ }): Promise<APIResponseWithTime<any>> {
185
+ return this.postPrivate('futures/private/order/create', orderRequest);
186
+ }
187
+
188
+ getActiveOrderList(params: {
189
+ symbol: string;
190
+ order_status?: string;
191
+ direction?: string;
192
+ limit?: number;
193
+ cursor?: string;
194
+ }): Promise<APIResponseWithTime<any>> {
195
+ return this.getPrivate('futures/private/order/list', params);
196
+ }
197
+
198
+ cancelActiveOrder(params: {
199
+ symbol: string;
200
+ order_id?: string;
201
+ order_link_id?: string;
202
+ }): Promise<APIResponseWithTime<any>> {
203
+ return this.postPrivate('futures/private/order/cancel', params);
204
+ }
205
+
206
+ cancelAllActiveOrders(
207
+ params: SymbolParam
208
+ ): Promise<APIResponseWithTime<any>> {
209
+ return this.postPrivate('futures/private/order/cancelAll', params);
210
+ }
211
+
212
+ replaceActiveOrder(params: {
213
+ order_id?: string;
214
+ order_link_id?: string;
215
+ symbol: string;
216
+ p_r_qty?: string;
217
+ p_r_price?: string;
218
+ }): Promise<APIResponseWithTime<any>> {
219
+ return this.postPrivate('futures/private/order/replace', params);
220
+ }
221
+
222
+ queryActiveOrder(params: {
223
+ order_id?: string;
224
+ order_link_id?: string;
225
+ symbol: string;
226
+ }): Promise<APIResponseWithTime<any>> {
227
+ return this.getPrivate('futures/private/order', params);
228
+ }
229
+
230
+ /**
231
+ * Conditional orders
232
+ */
233
+
234
+ placeConditionalOrder(params: {
235
+ side: string;
236
+ symbol: string;
237
+ order_type: string;
238
+ qty: string;
239
+ price?: string;
240
+ base_price: string;
241
+ stop_px: string;
242
+ time_in_force: string;
243
+ trigger_by?: string;
244
+ close_on_trigger?: boolean;
245
+ order_link_id?: string;
246
+ }): Promise<APIResponseWithTime<any>> {
247
+ return this.postPrivate('futures/private/stop-order/create', params);
248
+ }
249
+
250
+ getConditionalOrder(params: {
251
+ symbol: string;
252
+ stop_order_status?: string;
253
+ direction?: string;
254
+ limit?: number;
255
+ cursor?: string;
256
+ }): Promise<APIResponseWithTime<any>> {
257
+ return this.getPrivate('futures/private/stop-order/list', params);
258
+ }
259
+
260
+ cancelConditionalOrder(params: {
261
+ symbol: string;
262
+ stop_order_id?: string;
263
+ order_link_id?: string;
264
+ }): Promise<APIResponseWithTime<any>> {
265
+ return this.postPrivate('futures/private/stop-order/cancel', params);
266
+ }
267
+
268
+ cancelAllConditionalOrders(
269
+ params: SymbolParam
270
+ ): Promise<APIResponseWithTime<any>> {
271
+ return this.postPrivate('futures/private/stop-order/cancelAll', params);
272
+ }
273
+
274
+ replaceConditionalOrder(params: {
275
+ stop_order_id?: string;
276
+ order_link_id?: string;
277
+ symbol: string;
278
+ p_r_qty?: number;
279
+ p_r_price?: string;
280
+ p_r_trigger_price?: string;
281
+ }): Promise<APIResponseWithTime<any>> {
282
+ return this.postPrivate('futures/private/stop-order/replace', params);
283
+ }
284
+
285
+ queryConditionalOrder(params: {
286
+ symbol: string;
287
+ stop_order_id?: string;
288
+ order_link_id?: string;
289
+ }): Promise<APIResponseWithTime<any>> {
290
+ return this.getPrivate('futures/private/stop-order', params);
291
+ }
292
+
293
+ /**
294
+ * Position
295
+ */
296
+
297
+ /**
298
+ * Get position list
299
+ */
300
+ getPosition(
301
+ params?: Partial<SymbolParam>
302
+ ): Promise<APIResponseWithTime<any>> {
303
+ return this.getPrivate('futures/private/position/list', params);
304
+ }
305
+
306
+ changePositionMargin(params: {
307
+ symbol: string;
308
+ margin: string;
309
+ }): Promise<APIResponseWithTime<any>> {
310
+ return this.postPrivate(
311
+ 'futures/private/position/change-position-margin',
312
+ params
313
+ );
314
+ }
315
+
316
+ setTradingStop(params: {
317
+ symbol: string;
318
+ take_profit?: number;
319
+ stop_loss?: number;
320
+ trailing_stop?: number;
321
+ tp_trigger_by?: string;
322
+ sl_trigger_by?: string;
323
+ new_trailing_active?: number;
324
+ }): Promise<APIResponseWithTime<any>> {
325
+ return this.postPrivate('futures/private/position/trading-stop', params);
326
+ }
327
+
328
+ setUserLeverage(params: {
329
+ symbol: string;
330
+ buy_leverage: number;
331
+ sell_leverage: number;
332
+ }): Promise<APIResponseWithTime<any>> {
333
+ return this.postPrivate('futures/private/position/leverage/save', params);
334
+ }
335
+
336
+ /**
337
+ * Position mode switch
338
+ */
339
+ setPositionMode(params: {
340
+ symbol: string;
341
+ mode: number;
342
+ }): Promise<APIResponseWithTime<any>> {
343
+ return this.postPrivate('futures/private/position/switch-mode', params);
344
+ }
345
+
346
+ /**
347
+ * Cross/Isolated margin switch. Must set leverage value when switching.
348
+ */
349
+ setMarginType(params: {
350
+ symbol: string;
351
+ is_isolated: boolean;
352
+ buy_leverage: number;
353
+ sell_leverage: number;
354
+ }): Promise<APIResponseWithTime<any>> {
355
+ return this.postPrivate('futures/private/position/switch-isolated', params);
356
+ }
357
+
358
+ getTradeRecords(params: {
359
+ order_id?: string;
360
+ symbol: string;
361
+ start_time?: number;
362
+ page?: number;
363
+ limit?: number;
364
+ order?: string;
365
+ }): Promise<APIResponseWithTime<any>> {
366
+ return this.getPrivate('futures/private/execution/list', params);
367
+ }
368
+
369
+ getClosedPnl(params: {
370
+ symbol: string;
371
+ start_time?: number;
372
+ end_time?: number;
373
+ exec_type?: string;
374
+ page?: number;
375
+ limit?: number;
376
+ }): Promise<APIResponseWithTime<any>> {
377
+ return this.getPrivate('futures/private/trade/closed-pnl/list', params);
378
+ }
379
+
380
+ /**
381
+ * Funding
382
+ */
383
+
384
+ getLastFundingRate(params: SymbolParam): Promise<APIResponseWithTime<any>> {
385
+ return this.get('v2/public/funding/prev-funding-rate', params);
386
+ }
387
+
388
+ getMyLastFundingFee(params: SymbolParam): Promise<APIResponseWithTime<any>> {
389
+ return this.getPrivate('v2/private/funding/prev-funding', params);
390
+ }
391
+
392
+ getPredictedFunding(params: SymbolParam): Promise<APIResponseWithTime<any>> {
393
+ return this.getPrivate('v2/private/funding/predicted-funding', params);
394
+ }
395
+
396
+ /**
397
+ * LCP Info
398
+ */
399
+
400
+ getLcpInfo(params: SymbolParam): Promise<APIResponseWithTime<any>> {
401
+ return this.getPrivate('v2/private/account/lcp', params);
402
+ }
403
+ }