-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpotClient.ts
More file actions
1565 lines (1437 loc) · 44.2 KB
/
Copy pathSpotClient.ts
File metadata and controls
1565 lines (1437 loc) · 44.2 KB
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { BaseRestClient } from './lib/BaseRestClient.js';
import {
generateNewOrderID,
getOrderIdPrefix,
logInvalidOrderId,
REST_CLIENT_TYPE_ENUM,
RestClientType,
} from './lib/requestUtils.js';
import type {
SpotAccountTransferReq,
SpotBrokerAccountCapitalSnapshotReq,
SpotBrokerSubUserFeeRateAddReq,
SpotCrossMarginLoanOrdersReq,
SpotDepositWithdrawQueryReq,
SpotEarnProjectListReq,
SpotEarnRedeemReq,
SpotEarnSubscribeReq,
SpotEarnUserAssetsReq,
SpotGetAccountHistoryReq,
SpotGetAccountLedgerReq,
SpotGetAssetValuationReq,
SpotGetChainsReq,
SpotGetDepthReq,
SpotGetKlineReq,
SpotGetMatchResultsReq,
SpotGetOpenOrdersReq,
SpotGetOrderHistory48hReq,
SpotGetOrderHistoryReq,
SpotMarginLoanOrderReq,
SpotMarginLoanOrdersReq,
SpotMarginRepaymentReq,
SpotMarginTransferInIsolatedReq,
SpotMarginTransferOutIsolatedReq,
SpotP2POrderHistoryReq,
SpotReferralAllRebateDetailReq,
SpotReferralRebateHistoryReq,
SpotReferralReferralsReq,
SpotRepaymentRecordReq,
SpotSubUserApiKeyCreationReq,
SpotSubUserApiKeyUpdateReq,
SpotSubUserDepositHistoryReq,
SpotSubUserManagedTransferHistoryReq,
SpotSubUserTradableMarketReq,
SpotSubUserTransferPermissionsReq,
SpotSubUserTransferReq,
SpotV1FuturesTransferReq,
SpotV1OrderAutoPlaceReq,
SpotV1OrderBatchCancelOpenOrdersReq,
SpotV1OrderPlaceReq,
SpotV2AccountTransferReq,
SpotV2AlgoOrdersHistoryReq,
SpotV2AlgoOrdersOpeningReq,
SpotV2AlgoOrdersPlaceReq,
SpotV2PointTransferReq,
SpotWithdrawAddressReq,
SpotWithdrawCreateReq,
} from './types/request/spot.types.js';
import {
SpotAPISuccessResponse,
SpotOrderIdProperty,
} from './types/response/shared.types.js';
import {
SpotAccount,
SpotAccountBalance,
SpotAccountHistory,
SpotAccountTransferResult,
SpotBrokerAccountCapitalSnapshot,
SpotBrokerFeeRateAddResult,
SpotBrokerSubUserFeeRate,
SpotBrokerUserRebateStatus,
SpotCrossMarginAccountBalance,
SpotCrossMarginLoanOrder,
SpotCurrency,
SpotDepositAddress,
SpotDepositWithdrawRecord,
SpotDepth,
SpotDetailTick,
SpotEarnProject,
SpotEarnRedeemResult,
SpotEarnSubscribeResult,
SpotEarnUserAsset,
SpotKline,
SpotLastTrade,
SpotMarginAccountBalance,
SpotMarginLimit,
SpotMarginLoanInfo,
SpotMarginLoanInfoCurrency,
SpotMarginLoanOrder,
SpotMarginRepaymentResult,
SpotMarketStatusResponse,
SpotMergedTicker,
SpotP2POrderHistory,
SpotReferralAllRebateDetail,
SpotReferralRebateDetail,
SpotReferralRebateHistoryRecord,
SpotReferralReferral,
SpotRepaymentRecord,
SpotSubUserAccountsResult,
SpotSubUserApiKey,
SpotSubUserApiKeyCreationResult,
SpotSubUserApiKeyUpdateResult,
SpotSubUserBalanceResult,
SpotSubUserCreationResult,
SpotSubUserDeductModeResult,
SpotSubUserDepositHistoryRecord,
SpotSubUserEntrustUser,
SpotSubUserList,
SpotSubUserLockStatusResult,
SpotSubUserManagedTransferRecord,
SpotSubUsersAggregatedBalance,
SpotSubUserStatusResult,
SpotSubUserTradableMarketResult,
SpotSubUserTransferPermissionsResult,
SpotTicker,
SpotTradeTimestampGroup,
SpotTradingSymbol,
SpotV1AccountOverviewInfo,
SpotV1AccountSwitchUserInfo,
SpotV1ChainInfo,
SpotV1CurrencySettings,
SpotV1MarketSymbolSettings,
SpotV1OpenOrder,
SpotV1OrderAutoPlaceResult,
SpotV1OrderBatchCancelOpenOrdersResult,
SpotV1OrderBatchCancelResult,
SpotV1OrderBatchPlaceResult,
SpotV1OrderCancelByClientOrderIdResult,
SpotV1OrderCancelResult,
SpotV1OrderDetail,
SpotV1OrderHistory,
SpotV1OrderHistory48h,
SpotV1OrderMatchResult,
SpotV1SymbolSettings,
SpotV2AccountLedger,
SpotV2AccountValuation,
SpotV2AlgoOrder,
SpotV2AlgoOrdersCancelAllAfterResult,
SpotV2AlgoOrdersCancellationResult,
SpotV2AlgoOrdersPlaceResult,
SpotV2AssetValuation,
SpotV2CurrencyReference,
SpotV2PointAccount,
SpotV2PointTransfer,
SpotV2TransactFeeRate,
SpotVaspExchange,
SpotWithdrawAddress,
SpotWithdrawQuota,
} from './types/response/spot.types.js';
/**
* The SpotClient provides integration to the HTX Spot API.
*/
export class SpotClient extends BaseRestClient {
getClientType(): RestClientType {
// Favour the spot AWS domain, as recommended by the API docs
return REST_CLIENT_TYPE_ENUM.spotAWS;
}
/**
*
* Misc Utility Methods
*
*/
generateNewOrderID(): string {
return generateNewOrderID();
}
/**
*
* Reference Data
*
*/
/**
* Get Market Status
*
* Returns current market status.
* 1=normal, 2=halted, 3=cancel-only.
*/
getMarketStatus(): Promise<SpotMarketStatusResponse> {
return this.get('/v2/market-status');
}
/**
* Get Current Timestamp (V1)
*
* Returns current server time in milliseconds since epoch. No signature required.
*/
getTimestamp(): Promise<SpotAPISuccessResponse<number>> {
return this.get('/v1/common/timestamp');
}
/**
* Get all Supported Trading Symbols (V2)
*
* Returns all supported trading symbols. Pass ts for incremental updates.
*/
getTradingSymbols(params?: {
ts?: number;
}): Promise<SpotAPISuccessResponse<SpotTradingSymbol[]>> {
return this.get('/v2/settings/common/symbols', params);
}
/**
* Get all Supported Currencies (V2)
*
* Returns all supported currencies. Pass ts for incremental updates.
*/
getCurrencies(params?: {
ts?: number;
}): Promise<SpotAPISuccessResponse<SpotCurrency[]>> {
return this.get('/v2/settings/common/currencies', params);
}
/**
* Get Currencys Settings (V1)
*
* Returns currency settings. No signature required. Pass ts for incremental updates.
*/
getCurrencysSettings(params?: {
ts?: number;
}): Promise<SpotAPISuccessResponse<SpotV1CurrencySettings[]>> {
return this.get('/v1/settings/common/currencys', params);
}
/**
* Get Symbols Settings (V1)
*
* Returns symbol settings. No signature required. Pass ts for incremental updates.
*/
getSymbolsSettings(params?: {
ts?: number;
}): Promise<SpotAPISuccessResponse<SpotV1SymbolSettings[]>> {
return this.get('/v1/settings/common/symbols', params);
}
/**
* Get Market Symbols Settings (V1)
*
* Returns market symbol settings. No signature required. Pass symbols (NA=all) and/or ts for incremental updates.
*/
getMarketSymbolsSettings(params?: {
symbols?: string;
ts?: number;
}): Promise<SpotAPISuccessResponse<SpotV1MarketSymbolSettings[]>> {
return this.get('/v1/settings/common/market-symbols', params);
}
/**
* Get Chains Information (V1)
*
* Returns chain info per currency. No signature required. Pass show-desc, currency, and/or ts for incremental updates.
*/
getChainsInfo(
params?: SpotGetChainsReq,
): Promise<SpotAPISuccessResponse<SpotV1ChainInfo[]>> {
return this.get('/v1/settings/common/chains', params);
}
/**
* Get Reference Currencies & Chains (V2)
*
* Returns static reference info for each currency and its chains. No signature required.
*/
getReferenceCurrencies(params?: {
currency?: string;
authorizedUser?: boolean;
}): Promise<SpotAPISuccessResponse<SpotV2CurrencyReference[]>> {
return this.get('/v2/reference/currencies', params);
}
/**
*
* Market Data
*
*/
/**
* Get Klines (Candles)
*
* Returns candlestick data for a symbol. No signature required.
*/
getKlines(
params: SpotGetKlineReq,
): Promise<SpotAPISuccessResponse<SpotKline[]>> {
return this.get('/market/history/kline', params);
}
/**
* Get Latest Aggregated Ticker
*
* Returns latest ticker with 24h aggregated market data. No signature required.
*/
getTicker(params: {
symbol: string;
}): Promise<SpotAPISuccessResponse<SpotMergedTicker, 'tick'>> {
return this.get('/market/detail/merged', params);
}
/**
* Get Latest Tickers for All Pairs
*
* Returns latest tickers for all supported pairs. No signature required.
*/
getTickers(): Promise<SpotAPISuccessResponse<SpotTicker[]>> {
return this.get('/market/tickers');
}
/**
* Get Market Depth
*
* Returns order book for a symbol. No signature required.
*/
getMarketDepth(
params: SpotGetDepthReq,
): Promise<SpotAPISuccessResponse<SpotDepth, 'tick'>> {
return this.get('/market/depth', params);
}
/**
* Get the Last Trade
*
* Returns latest trade with price, volume, direction. No signature required.
*/
getLastTrade(params: {
symbol: string;
}): Promise<SpotAPISuccessResponse<SpotLastTrade, 'tick'>> {
return this.get('/market/trade', params);
}
/**
* Get the Most Recent Trades
*
* Returns recent trades grouped by timestamp. No signature required.
*/
getHistoryTrades(params: {
symbol: string;
size?: number;
}): Promise<SpotAPISuccessResponse<SpotTradeTimestampGroup[]>> {
return this.get('/market/history/trade', params);
}
/**
* Get the Last 24h Market Summary
*
* Returns 24h trading summary for a symbol. No signature required.
*/
get24hMarketSummary(params: {
symbol: string;
}): Promise<SpotAPISuccessResponse<SpotDetailTick, 'tick'>> {
return this.get('/market/detail', params);
}
/**
* Get Full Order Book
*
* Returns complete market depth, up to 5000 levels. Updated once per second. No signature required.
*/
getFullOrderBook(params: {
symbol: string;
}): Promise<SpotAPISuccessResponse<SpotDepth, 'tick'>> {
return this.get('/market/fullMbp', params);
}
/**
*
* Account
*
*/
/**
* Get all Accounts of the Current User
*
* Returns list of accounts owned by this API user. Signature required.
*/
getAccounts(): Promise<SpotAPISuccessResponse<SpotAccount[]>> {
return this.getPrivate('/v1/account/accounts');
}
/**
* Get Account Balance of a Specific Account
*
* Returns balance for account specified by account id. Signature required. OTC not supported.
*/
getAccountBalance(params: {
accountId: string | number;
}): Promise<SpotAPISuccessResponse<SpotAccountBalance>> {
return this.getPrivate(`/v1/account/accounts/${params.accountId}/balance`);
}
/**
* Get The Total Valuation of Platform Assets
*
* Returns total asset valuation in BTC or fiat. Signature required.
*/
getAccountValuation(params?: {
accountType?: string;
valuationCurrency?: string;
}): Promise<SpotAPISuccessResponse<SpotV2AccountValuation>> {
return this.getPrivate('/v2/account/valuation', params);
}
/**
* Get Asset Valuation
*
* Returns valuation of total assets in BTC or fiat. Signature required.
*/
getAssetValuation(
params?: SpotGetAssetValuationReq,
): Promise<SpotAPISuccessResponse<SpotV2AssetValuation>> {
return this.getPrivate('/v2/account/asset-valuation', params);
}
/**
* Asset Transfer
*
* Transfer asset between accounts (spot, margin, sub-users). Signature required. Trade permission.
*/
submitTransfer(
params: SpotAccountTransferReq,
): Promise<SpotAPISuccessResponse<SpotAccountTransferResult>> {
return this.postPrivate('/v1/account/transfer', { body: params });
}
/**
* Get Account History
*
* Returns amount changes of specified account. Signature required. Max 1h query window, 30 days range.
*/
getAccountHistory(
params: SpotGetAccountHistoryReq,
): Promise<
SpotAPISuccessResponse<SpotAccountHistory[]> & { 'next-id'?: number }
> {
return this.getPrivate('/v1/account/history', params);
}
/**
* Get Account Ledger
*
* Returns amount changes (phase 1: transfer only). Max 10-day window, 180 days range. Signature required.
*/
getAccountLedger(
params?: SpotGetAccountLedgerReq,
): Promise<
SpotAPISuccessResponse<SpotV2AccountLedger[]> & { nextId?: number }
> {
return this.getPrivate('/v2/account/ledger', params);
}
/**
* V2 Account Transfer
*
* Transfer funds between spot, linear-swap, otc, futures, swap. Signature required. Trade permission.
*/
submitV2AccountTransfer(
params: SpotV2AccountTransferReq,
): Promise<SpotAPISuccessResponse<number>> {
return this.postPrivate('/v2/account/transfer', { body: params });
}
/**
* Futures Transfer
*
* Transfer between spot and future contract account. pro-to-futures = spot -> contract, futures-to-pro = contract -> spot. Signature required. Trade permission.
*/
submitFuturesTransfer(
params: SpotV1FuturesTransferReq,
): Promise<SpotAPISuccessResponse<number>> {
return this.postPrivate('/v1/futures/transfer', { body: params });
}
/**
* Get Point Balance
*
* Query termless and terminable point balance. Parent can query sub user via subUid. Signature required. Read permission. Rate: 2/s.
*/
getPointBalance(params?: {
subUid?: string;
}): Promise<SpotAPISuccessResponse<SpotV2PointAccount>> {
return this.getPrivate('/v2/point/account', params);
}
/**
* Point Transfer
*
* Transfer points between parent and sub user. groupId=0 for termless; for terminable query sub balance first. Signature required. Trade permission. Rate: 2/s.
*/
submitPointTransfer(
params: SpotV2PointTransferReq,
): Promise<SpotAPISuccessResponse<SpotV2PointTransfer>> {
return this.postPrivate('/v2/point/transfer', { body: params });
}
/**
* Get User Deduction Info
*
* Query point card vs HTX deduction settings. Signature required. Read permission. Rate: 5/s.
*/
getAccountSwitchUserInfo(): Promise<
SpotAPISuccessResponse<SpotV1AccountSwitchUserInfo>
> {
return this.getPrivate('/v1/account/switch/user/info');
}
/**
* Get Deductible Currency Overview
*
* Query asset that can be used to deduct fees. Signature required. Read permission. Rate: 5/s.
*/
getAccountOverviewInfo(): Promise<
SpotAPISuccessResponse<SpotV1AccountOverviewInfo>
> {
return this.getPrivate('/v1/account/overview/info');
}
/**
* Set Spot/Margin Fee Deduction Method
*
* switchType: 0=point card, 1=currency (pass deductionCurrency), 2=close. Signature required. Read permission. Rate: 2/s.
*/
updateFeeDeductionMethod(params: {
switchType: 0 | 1 | 2;
deductionCurrency?: string;
}): Promise<SpotAPISuccessResponse<null>> {
return this.postPrivate('/v1/account/fee/switch', { body: params });
}
/**
*
* Trading
*
*/
/**
* Place a New Order
*
* Places order to be matched. Set account-id and source per account type. Signature required. Trade permission. Rate: 100/2s.
*/
submitOrder(
params: SpotV1OrderPlaceReq,
): Promise<SpotAPISuccessResponse<string>> {
this.validateOrderId(params, 'client-order-id');
return this.postPrivate('/v1/order/orders/place', { body: params });
}
/**
* Place a Batch of Orders
*
* Max 10 orders per batch. Each returns order-id or err-code/err-msg. Signature required. Trade permission. Rate: 50/2s.
*/
submitBatchOrders(
params: SpotV1OrderPlaceReq[],
): Promise<SpotAPISuccessResponse<SpotV1OrderBatchPlaceResult[]>> {
for (const order of params) {
this.validateOrderId(order, 'client-order-id');
}
return this.postPrivate('/v1/order/batch-orders', { body: params });
}
/**
* Margin Order (Auto Borrow/Repay)
*
* Auto borrow to place or auto repay. Sub-accounts not supported. Use amount or market-amount. Signature required. Trade permission. Rate: 100/2s.
*/
submitMarginOrder(
params: SpotV1OrderAutoPlaceReq,
): Promise<SpotAPISuccessResponse<SpotV1OrderAutoPlaceResult>> {
this.validateOrderId(params, 'client-order-id');
return this.postPrivate('/v1/order/auto/place', { body: params });
}
/**
* Cancel Order by Order ID
*
* Submits cancel request. Verify via order status or match result. Signature required. Trade permission. Rate: 100/2s.
*/
cancelOrderById(params: {
orderId: string;
symbol?: string;
}): Promise<SpotAPISuccessResponse<SpotV1OrderCancelResult>> {
const { orderId, ...body } = params;
return this.postPrivate(`/v1/order/orders/${orderId}/submitcancel`, {
body: body,
});
}
/**
* Cancel Order by Client Order ID
*
* Prefer cancelOrder (by order-id) when possible. Submits cancel request; verify via order status. Signature required. Trade permission. Rate: 100/2s.
*/
cancelOrderByClientId(params: {
'client-order-id': string;
}): Promise<SpotAPISuccessResponse<SpotV1OrderCancelByClientOrderIdResult>> {
return this.postPrivate('/v1/order/orders/submitCancelClientOrder', {
body: params,
});
}
/**
* Cancel All Spot Orders
*
* Cancel all open spot orders. Pass symbol for specific pair(s), comma-separated; omit for all. Signature required. Trade permission. Rate: 1/2s.
*/
cancelAllOrders(params?: {
symbol?: string;
}): Promise<SpotAPISuccessResponse<null>> {
return this.getPrivate('/v1/order/cancelAllOrders', params);
}
/**
* Get All Open Orders
*
* Returns unfilled orders. Filter by account-id, symbol, side. Signature required. Read permission. Rate: 50/2s.
*/
getOpenOrders(
params?: SpotGetOpenOrdersReq,
): Promise<SpotAPISuccessResponse<SpotV1OpenOrder[]>> {
return this.getPrivate('/v1/order/openOrders', params);
}
/**
* Cancel Multiple Orders by Criteria
*
* Cancel up to 100 orders matching account-id, symbol, types, side. Submit only; verify via order status. Signature required. Trade permission. Rate: 50/2s.
*/
batchCancelOpenOrders(
params?: SpotV1OrderBatchCancelOpenOrdersReq,
): Promise<SpotAPISuccessResponse<SpotV1OrderBatchCancelOpenOrdersResult>> {
return this.postPrivate('/v1/order/orders/batchCancelOpenOrders', {
body: params,
});
}
/**
* Cancel Multiple Orders by IDs
*
* Cancel by order-ids or client-order-ids (max 50). Prefer order-ids. Signature required. Trade permission. Rate: 50/2s.
*/
batchCancelOrders(params: {
'order-ids'?: string[];
'client-order-ids'?: string[];
}): Promise<SpotAPISuccessResponse<SpotV1OrderBatchCancelResult>> {
return this.postPrivate('/v1/order/orders/batchcancel', { body: params });
}
/**
* Dead Man's Switch (Cancel All After)
*
* Turn on/off. timeout=0 to turn off. timeout>=5 to turn on: must call twice within timeout seconds or all spot orders (max 500) are canceled. Signature required. Trade permission.
*/
setCancelAllAfter(params: {
timeout: number;
}): Promise<SpotAPISuccessResponse<SpotV2AlgoOrdersCancelAllAfterResult>> {
return this.postPrivate('/v2/algo-orders/cancel-all-after', {
body: params,
});
}
/**
* Get Order Detail by Order ID
*
* Returns order detail. API-created orders not queryable 2h after cancel. Signature required. Read permission. Rate: 50/2s.
*/
getOrder(params: {
orderId: string;
}): Promise<SpotAPISuccessResponse<SpotV1OrderDetail>> {
return this.getPrivate(`/v1/order/orders/${params.orderId}`);
}
/**
* Get Order Detail by Client Order ID
*
* Returns latest status of order with given client order ID. Signature required. Read permission. Rate: 50/2s.
*/
getOrderByClientId(params: {
clientOrderId: string;
}): Promise<SpotAPISuccessResponse<SpotV1OrderDetail>> {
return this.getPrivate('/v1/order/orders/getClientOrder', params);
}
/**
* Get Match Results of an Order
*
* Returns match/trade results for a specific order. Signature required. Read permission. Rate: 50/2s.
*/
getOrderMatch(params: {
orderId: string;
}): Promise<SpotAPISuccessResponse<SpotV1OrderMatchResult[]>> {
return this.getPrivate(`/v1/order/orders/${params.orderId}/matchresults`);
}
/**
* Search Past Orders
*
* Historical orders by symbol, states, time range. Max 48h window, 180 days range. API orders not queryable 2h after cancel. Signature required. Read permission. Rate: 50/2s.
*/
getOrderHistory(
params: SpotGetOrderHistoryReq,
): Promise<SpotAPISuccessResponse<SpotV1OrderHistory[]>> {
return this.getPrivate('/v1/order/orders', params);
}
/**
* Search Historical Orders within 48 Hours
*
* Orders by time range. Default: last 48h. next-time in last item when more exist. API orders not queryable 2h after cancel. Signature required. Read permission. Rate: 20/2s.
*/
getOrderHistory48h(
params?: SpotGetOrderHistory48hReq,
): Promise<SpotAPISuccessResponse<SpotV1OrderHistory48h[]>> {
return this.getPrivate('/v1/order/history', params);
}
/**
* Search Match Results
*
* Match results of filled/partial orders by symbol, types, time. 48h window, 120 days range. Signature required. Read permission. Rate: 20/2s.
*/
getMatchResults(
params?: SpotGetMatchResultsReq,
): Promise<SpotAPISuccessResponse<SpotV1OrderMatchResult[]>> {
return this.getPrivate('/v1/order/matchresults', params);
}
/**
* Get Transact Fee Rate
*
* Query fee rates for trading pairs. Max 10 symbols. Signature required. Read permission. Rate: 50/2s.
*/
getFeeRate(params: {
symbols: string;
}): Promise<SpotAPISuccessResponse<SpotV2TransactFeeRate[]>> {
return this.getPrivate('/v2/reference/transact-fee-rate', params);
}
/**
*
* Conditional Order
*
*/
/**
* Place a Conditional Order
*
* Conditional orders only via this endpoint (not Trading section). Signature required. Trade permission. Rate: 20/2s.
*/
placeConditionalOrder(
params: SpotV2AlgoOrdersPlaceReq,
): Promise<SpotAPISuccessResponse<SpotV2AlgoOrdersPlaceResult>> {
this.validateOrderId(params, 'clientOrderId');
return this.postPrivate('/v2/algo-orders', { body: params });
}
/**
* Cancel Conditional Orders (before triggering)
*
* Only cancels conditional orders that have not triggered yet. Max 50 orders. Signature required. Trade permission. Rate: 20/2s.
*/
cancelConditionalOrders(params: {
clientOrderIds: string[];
}): Promise<SpotAPISuccessResponse<SpotV2AlgoOrdersCancellationResult>> {
return this.postPrivate('/v2/algo-orders/cancellation', { body: params });
}
/**
* Query Open Conditional Orders (before triggering)
*
* Returns conditional orders with orderStatus=created. Signature required. Read permission. Rate: 20/2s.
*/
getOpenConditionalOrders(
params?: SpotV2AlgoOrdersOpeningReq,
): Promise<SpotAPISuccessResponse<SpotV2AlgoOrder[]> & { nextId?: number }> {
return this.getPrivate('/v2/algo-orders/opening', params);
}
/**
* Query Conditional Order History
*
* Returns canceled/rejected/triggered conditional orders. For triggered, use Trading section for latest status. Signature required. Read permission. Rate: 20/2s.
*/
getConditionalOrderHistory(
params?: SpotV2AlgoOrdersHistoryReq,
): Promise<SpotAPISuccessResponse<SpotV2AlgoOrder[]> & { nextId?: number }> {
return this.getPrivate('/v2/algo-orders/history', params);
}
/**
* Query a Specific Conditional Order
*
* By clientOrderId. Covers created, triggered, canceled, rejected. Signature required. Read permission. Rate: 20/2s.
*/
getConditionalOrder(params: {
clientOrderId: string;
}): Promise<SpotAPISuccessResponse<SpotV2AlgoOrder>> {
return this.getPrivate('/v2/algo-orders/specific', params);
}
/**
*
* Margin Loan (Cross/Isolated)
*
*/
/**
* Repayment Record Reference
*
* Query repayment records. Sorted by repayTime. Main and sub-accounts. Signature required. Read permission. Rate: 2/2s.
*/
getRepaymentRecords(
params?: SpotRepaymentRecordReq,
): Promise<
SpotAPISuccessResponse<SpotRepaymentRecord[]> & { nextId?: number }
> {
return this.getPrivate('/v2/account/repayment', params);
}
/**
* Repay Margin Loan (Cross/Isolated)
*
* Loan interest paid first if no transactId. Main and sub-accounts. Signature required. Trade permission. Rate: 2/s.
*/
repayMarginLoan(
params: SpotMarginRepaymentReq,
): Promise<SpotAPISuccessResponse<SpotMarginRepaymentResult[]>> {
return this.postPrivate('/v2/account/repayment', { body: params });
}
/**
* Transfer Asset from Spot Trading Account to Isolated Margin Account
*
* Signature required. Trade permission. Rate: 2/2s.
*/
transferSpotToIsolatedMargin(
params: SpotMarginTransferInIsolatedReq,
): Promise<SpotAPISuccessResponse<number>> {
return this.postPrivate('/v1/dw/transfer-in/margin', { body: params });
}
/**
* Transfer Asset from Isolated Margin Account to Spot Trading Account
*
* Signature required. Trade permission. Rate: 2/2s.
*/
transferIsolatedMarginToSpot(
params: SpotMarginTransferOutIsolatedReq,
): Promise<SpotAPISuccessResponse<number>> {
return this.postPrivate('/v1/dw/transfer-out/margin', { body: params });
}
/**
* Get Loan Interest Rate and Quota (Isolated)
*
* Returns loan interest rates and quota per symbol. Signature required. Read permission. Rate: 20/2s.
*/
getMarginLoanInfo(params?: {
symbols?: string;
}): Promise<SpotAPISuccessResponse<SpotMarginLoanInfo[]>> {
return this.getPrivate('/v1/margin/loan-info', params);
}
/**
* Request a Margin Loan (Isolated)
*
* Places order to borrow margin. Signature required. Trade permission. Rate: 2/2s.
*/
requestMarginLoan(
params: SpotMarginLoanOrderReq,
): Promise<SpotAPISuccessResponse<number>> {
return this.postPrivate('/v1/margin/orders', { body: params });
}
/**
* Repay Margin Loan (Isolated)
*
* Repays with asset in margin account. Signature required. Trade permission. Rate: 2/2s.
*/
repayMarginLoanIsolated(params: {
orderId: string;
amount: string;
}): Promise<SpotAPISuccessResponse<number>> {
const { orderId, amount } = params;
return this.postPrivate(`/v1/margin/orders/${orderId}/repay`, {
body: { amount },
});
}
/**
* Search Past Margin Orders (Isolated)
*
* Returns margin loan orders by criteria. Signature required. Read permission. Rate: 100/2s.
*/
getMarginLoanOrders(
params?: SpotMarginLoanOrdersReq,
): Promise<SpotAPISuccessResponse<SpotMarginLoanOrder[]>> {
return this.getPrivate('/v1/margin/loan-orders', params);
}
/**
* Get the Balance of the Margin Loan Account (Isolated)
*
* Signature required. Read permission. Rate: 100/2s.
*/
getMarginAccountBalance(params?: {
symbol?: string;
'sub-uid'?: number;
}): Promise<SpotAPISuccessResponse<SpotMarginAccountBalance[]>> {
return this.getPrivate('/v1/margin/accounts/balance', params);
}
/**
* Transfer Asset from Spot Trading Account to Cross Margin Account
*
* Signature required. Trade permission.
*/
transferSpotToCrossMargin(params: {
currency?: string;
amount?: string;
}): Promise<SpotAPISuccessResponse<number>> {
return this.postPrivate('/v1/cross-margin/transfer-in', { body: params });
}
/**
* Transfer Asset from Cross Margin Account to Spot Trading Account
*
* Signature required. Trade permission.
*/
transferCrossMarginToSpot(params: {
currency?: string;
amount?: string;
}): Promise<SpotAPISuccessResponse<number>> {
return this.postPrivate('/v1/cross-margin/transfer-out', { body: params });
}
/**
* Get Loan Interest Rate and Quota (Cross)
*
* Returns loan interest rates and quota per currency. No params. Signature required. Read permission. Rate: 2/2s.
*/
getCrossMarginLoanInfo(): Promise<
SpotAPISuccessResponse<SpotMarginLoanInfoCurrency[]>
> {
return this.getPrivate('/v1/cross-margin/loan-info');
}
/**
* Request a Margin Loan (Cross)
*
* Places order to borrow margin. Signature required. Trade permission. Rate: 2/2s.
*/
requestCrossMarginLoan(params: {
currency?: string;
amount?: string;
}): Promise<SpotAPISuccessResponse<number>> {
return this.postPrivate('/v1/cross-margin/orders', { body: params });
}
/**
* Repay Margin Loan (Cross)
*
* Repays with asset in cross margin account. Signature required. Trade permission. Rate: 2/2s.
*/
repayCrossMarginLoan(params: {
orderId: string;
amount: string;
}): Promise<SpotAPISuccessResponse<null>> {
const { orderId, amount } = params;
return this.postPrivate(`/v1/cross-margin/orders/${orderId}/repay`, {
body: { amount },
});
}
/**
* Search Past Margin Orders (Cross)
*
* Returns margin loan orders by criteria. Signature required. Read permission. Rate: 2/2s.
*/
getCrossMarginLoanOrders(
params?: SpotCrossMarginLoanOrdersReq,
): Promise<SpotAPISuccessResponse<SpotCrossMarginLoanOrder[]>> {
return this.getPrivate('/v1/cross-margin/loan-orders', params);
}
/**
* Get the Balance of the Margin Loan Account (Cross)
*
* Returns single account object. Signature required. Read permission. Rate: 2/2s.
*/
getCrossMarginBalance(params?: {
'sub-uid'?: number;
}): Promise<SpotAPISuccessResponse<SpotCrossMarginAccountBalance>> {
return this.getPrivate('/v1/cross-margin/accounts/balance', params);
}
/**
* Obtain Leverage Position Limit (Cross)
*
* Returns position limit at user level per currency. Signature required. Read permission. Rate: 2/2s.