-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
spot-client.ts
439 lines (390 loc) · 11 KB
/
spot-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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
import {
APIResponse,
BatchCancelSpotOrderV2,
CancelSpotOrderV2,
CancelSpotPlanOrderParams,
CoinBalance,
GetHistoricPlanOrdersParams,
GetHistoricTradesParams,
GetSpotPlanOrdersParams,
ModifySpotPlanOrder,
NewBatchSpotOrder,
NewSpotOrder,
NewSpotPlanOrder,
NewSpotSubTransfer,
NewSpotWithdraw,
NewWalletTransfer,
Pagination,
SpotCandleData,
SpotKlineInterval,
SpotMarketTrade,
SpotOrderResult,
SpotPlanOrder,
SymbolRules,
VIPFeeRate,
} from './types';
import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient';
/**
* REST API client for the V1 bitget Spot APIs. These are the previous generation of Bitget's APIs and should be considered deprecated.
* These will be removed in a future release, once Bitget formally deprecates them.
*
* @deprecated use RestClientV2 instead
*/
export class SpotClient extends BaseRestClient {
getClientType() {
return REST_CLIENT_TYPE_ENUM.spot;
}
async fetchServerTime(): Promise<number> {
const res = await this.getServerTime();
return Number(res.data);
}
/**
*
* Public
*
*/
/** Get Server Time */
getServerTime(): Promise<APIResponse<string>> {
return this.get('/api/spot/v1/public/time');
}
/** Get Coin List : Get all coins information on the platform */
getCoins(): Promise<APIResponse<any[]>> {
return this.get('/api/spot/v1/public/currencies');
}
/** Get Symbols : Get basic configuration information of all trading pairs (including rules) */
getSymbols(): Promise<APIResponse<SymbolRules[]>> {
return this.get('/api/spot/v1/public/products');
}
/** Get Single Symbol : Get basic configuration information for one symbol */
getSymbol(symbol: string): Promise<APIResponse<any>> {
return this.get('/api/spot/v1/public/product', { symbol });
}
/**
*
* Market
*
*/
/** Get Single Ticker */
getTicker(symbol: string): Promise<APIResponse<any>> {
return this.get('/api/spot/v1/market/ticker', { symbol });
}
/** Get All Tickers */
getAllTickers(): Promise<APIResponse<any>> {
return this.get('/api/spot/v1/market/tickers');
}
/** Get most recent trades (up to 500, 100 by default) */
getRecentTrades(
symbol: string,
limit?: string,
): Promise<APIResponse<SpotMarketTrade[]>> {
return this.get('/api/spot/v1/market/fills', { symbol, limit });
}
/** Get historic trades, up to 30 days at a time. Same-parameter responses are cached for 10 minutes. */
getHistoricTrades(
params: GetHistoricTradesParams,
): Promise<APIResponse<SpotMarketTrade[]>> {
return this.get('/api/spot/v1/market/fills-history', params);
}
/**
* @deprecated use getRecentTrades() instead. This method will be removed soon.
*/
getMarketTrades(
symbol: string,
limit?: string,
): Promise<APIResponse<SpotMarketTrade[]>> {
return this.get('/api/spot/v1/market/fills', { symbol, limit });
}
/** Get Candle Data */
getCandles(
symbol: string,
period: SpotKlineInterval,
pagination?: Pagination,
): Promise<APIResponse<SpotCandleData[]>> {
return this.get('/api/spot/v1/market/candles', {
symbol,
period,
...pagination,
});
}
/** Get Depth */
getDepth(
symbol: string,
type: 'step0' | 'step1' | 'step2' | 'step3' | 'step4' | 'step5',
limit?: string,
): Promise<APIResponse<any>> {
return this.get('/api/spot/v1/market/depth', { symbol, type, limit });
}
/** Get VIP fee rates */
getVIPFeeRates(): Promise<APIResponse<VIPFeeRate[]>> {
return this.get('/api/spot/v1/market/spot-vip-level');
}
/**
*
* Wallet Endpoints
*
*/
/** Initiate wallet transfer */
transfer(params: NewWalletTransfer): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/wallet/transfer', params);
}
/** Initiate wallet transfer (v2 endpoint) */
transferV2(params: NewWalletTransfer): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/wallet/transfer-v2', params);
}
/**
* Transfer main-sub, sub-sub or sub-main
*/
subTransfer(params: NewSpotSubTransfer): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/wallet/subTransfer', params);
}
/** Get Coin Address */
getDepositAddress(coin: string, chain?: string): Promise<APIResponse<any>> {
return this.getPrivate('/api/spot/v1/wallet/deposit-address', {
coin,
chain,
});
}
/** Withdraw Coins On Chain */
withdraw(params: NewSpotWithdraw): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/wallet/withdrawal', params);
}
/** Withdraw Coins On Chain (v2 endpoint) */
withdrawV2(params: NewSpotWithdraw): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/wallet/withdrawal-v2', params);
}
/** Inner Withdraw : Internal withdrawal means that both users are on the Bitget platform */
innerWithdraw(
coin: string,
toUid: string,
amount: string,
clientOid?: string,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/wallet/withdrawal-inner', {
coin,
toUid,
amount,
clientOid,
});
}
/** Inner Withdraw (v2 endpoint) : Internal withdrawal means that both users are on the Bitget platform */
innerWithdrawV2(
coin: string,
toUid: string,
amount: string,
clientOid?: string,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/wallet/withdrawal-inner-v2', {
coin,
toUid,
amount,
clientOid,
});
}
/** Get Withdraw List */
getWithdrawals(
coin: string,
startTime: string,
endTime: string,
pageSize?: string,
pageNo?: string,
clientOid?: string,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/spot/v1/wallet/withdrawal-list', {
coin,
startTime,
endTime,
pageSize,
pageNo,
clientOid,
});
}
/** Get Deposit List */
getDeposits(
coin: string,
startTime: string,
endTime: string,
pageSize?: string,
pageNo?: string,
): Promise<APIResponse<any>> {
return this.getPrivate('/api/spot/v1/wallet/deposit-list', {
coin,
startTime,
endTime,
pageSize,
pageNo,
});
}
/**
*
* Account Endpoints
*
*/
/** Get ApiKey Info */
getApiKeyInfo(): Promise<APIResponse<any>> {
return this.getPrivate('/api/spot/v1/account/getInfo');
}
/** Get Account : get account assets */
getBalance(coin?: string): Promise<APIResponse<CoinBalance[]>> {
return this.getPrivate('/api/spot/v1/account/assets', { coin });
}
/** Get sub Account Spot Asset */
getSubAccountSpotAssets(): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/account/sub-account-spot-assets');
}
/** Get Bills : get transaction detail flow */
getTransactionHistory(params?: {
coinId?: number;
groupType?: string;
bizType?: string;
after?: string;
before?: string;
limit?: number;
}): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/account/bills', params);
}
/** Get Transfer List */
getTransferHistory(params?: {
coinId?: number;
fromType?: string;
after?: string;
before?: string;
limit?: number;
clientOid?: string;
}): Promise<APIResponse<any>> {
return this.getPrivate('/api/spot/v1/account/transferRecords', params);
}
/**
*
* Trade Endpoints
*
*/
/** Place order */
submitOrder(params: NewSpotOrder): Promise<APIResponse<SpotOrderResult>> {
return this.postPrivate('/api/spot/v1/trade/orders', params);
}
/** Place orders in batches, up to 50 at a time */
batchSubmitOrder(
symbol: string,
orderList: NewBatchSpotOrder[],
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/batch-orders', {
symbol,
orderList,
});
}
/** Cancel order */
cancelOrder(symbol: string, orderId: string): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/cancel-order', {
symbol,
orderId,
});
}
/** Cancel order (v2 endpoint - supports orderId or clientOid) */
cancelOrderV2(params?: CancelSpotOrderV2): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/cancel-order-v2', params);
}
/**
* Cancel all spot orders for a symbol
*/
cancelSymbolOrders(symbol: string): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/cancel-symbol-order', {
symbol,
});
}
/** Cancel order in batch (per symbol) */
batchCancelOrder(
symbol: string,
orderIds: string[],
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/cancel-batch-orders', {
symbol,
orderIds,
});
}
/** Cancel order in batch (per symbol). V2 endpoint, supports orderIds or clientOids. */
batchCancelOrderV2(
params: BatchCancelSpotOrderV2,
): Promise<APIResponse<any>> {
return this.postPrivate(
'/api/spot/v1/trade/cancel-batch-orders-v2',
params,
);
}
/** Get order details */
getOrder(
symbol: string,
orderId: string,
clientOrderId?: string,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/orderInfo', {
symbol,
orderId,
clientOrderId,
});
}
/** Get order list (open orders) */
getOpenOrders(symbol?: string): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/open-orders', { symbol });
}
/** Get order history for a symbol */
getOrderHistory(
symbol: string,
pagination?: Pagination,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/history', {
symbol,
...pagination,
});
}
/** Get transaction details / history (fills) for an order */
getOrderFills(
symbol: string,
orderId: string,
pagination?: Pagination,
): Promise<APIResponse<any>> {
return this.postPrivate('/api/spot/v1/trade/fills', {
symbol,
orderId,
...pagination,
});
}
/** Place plan order */
submitPlanOrder(
params: NewSpotPlanOrder,
): Promise<APIResponse<SpotOrderResult>> {
return this.postPrivate('/api/spot/v1/plan/placePlan', params);
}
/** Modify plan order */
modifyPlanOrder(
params: ModifySpotPlanOrder,
): Promise<APIResponse<SpotOrderResult>> {
return this.postPrivate('/api/spot/v1/plan/modifyPlan', params);
}
/** Cancel plan order */
cancelPlanOrder(
params: CancelSpotPlanOrderParams,
): Promise<APIResponse<string>> {
return this.postPrivate('/api/spot/v1/plan/cancelPlan', params);
}
/** Get current plan orders */
getCurrentPlanOrders(params: GetSpotPlanOrdersParams): Promise<
APIResponse<{
nextFlag: boolean;
endId: number;
orderList: SpotPlanOrder[];
}>
> {
return this.postPrivate('/api/spot/v1/plan/currentPlan', params);
}
/** Get history plan orders */
getHistoricPlanOrders(params: GetHistoricPlanOrdersParams): Promise<
APIResponse<{
nextFlag: boolean;
endId: number;
orderList: SpotPlanOrder[];
}>
> {
return this.postPrivate('/api/spot/v1/plan/historyPlan', params);
}
}