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.
- package/lib/util/websocket-util.d.ts +2 -1
- package/lib/util/websocket-util.js +2 -2
- package/lib/util/websocket-util.js.map +1 -1
- package/lib/websocket-client.js +1 -1
- package/lib/websocket-client.js.map +1 -1
- package/package.json +13 -1
- package/src/account-asset-client-v3.ts +310 -0
- package/src/account-asset-client.ts +149 -0
- package/src/constants/enum.ts +105 -0
- package/src/contract-client.ts +360 -0
- package/src/copy-trading-client.ts +159 -0
- package/src/index.ts +18 -0
- package/src/inverse-client.ts +337 -0
- package/src/inverse-futures-client.ts +403 -0
- package/src/linear-client.ts +387 -0
- package/src/rest-client-v5.ts +1638 -0
- package/src/spot-client-v3.ts +303 -0
- package/src/spot-client.ts +180 -0
- package/src/types/index.ts +5 -0
- package/src/types/request/account-asset.ts +258 -0
- package/src/types/request/contract.ts +139 -0
- package/src/types/request/copy-trading.ts +53 -0
- package/src/types/request/index.ts +18 -0
- package/src/types/request/inverse.ts +135 -0
- package/src/types/request/linear.ts +201 -0
- package/src/types/request/spot.ts +89 -0
- package/src/types/request/unified-margin.ts +247 -0
- package/src/types/request/usdc-options.ts +134 -0
- package/src/types/request/usdc-perp.ts +100 -0
- package/src/types/request/usdc-shared.ts +39 -0
- package/src/types/request/v5-account.ts +40 -0
- package/src/types/request/v5-asset.ts +133 -0
- package/src/types/request/v5-market.ts +127 -0
- package/src/types/request/v5-position.ts +107 -0
- package/src/types/request/v5-pre-upgrade.ts +37 -0
- package/src/types/request/v5-spot-leverage-token.ts +23 -0
- package/src/types/request/v5-trade.ts +133 -0
- package/src/types/request/v5-user.ts +21 -0
- package/src/types/response/account-asset.ts +236 -0
- package/src/types/response/contract.ts +74 -0
- package/src/types/response/index.ts +13 -0
- package/src/types/response/shared.ts +19 -0
- package/src/types/response/spot.ts +17 -0
- package/src/types/response/unified-margin.ts +71 -0
- package/src/types/response/usdt-perp.ts +58 -0
- package/src/types/response/v5-account.ts +122 -0
- package/src/types/response/v5-asset.ts +170 -0
- package/src/types/response/v5-market.ts +271 -0
- package/src/types/response/v5-position.ts +118 -0
- package/src/types/response/v5-spot-leverage-token.ts +70 -0
- package/src/types/response/v5-trade.ts +103 -0
- package/src/types/response/v5-user.ts +58 -0
- package/src/types/shared.ts +175 -0
- package/src/types/v5-shared.ts +213 -0
- package/src/types/websockets.ts +115 -0
- package/src/types/ws-events/failed-topic-subscription-confirmation.ts +6 -0
- package/src/types/ws-events/succeeded-topic-subscription-confirmation.ts +6 -0
- package/src/types/ws-events/topic-subscription-confirmation.ts +7 -0
- package/src/unified-margin-client.ts +400 -0
- package/src/usdc-option-client.ts +333 -0
- package/src/usdc-perpetual-client.ts +312 -0
- package/src/util/BaseRestClient.ts +502 -0
- package/src/util/WsStore.ts +160 -0
- package/src/util/browser-support.ts +29 -0
- package/src/util/index.ts +5 -0
- package/src/util/logger.ts +26 -0
- package/src/util/node-support.ts +9 -0
- package/src/util/requestUtils.ts +171 -0
- package/src/util/websocket-util.ts +550 -0
- package/src/websocket-client.ts +1262 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import {
|
|
3
|
+
APIResponseV3,
|
|
4
|
+
APIResponseWithTime,
|
|
5
|
+
USDCOptionsActiveOrdersRealtimeRequest,
|
|
6
|
+
USDCOptionsActiveOrdersRequest,
|
|
7
|
+
USDCOptionsCancelAllOrdersRequest,
|
|
8
|
+
USDCOptionsCancelOrderRequest,
|
|
9
|
+
USDCOptionsContractInfoRequest,
|
|
10
|
+
USDCOptionsDeliveryHistoryRequest,
|
|
11
|
+
USDCOptionsDeliveryPriceRequest,
|
|
12
|
+
USDCOptionsHistoricOrdersRequest,
|
|
13
|
+
USDCOptionsHistoricalVolatilityRequest,
|
|
14
|
+
USDCOptionsModifyMMPRequest,
|
|
15
|
+
USDCOptionsModifyOrderRequest,
|
|
16
|
+
USDCOptionsOrderExecutionRequest,
|
|
17
|
+
USDCOptionsOrderRequest,
|
|
18
|
+
USDCOptionsPositionsInfoExpiryRequest,
|
|
19
|
+
USDCOptionsRecentTradesRequest,
|
|
20
|
+
USDCPositionsRequest,
|
|
21
|
+
USDCTransactionLogRequest,
|
|
22
|
+
} from './types';
|
|
23
|
+
import { REST_CLIENT_TYPE_ENUM } from './util';
|
|
24
|
+
import BaseRestClient from './util/BaseRestClient';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* REST API client for USDC Option APIs
|
|
28
|
+
*/
|
|
29
|
+
export class USDCOptionClient extends BaseRestClient {
|
|
30
|
+
getClientType() {
|
|
31
|
+
return REST_CLIENT_TYPE_ENUM.v3;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async fetchServerTime(): Promise<number> {
|
|
35
|
+
const res = await this.getServerTime();
|
|
36
|
+
return Number(res.time_now);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* Market Data Endpoints
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/** Query order book info. Each side has a depth of 25 orders. */
|
|
46
|
+
getOrderBook(symbol: string): Promise<APIResponseV3<any>> {
|
|
47
|
+
return this.get('/option/usdc/openapi/public/v1/order-book', { symbol });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Fetch trading rules (such as min/max qty). Query for all if blank. */
|
|
51
|
+
getContractInfo(
|
|
52
|
+
params?: USDCOptionsContractInfoRequest
|
|
53
|
+
): Promise<APIResponseV3<any>> {
|
|
54
|
+
return this.get('/option/usdc/openapi/public/v1/symbols', params);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Get a symbol price/statistics ticker */
|
|
58
|
+
getSymbolTicker(symbol: string): Promise<APIResponseV3<any>> {
|
|
59
|
+
return this.get('/option/usdc/openapi/public/v1/tick', { symbol });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Get delivery information */
|
|
63
|
+
getDeliveryPrice(
|
|
64
|
+
params?: USDCOptionsDeliveryPriceRequest
|
|
65
|
+
): Promise<APIResponseV3<any>> {
|
|
66
|
+
return this.get('/option/usdc/openapi/public/v1/delivery-price', params);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Returned records are Taker Buy in default. */
|
|
70
|
+
getLast500Trades(
|
|
71
|
+
params: USDCOptionsRecentTradesRequest
|
|
72
|
+
): Promise<APIResponseV3<any>> {
|
|
73
|
+
return this.get(
|
|
74
|
+
'/option/usdc/openapi/public/v1/query-trade-latest',
|
|
75
|
+
params
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The data is in hourly.
|
|
81
|
+
* If time field is not passed, it returns the recent 1 hour data by default.
|
|
82
|
+
* It could be any timeframe by inputting startTime & endTime, but it must satisfy [endTime - startTime] <= 30 days.
|
|
83
|
+
* It returns all data in 2 years when startTime & endTime are not passed.
|
|
84
|
+
* Both startTime & endTime entered together or both are left blank
|
|
85
|
+
*/
|
|
86
|
+
getHistoricalVolatility(
|
|
87
|
+
params?: USDCOptionsHistoricalVolatilityRequest
|
|
88
|
+
): Promise<APIResponseV3<any>> {
|
|
89
|
+
return this.get(
|
|
90
|
+
'/option/usdc/openapi/public/v1/query-historical-volatility',
|
|
91
|
+
params
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* Account Data Endpoints
|
|
98
|
+
*
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
/** -> Order API */
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Place an order using the USDC Derivatives Account.
|
|
105
|
+
* The request status can be queried in real-time.
|
|
106
|
+
* The response parameters must be queried through a query or a WebSocket response.
|
|
107
|
+
*/
|
|
108
|
+
submitOrder(params: USDCOptionsOrderRequest): Promise<APIResponseV3<any>> {
|
|
109
|
+
return this.postPrivate(
|
|
110
|
+
'/option/usdc/openapi/private/v1/place-order',
|
|
111
|
+
params
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Each request supports a max. of four orders. The reduceOnly parameter should be separate and unique for each order in the request.
|
|
117
|
+
*/
|
|
118
|
+
batchSubmitOrders(
|
|
119
|
+
orderRequest: USDCOptionsOrderRequest[]
|
|
120
|
+
): Promise<APIResponseV3<any>> {
|
|
121
|
+
return this.postPrivate(
|
|
122
|
+
'/option/usdc/openapi/private/v1/batch-place-orders',
|
|
123
|
+
{ orderRequest }
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** For Options, at least one of the three parameters — price, quantity or implied volatility — must be input. */
|
|
128
|
+
modifyOrder(
|
|
129
|
+
params: USDCOptionsModifyOrderRequest
|
|
130
|
+
): Promise<APIResponseV3<any>> {
|
|
131
|
+
return this.postPrivate(
|
|
132
|
+
'/option/usdc/openapi/private/v1/replace-order',
|
|
133
|
+
params
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Each request supports a max. of four orders. The reduceOnly parameter should be separate and unique for each order in the request. */
|
|
138
|
+
batchModifyOrders(
|
|
139
|
+
replaceOrderRequest: USDCOptionsModifyOrderRequest[]
|
|
140
|
+
): Promise<APIResponseV3<any>> {
|
|
141
|
+
return this.postPrivate(
|
|
142
|
+
'/option/usdc/openapi/private/v1/batch-replace-orders',
|
|
143
|
+
{ replaceOrderRequest }
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Cancel order */
|
|
148
|
+
cancelOrder(
|
|
149
|
+
params: USDCOptionsCancelOrderRequest
|
|
150
|
+
): Promise<APIResponseV3<any>> {
|
|
151
|
+
return this.postPrivate(
|
|
152
|
+
'/option/usdc/openapi/private/v1/cancel-order',
|
|
153
|
+
params
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Batch cancel orders */
|
|
158
|
+
batchCancelOrders(
|
|
159
|
+
cancelRequest: USDCOptionsCancelOrderRequest[]
|
|
160
|
+
): Promise<APIResponseV3<any>> {
|
|
161
|
+
return this.postPrivate(
|
|
162
|
+
'/option/usdc/openapi/private/v1/batch-cancel-orders',
|
|
163
|
+
{ cancelRequest }
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** This is used to cancel all active orders. The real-time response indicates whether the request is successful, depending on retCode. */
|
|
168
|
+
cancelActiveOrders(
|
|
169
|
+
params?: USDCOptionsCancelAllOrdersRequest
|
|
170
|
+
): Promise<APIResponseV3<any>> {
|
|
171
|
+
return this.postPrivate(
|
|
172
|
+
'/option/usdc/openapi/private/v1/cancel-all',
|
|
173
|
+
params
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Query Unfilled/Partially Filled Orders(real-time), up to last 7 days of partially filled/unfilled orders */
|
|
178
|
+
getActiveRealtimeOrders(
|
|
179
|
+
params?: USDCOptionsActiveOrdersRealtimeRequest
|
|
180
|
+
): Promise<APIResponseV3<any>> {
|
|
181
|
+
return this.getPrivate(
|
|
182
|
+
'/option/usdc/openapi/private/v1/trade/query-active-orders',
|
|
183
|
+
params
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Query Unfilled/Partially Filled Orders */
|
|
188
|
+
getActiveOrders(
|
|
189
|
+
params: USDCOptionsActiveOrdersRequest
|
|
190
|
+
): Promise<APIResponseV3<any>> {
|
|
191
|
+
return this.postPrivate(
|
|
192
|
+
'/option/usdc/openapi/private/v1/query-active-orders',
|
|
193
|
+
params
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Query order history. The endpoint only supports up to 30 days of queried records */
|
|
198
|
+
getHistoricOrders(
|
|
199
|
+
params: USDCOptionsHistoricOrdersRequest
|
|
200
|
+
): Promise<APIResponseV3<any>> {
|
|
201
|
+
return this.postPrivate(
|
|
202
|
+
'/option/usdc/openapi/private/v1/query-order-history',
|
|
203
|
+
params
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Query trade history.
|
|
209
|
+
* The endpoint only supports up to 30 days of queried records.
|
|
210
|
+
* An error will be returned if startTime is more than 30 days.
|
|
211
|
+
*/
|
|
212
|
+
getOrderExecutionHistory(
|
|
213
|
+
params: USDCOptionsOrderExecutionRequest
|
|
214
|
+
): Promise<APIResponseV3<any>> {
|
|
215
|
+
return this.postPrivate(
|
|
216
|
+
'/option/usdc/openapi/private/v1/execution-list',
|
|
217
|
+
params
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** -> Account API */
|
|
222
|
+
|
|
223
|
+
/** The endpoint only supports up to 30 days of queried records. An error will be returned if startTime is more than 30 days. */
|
|
224
|
+
getTransactionLog(
|
|
225
|
+
params: USDCTransactionLogRequest
|
|
226
|
+
): Promise<APIResponseV3<any>> {
|
|
227
|
+
return this.postPrivate(
|
|
228
|
+
'/option/usdc/openapi/private/v1/query-transaction-log',
|
|
229
|
+
params
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Wallet info for USDC account. */
|
|
234
|
+
getBalances(): Promise<APIResponseV3<any>> {
|
|
235
|
+
return this.postPrivate(
|
|
236
|
+
'/option/usdc/openapi/private/v1/query-wallet-balance'
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Asset Info */
|
|
241
|
+
getAssetInfo(baseCoin?: string): Promise<APIResponseV3<any>> {
|
|
242
|
+
return this.postPrivate(
|
|
243
|
+
'/option/usdc/openapi/private/v1/query-asset-info',
|
|
244
|
+
{ baseCoin }
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* If USDC derivatives account balance is greater than X, you can open PORTFOLIO_MARGIN,
|
|
250
|
+
* and if it is less than Y, it will automatically close PORTFOLIO_MARGIN and change back to REGULAR_MARGIN.
|
|
251
|
+
* X and Y will be adjusted according to operational requirements.
|
|
252
|
+
* Rest API returns the result of checking prerequisites. You could get the real status of margin mode change by subscribing margin mode.
|
|
253
|
+
*/
|
|
254
|
+
setMarginMode(
|
|
255
|
+
newMarginMode: 'REGULAR_MARGIN' | 'PORTFOLIO_MARGIN'
|
|
256
|
+
): Promise<APIResponseV3<any>> {
|
|
257
|
+
return this.postPrivate(
|
|
258
|
+
'/option/usdc/private/asset/account/setMarginMode',
|
|
259
|
+
{ setMarginMode: newMarginMode }
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Query margin mode for USDC account. */
|
|
264
|
+
getMarginMode(): Promise<APIResponseV3<any>> {
|
|
265
|
+
return this.postPrivate(
|
|
266
|
+
'/option/usdc/openapi/private/v1/query-margin-info'
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** -> Positions API */
|
|
271
|
+
|
|
272
|
+
/** Query my positions */
|
|
273
|
+
getPositions(params: USDCPositionsRequest): Promise<APIResponseV3<any>> {
|
|
274
|
+
return this.postPrivate(
|
|
275
|
+
'/option/usdc/openapi/private/v1/query-position',
|
|
276
|
+
params
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Query Delivery History */
|
|
281
|
+
getDeliveryHistory(
|
|
282
|
+
params: USDCOptionsDeliveryHistoryRequest
|
|
283
|
+
): Promise<APIResponseV3<any>> {
|
|
284
|
+
return this.postPrivate(
|
|
285
|
+
'/option/usdc/openapi/private/v1/query-delivery-list',
|
|
286
|
+
params
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Query Positions Info Upon Expiry */
|
|
291
|
+
getPositionsInfoUponExpiry(
|
|
292
|
+
params?: USDCOptionsPositionsInfoExpiryRequest
|
|
293
|
+
): Promise<APIResponseV3<any>> {
|
|
294
|
+
return this.postPrivate(
|
|
295
|
+
'/option/usdc/openapi/private/v1/query-position-exp-date',
|
|
296
|
+
params
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** -> Market Maker Protection */
|
|
301
|
+
|
|
302
|
+
/** modifyMMP */
|
|
303
|
+
modifyMMP(params: USDCOptionsModifyMMPRequest): Promise<APIResponseV3<any>> {
|
|
304
|
+
return this.postPrivate(
|
|
305
|
+
'/option/usdc/openapi/private/v1/mmp-modify',
|
|
306
|
+
params
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** resetMMP */
|
|
311
|
+
resetMMP(currency: string): Promise<APIResponseV3<any>> {
|
|
312
|
+
return this.postPrivate('/option/usdc/openapi/private/v1/mmp-reset', {
|
|
313
|
+
currency,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** queryMMPState */
|
|
318
|
+
queryMMPState(baseCoin: string): Promise<APIResponseV3<any>> {
|
|
319
|
+
return this.postPrivate('/option/usdc/openapi/private/v1/get-mmp-state', {
|
|
320
|
+
baseCoin,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
*
|
|
326
|
+
* API Data Endpoints
|
|
327
|
+
*
|
|
328
|
+
*/
|
|
329
|
+
|
|
330
|
+
getServerTime(): Promise<APIResponseWithTime> {
|
|
331
|
+
return this.get('/v2/public/time');
|
|
332
|
+
}
|
|
333
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import {
|
|
3
|
+
APIResponseV3,
|
|
4
|
+
APIResponseWithTime,
|
|
5
|
+
SymbolLimitParam,
|
|
6
|
+
SymbolPeriodLimitParam,
|
|
7
|
+
USDCKlineRequest,
|
|
8
|
+
USDCLast500TradesRequest,
|
|
9
|
+
USDCOpenInterestRequest,
|
|
10
|
+
USDCOrderFilter,
|
|
11
|
+
USDCPerpActiveOrdersRequest,
|
|
12
|
+
USDCPerpCancelOrderRequest,
|
|
13
|
+
USDCPerpHistoricOrdersRequest,
|
|
14
|
+
USDCPerpModifyOrderRequest,
|
|
15
|
+
USDCPerpOrderRequest,
|
|
16
|
+
USDCPositionsRequest,
|
|
17
|
+
USDCSymbolDirectionLimit,
|
|
18
|
+
USDCSymbolDirectionLimitCursor,
|
|
19
|
+
USDCTransactionLogRequest,
|
|
20
|
+
} from './types';
|
|
21
|
+
import { REST_CLIENT_TYPE_ENUM } from './util';
|
|
22
|
+
import BaseRestClient from './util/BaseRestClient';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* REST API client for USDC Perpetual APIs
|
|
26
|
+
*/
|
|
27
|
+
export class USDCPerpetualClient extends BaseRestClient {
|
|
28
|
+
getClientType() {
|
|
29
|
+
// Follows the same authentication mechanism as other v3 APIs (e.g. USDC)
|
|
30
|
+
return REST_CLIENT_TYPE_ENUM.v3;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async fetchServerTime(): Promise<number> {
|
|
34
|
+
const res = await this.getServerTime();
|
|
35
|
+
return Number(res.time_now);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* Market Data Endpoints
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
getOrderBook(symbol: string): Promise<APIResponseV3<any>> {
|
|
45
|
+
return this.get('/perpetual/usdc/openapi/public/v1/order-book', { symbol });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Fetch trading rules (such as min/max qty). Query for all if blank. */
|
|
49
|
+
getContractInfo(
|
|
50
|
+
params?: USDCSymbolDirectionLimit
|
|
51
|
+
): Promise<APIResponseV3<any>> {
|
|
52
|
+
return this.get('/perpetual/usdc/openapi/public/v1/symbols', params);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Get a symbol price/statistics ticker */
|
|
56
|
+
getSymbolTicker(symbol: string): Promise<APIResponseV3<any>> {
|
|
57
|
+
return this.get('/perpetual/usdc/openapi/public/v1/tick', { symbol });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getCandles(params: USDCKlineRequest): Promise<APIResponseV3<any>> {
|
|
61
|
+
return this.get('/perpetual/usdc/openapi/public/v1/kline/list', params);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getMarkPrice(params: USDCKlineRequest): Promise<APIResponseV3<any>> {
|
|
65
|
+
return this.get(
|
|
66
|
+
'/perpetual/usdc/openapi/public/v1/mark-price-kline',
|
|
67
|
+
params
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getIndexPrice(params: USDCKlineRequest): Promise<APIResponseV3<any>> {
|
|
72
|
+
return this.get(
|
|
73
|
+
'/perpetual/usdc/openapi/public/v1/index-price-kline',
|
|
74
|
+
params
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getIndexPremium(params: USDCKlineRequest): Promise<APIResponseV3<any>> {
|
|
79
|
+
return this.get(
|
|
80
|
+
'/perpetual/usdc/openapi/public/v1/premium-index-kline',
|
|
81
|
+
params
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getOpenInterest(
|
|
86
|
+
params: USDCOpenInterestRequest
|
|
87
|
+
): Promise<APIResponseV3<any>> {
|
|
88
|
+
return this.get('/perpetual/usdc/openapi/public/v1/open-interest', params);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getLargeOrders(
|
|
92
|
+
params: SymbolLimitParam<string>
|
|
93
|
+
): Promise<APIResponseV3<any>> {
|
|
94
|
+
return this.get('/perpetual/usdc/openapi/public/v1/big-deal', params);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getLongShortRatio(
|
|
98
|
+
params: SymbolPeriodLimitParam<string>
|
|
99
|
+
): Promise<APIResponseV3<any>> {
|
|
100
|
+
return this.get('/perpetual/usdc/openapi/public/v1/account-ratio', params);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getLast500Trades(
|
|
104
|
+
params: USDCLast500TradesRequest
|
|
105
|
+
): Promise<APIResponseV3<any>> {
|
|
106
|
+
return this.get(
|
|
107
|
+
'/option/usdc/openapi/public/v1/query-trade-latest',
|
|
108
|
+
params
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
*
|
|
114
|
+
* Account Data Endpoints
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
/** -> Order API */
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Place an order using the USDC Derivatives Account.
|
|
122
|
+
* The request status can be queried in real-time.
|
|
123
|
+
* The response parameters must be queried through a query or a WebSocket response.
|
|
124
|
+
*/
|
|
125
|
+
submitOrder(params: USDCPerpOrderRequest): Promise<APIResponseV3<any>> {
|
|
126
|
+
return this.postPrivate(
|
|
127
|
+
'/perpetual/usdc/openapi/private/v1/place-order',
|
|
128
|
+
params
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Active order parameters (such as quantity, price) and stop order parameters cannot be modified in one request at the same time. Please request modification separately. */
|
|
133
|
+
modifyOrder(params: USDCPerpModifyOrderRequest): Promise<APIResponseV3<any>> {
|
|
134
|
+
return this.postPrivate(
|
|
135
|
+
'/perpetual/usdc/openapi/private/v1/replace-order',
|
|
136
|
+
params
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Cancel order */
|
|
141
|
+
cancelOrder(params: USDCPerpCancelOrderRequest): Promise<APIResponseV3<any>> {
|
|
142
|
+
return this.postPrivate(
|
|
143
|
+
'/perpetual/usdc/openapi/private/v1/cancel-order',
|
|
144
|
+
params
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Cancel all active orders. The real-time response indicates whether the request is successful, depending on retCode. */
|
|
149
|
+
cancelActiveOrders(
|
|
150
|
+
symbol: string,
|
|
151
|
+
orderFilter: USDCOrderFilter
|
|
152
|
+
): Promise<APIResponseV3<any>> {
|
|
153
|
+
return this.postPrivate('/perpetual/usdc/openapi/private/v1/cancel-all', {
|
|
154
|
+
symbol,
|
|
155
|
+
orderFilter,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Query Unfilled/Partially Filled Orders */
|
|
160
|
+
getActiveOrders(
|
|
161
|
+
params: USDCPerpActiveOrdersRequest
|
|
162
|
+
): Promise<APIResponseV3<any>> {
|
|
163
|
+
return this.postPrivate(
|
|
164
|
+
'/option/usdc/openapi/private/v1/query-active-orders',
|
|
165
|
+
params
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Query order history. The endpoint only supports up to 30 days of queried records */
|
|
170
|
+
getHistoricOrders(
|
|
171
|
+
params: USDCPerpHistoricOrdersRequest
|
|
172
|
+
): Promise<APIResponseV3<any>> {
|
|
173
|
+
return this.postPrivate(
|
|
174
|
+
'/option/usdc/openapi/private/v1/query-order-history',
|
|
175
|
+
params
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Query trade history. The endpoint only supports up to 30 days of queried records. An error will be returned if startTime is more than 30 days. */
|
|
180
|
+
getOrderExecutionHistory(
|
|
181
|
+
params: USDCPerpActiveOrdersRequest
|
|
182
|
+
): Promise<APIResponseV3<any>> {
|
|
183
|
+
return this.postPrivate(
|
|
184
|
+
'/option/usdc/openapi/private/v1/execution-list',
|
|
185
|
+
params
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** -> Account API */
|
|
190
|
+
|
|
191
|
+
/** The endpoint only supports up to 30 days of queried records. An error will be returned if startTime is more than 30 days. */
|
|
192
|
+
getTransactionLog(
|
|
193
|
+
params: USDCTransactionLogRequest
|
|
194
|
+
): Promise<APIResponseV3<any>> {
|
|
195
|
+
return this.postPrivate(
|
|
196
|
+
'/option/usdc/openapi/private/v1/query-transaction-log',
|
|
197
|
+
params
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Wallet info for USDC account. */
|
|
202
|
+
getBalances(): Promise<APIResponseV3<any>> {
|
|
203
|
+
return this.postPrivate(
|
|
204
|
+
'/option/usdc/openapi/private/v1/query-wallet-balance'
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Asset Info */
|
|
209
|
+
getAssetInfo(baseCoin?: string): Promise<APIResponseV3<any>> {
|
|
210
|
+
return this.postPrivate(
|
|
211
|
+
'/option/usdc/openapi/private/v1/query-asset-info',
|
|
212
|
+
{ baseCoin }
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* If USDC derivatives account balance is greater than X, you can open PORTFOLIO_MARGIN,
|
|
218
|
+
* and if it is less than Y, it will automatically close PORTFOLIO_MARGIN and change back to REGULAR_MARGIN.
|
|
219
|
+
* X and Y will be adjusted according to operational requirements.
|
|
220
|
+
* Rest API returns the result of checking prerequisites. You could get the real status of margin mode change by subscribing margin mode.
|
|
221
|
+
*/
|
|
222
|
+
setMarginMode(
|
|
223
|
+
newMarginMode: 'REGULAR_MARGIN' | 'PORTFOLIO_MARGIN'
|
|
224
|
+
): Promise<APIResponseV3<any>> {
|
|
225
|
+
return this.postPrivate(
|
|
226
|
+
'/option/usdc/private/asset/account/setMarginMode',
|
|
227
|
+
{ setMarginMode: newMarginMode }
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Query margin mode for USDC account. */
|
|
232
|
+
getMarginMode(): Promise<APIResponseV3<any>> {
|
|
233
|
+
return this.postPrivate(
|
|
234
|
+
'/option/usdc/openapi/private/v1/query-margin-info'
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** -> Positions API */
|
|
239
|
+
|
|
240
|
+
/** Query my positions */
|
|
241
|
+
getPositions(params: USDCPositionsRequest): Promise<APIResponseV3<any>> {
|
|
242
|
+
return this.postPrivate(
|
|
243
|
+
'/option/usdc/openapi/private/v1/query-position',
|
|
244
|
+
params
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Only for REGULAR_MARGIN */
|
|
249
|
+
setLeverage(symbol: string, leverage: string): Promise<APIResponseV3<any>> {
|
|
250
|
+
return this.postPrivate(
|
|
251
|
+
'/perpetual/usdc/openapi/private/v1/position/leverage/save',
|
|
252
|
+
{ symbol, leverage }
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Query Settlement History */
|
|
257
|
+
getSettlementHistory(
|
|
258
|
+
params?: USDCSymbolDirectionLimitCursor
|
|
259
|
+
): Promise<APIResponseV3<any>> {
|
|
260
|
+
return this.postPrivate(
|
|
261
|
+
'/option/usdc/openapi/private/v1/session-settlement',
|
|
262
|
+
params
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** -> Risk Limit API */
|
|
267
|
+
|
|
268
|
+
/** Query risk limit */
|
|
269
|
+
getRiskLimit(symbol: string): Promise<APIResponseV3<any>> {
|
|
270
|
+
return this.getPrivate(
|
|
271
|
+
'/perpetual/usdc/openapi/public/v1/risk-limit/list',
|
|
272
|
+
{
|
|
273
|
+
symbol,
|
|
274
|
+
}
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Set risk limit */
|
|
279
|
+
setRiskLimit(symbol: string, riskId: number): Promise<APIResponseV3<any>> {
|
|
280
|
+
return this.postPrivate(
|
|
281
|
+
'/perpetual/usdc/openapi/private/v1/position/set-risk-limit',
|
|
282
|
+
{ symbol, riskId }
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** -> Funding API */
|
|
287
|
+
|
|
288
|
+
/** Funding settlement occurs every 8 hours at 00:00 UTC, 08:00 UTC and 16:00 UTC. The current interval's fund fee settlement is based on the previous interval's fund rate. For example, at 16:00, the settlement is based on the fund rate generated at 8:00. The fund rate generated at 16:00 will be used at 0:00 the next day. */
|
|
289
|
+
getLastFundingRate(symbol: string): Promise<APIResponseV3<any>> {
|
|
290
|
+
return this.get('/perpetual/usdc/openapi/public/v1/prev-funding-rate', {
|
|
291
|
+
symbol,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** Get predicted funding rate and my predicted funding fee */
|
|
296
|
+
getPredictedFundingRate(symbol: string): Promise<APIResponseV3<any>> {
|
|
297
|
+
return this.postPrivate(
|
|
298
|
+
'/perpetual/usdc/openapi/private/v1/predicted-funding',
|
|
299
|
+
{ symbol }
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
*
|
|
305
|
+
* API Data Endpoints
|
|
306
|
+
*
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
getServerTime(): Promise<APIResponseWithTime> {
|
|
310
|
+
return this.get('/v2/public/time');
|
|
311
|
+
}
|
|
312
|
+
}
|