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