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,337 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { REST_CLIENT_TYPE_ENUM } from './util';
3
+ import {
4
+ APIResponseWithTime,
5
+ AssetExchangeRecordsReq,
6
+ CoinParam,
7
+ InverseActiveConditionalOrderRequest,
8
+ InverseActiveOrdersRequest,
9
+ InverseCancelConditionalOrderRequest,
10
+ InverseCancelOrderRequest,
11
+ InverseChangePositionMarginRequest,
12
+ InverseConditionalOrderRequest,
13
+ InverseGetClosedPnlRequest,
14
+ InverseGetOrderRequest,
15
+ InverseGetTradeRecordsRequest,
16
+ InverseOrderRequest,
17
+ InverseReplaceConditionalOrderRequest,
18
+ InverseReplaceOrderRequest,
19
+ InverseSetLeverageRequest,
20
+ InverseSetMarginTypeRequest,
21
+ InverseSetSlTpPositionModeRequest,
22
+ InverseSetTradingStopRequest,
23
+ SymbolInfo,
24
+ SymbolIntervalFromLimitParam,
25
+ SymbolLimitParam,
26
+ SymbolParam,
27
+ SymbolPeriodLimitParam,
28
+ WalletFundRecordsReq,
29
+ WithdrawRecordsReq,
30
+ } from './types';
31
+ import BaseRestClient from './util/BaseRestClient';
32
+
33
+ /**
34
+ * REST API client for Inverse Perpetual Futures APIs (v2)
35
+ */
36
+ export class InverseClient extends BaseRestClient {
37
+ getClientType() {
38
+ return REST_CLIENT_TYPE_ENUM.inverse;
39
+ }
40
+
41
+ async fetchServerTime(): Promise<number> {
42
+ const res = await this.getServerTime();
43
+ return Number(res.time_now);
44
+ }
45
+
46
+ /**
47
+ *
48
+ * Market Data Endpoints
49
+ *
50
+ */
51
+
52
+ getOrderBook(params: SymbolParam): Promise<APIResponseWithTime<any[]>> {
53
+ return this.get('v2/public/orderBook/L2', params);
54
+ }
55
+
56
+ getKline(
57
+ params: SymbolIntervalFromLimitParam
58
+ ): Promise<APIResponseWithTime<any[]>> {
59
+ return this.get('v2/public/kline/list', params);
60
+ }
61
+
62
+ /**
63
+ * Get latest information for symbol
64
+ */
65
+ getTickers(
66
+ params?: Partial<SymbolParam>
67
+ ): Promise<APIResponseWithTime<any[]>> {
68
+ return this.get('v2/public/tickers', params);
69
+ }
70
+
71
+ getTrades(params: SymbolLimitParam): Promise<APIResponseWithTime<any[]>> {
72
+ return this.get('v2/public/trading-records', params);
73
+ }
74
+
75
+ getSymbols(): Promise<APIResponseWithTime<SymbolInfo[]>> {
76
+ return this.get('v2/public/symbols');
77
+ }
78
+
79
+ getMarkPriceKline(
80
+ params: SymbolIntervalFromLimitParam
81
+ ): Promise<APIResponseWithTime<any[]>> {
82
+ return this.get('v2/public/mark-price-kline', params);
83
+ }
84
+
85
+ getIndexPriceKline(
86
+ params: SymbolIntervalFromLimitParam
87
+ ): Promise<APIResponseWithTime<any[]>> {
88
+ return this.get('v2/public/index-price-kline', params);
89
+ }
90
+
91
+ getPremiumIndexKline(
92
+ params: SymbolIntervalFromLimitParam
93
+ ): Promise<APIResponseWithTime<any[]>> {
94
+ return this.get('v2/public/premium-index-kline', params);
95
+ }
96
+
97
+ /**
98
+ *
99
+ * Market Data : Advanced
100
+ *
101
+ */
102
+
103
+ getOpenInterest(
104
+ params: SymbolPeriodLimitParam
105
+ ): Promise<APIResponseWithTime<any[]>> {
106
+ return this.get('v2/public/open-interest', params);
107
+ }
108
+
109
+ getLatestBigDeal(
110
+ params: SymbolLimitParam
111
+ ): Promise<APIResponseWithTime<any[]>> {
112
+ return this.get('v2/public/big-deal', params);
113
+ }
114
+
115
+ getLongShortRatio(
116
+ params: SymbolPeriodLimitParam
117
+ ): Promise<APIResponseWithTime<any[]>> {
118
+ return this.get('v2/public/account-ratio', params);
119
+ }
120
+
121
+ /**
122
+ *
123
+ * Account Data Endpoints
124
+ *
125
+ */
126
+
127
+ getApiKeyInfo(): Promise<APIResponseWithTime<any>> {
128
+ return this.getPrivate('v2/private/account/api-key');
129
+ }
130
+
131
+ /**
132
+ *
133
+ * Wallet Data Endpoints
134
+ *
135
+ */
136
+
137
+ getWalletBalance(
138
+ params?: Partial<CoinParam>
139
+ ): Promise<APIResponseWithTime<any>> {
140
+ return this.getPrivate('v2/private/wallet/balance', params);
141
+ }
142
+
143
+ getWalletFundRecords(
144
+ params?: WalletFundRecordsReq
145
+ ): Promise<APIResponseWithTime<any>> {
146
+ return this.getPrivate('v2/private/wallet/fund/records', params);
147
+ }
148
+
149
+ getWithdrawRecords(
150
+ params?: WithdrawRecordsReq
151
+ ): Promise<APIResponseWithTime<any>> {
152
+ return this.getPrivate('v2/private/wallet/withdraw/list', params);
153
+ }
154
+
155
+ getAssetExchangeRecords(
156
+ params?: AssetExchangeRecordsReq
157
+ ): Promise<APIResponseWithTime<any>> {
158
+ return this.getPrivate('v2/private/exchange-order/list', params);
159
+ }
160
+
161
+ /**
162
+ *
163
+ * API Data Endpoints
164
+ *
165
+ */
166
+
167
+ getServerTime(): Promise<APIResponseWithTime<{}>> {
168
+ return this.get('v2/public/time');
169
+ }
170
+
171
+ getApiAnnouncements(): Promise<APIResponseWithTime<any[]>> {
172
+ return this.get('v2/public/announcement');
173
+ }
174
+
175
+ /**
176
+ *
177
+ * Account Data Endpoints
178
+ *
179
+ */
180
+
181
+ /**
182
+ * Active orders
183
+ */
184
+
185
+ placeActiveOrder(
186
+ orderRequest: InverseOrderRequest
187
+ ): Promise<APIResponseWithTime<any>> {
188
+ return this.postPrivate('v2/private/order/create', orderRequest);
189
+ }
190
+
191
+ getActiveOrderList(
192
+ params: InverseActiveOrdersRequest
193
+ ): Promise<APIResponseWithTime<any>> {
194
+ return this.getPrivate('v2/private/order/list', params);
195
+ }
196
+
197
+ cancelActiveOrder(
198
+ params: InverseCancelOrderRequest
199
+ ): Promise<APIResponseWithTime<any>> {
200
+ return this.postPrivate('v2/private/order/cancel', params);
201
+ }
202
+
203
+ cancelAllActiveOrders(
204
+ params: SymbolParam
205
+ ): Promise<APIResponseWithTime<any>> {
206
+ return this.postPrivate('v2/private/order/cancelAll', params);
207
+ }
208
+
209
+ replaceActiveOrder(
210
+ params: InverseReplaceOrderRequest
211
+ ): Promise<APIResponseWithTime<any>> {
212
+ return this.postPrivate('v2/private/order/replace', params);
213
+ }
214
+
215
+ queryActiveOrder(
216
+ params: InverseGetOrderRequest
217
+ ): Promise<APIResponseWithTime<any>> {
218
+ return this.getPrivate('v2/private/order', params);
219
+ }
220
+
221
+ /**
222
+ * Conditional orders
223
+ */
224
+
225
+ placeConditionalOrder(
226
+ params: InverseConditionalOrderRequest
227
+ ): Promise<APIResponseWithTime<any>> {
228
+ return this.postPrivate('v2/private/stop-order/create', params);
229
+ }
230
+
231
+ /** get conditional order list. This may see delays, use queryConditionalOrder() for real-time queries */
232
+ getConditionalOrder(
233
+ params: InverseActiveConditionalOrderRequest
234
+ ): Promise<APIResponseWithTime<any>> {
235
+ return this.getPrivate('v2/private/stop-order/list', params);
236
+ }
237
+
238
+ cancelConditionalOrder(
239
+ params: InverseCancelConditionalOrderRequest
240
+ ): Promise<APIResponseWithTime<any>> {
241
+ return this.postPrivate('v2/private/stop-order/cancel', params);
242
+ }
243
+
244
+ cancelAllConditionalOrders(
245
+ params: SymbolParam
246
+ ): Promise<APIResponseWithTime<any>> {
247
+ return this.postPrivate('v2/private/stop-order/cancelAll', params);
248
+ }
249
+
250
+ replaceConditionalOrder(
251
+ params: InverseReplaceConditionalOrderRequest
252
+ ): Promise<APIResponseWithTime<any>> {
253
+ return this.postPrivate('v2/private/stop-order/replace', params);
254
+ }
255
+
256
+ queryConditionalOrder(
257
+ params: InverseGetOrderRequest
258
+ ): Promise<APIResponseWithTime<any>> {
259
+ return this.getPrivate('v2/private/stop-order', params);
260
+ }
261
+
262
+ /**
263
+ * Position
264
+ */
265
+
266
+ getPosition(
267
+ params?: Partial<SymbolParam>
268
+ ): Promise<APIResponseWithTime<any>> {
269
+ return this.getPrivate('v2/private/position/list', params);
270
+ }
271
+
272
+ changePositionMargin(
273
+ params: InverseChangePositionMarginRequest
274
+ ): Promise<APIResponseWithTime<any>> {
275
+ return this.postPrivate('position/change-position-margin', params);
276
+ }
277
+
278
+ setTradingStop(
279
+ params: InverseSetTradingStopRequest
280
+ ): Promise<APIResponseWithTime<any>> {
281
+ return this.postPrivate('v2/private/position/trading-stop', params);
282
+ }
283
+
284
+ setUserLeverage(
285
+ params: InverseSetLeverageRequest
286
+ ): Promise<APIResponseWithTime<any>> {
287
+ return this.postPrivate('v2/private/position/leverage/save', params);
288
+ }
289
+
290
+ getTradeRecords(
291
+ params: InverseGetTradeRecordsRequest
292
+ ): Promise<APIResponseWithTime<any>> {
293
+ return this.getPrivate('v2/private/execution/list', params);
294
+ }
295
+
296
+ getClosedPnl(
297
+ params: InverseGetClosedPnlRequest
298
+ ): Promise<APIResponseWithTime<any>> {
299
+ return this.getPrivate('v2/private/trade/closed-pnl/list', params);
300
+ }
301
+
302
+ setSlTpPositionMode(
303
+ params: InverseSetSlTpPositionModeRequest
304
+ ): Promise<APIResponseWithTime<any>> {
305
+ return this.postPrivate('v2/private/tpsl/switch-mode', params);
306
+ }
307
+
308
+ setMarginType(
309
+ params: InverseSetMarginTypeRequest
310
+ ): Promise<APIResponseWithTime<any>> {
311
+ return this.postPrivate('v2/private/position/switch-isolated', params);
312
+ }
313
+
314
+ /**
315
+ * Funding
316
+ */
317
+
318
+ getLastFundingRate(params: SymbolParam): Promise<APIResponseWithTime<any>> {
319
+ return this.get('v2/public/funding/prev-funding-rate', params);
320
+ }
321
+
322
+ getMyLastFundingFee(params: SymbolParam): Promise<APIResponseWithTime<any>> {
323
+ return this.getPrivate('v2/private/funding/prev-funding', params);
324
+ }
325
+
326
+ getPredictedFunding(params: SymbolParam): Promise<APIResponseWithTime<any>> {
327
+ return this.getPrivate('v2/private/funding/predicted-funding', params);
328
+ }
329
+
330
+ /**
331
+ * LCP Info
332
+ */
333
+
334
+ getLcpInfo(params: SymbolParam): Promise<APIResponseWithTime<any>> {
335
+ return this.getPrivate('v2/private/account/lcp', params);
336
+ }
337
+ }