-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSpotClient.ts
More file actions
915 lines (843 loc) · 24.3 KB
/
SpotClient.ts
File metadata and controls
915 lines (843 loc) · 24.3 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
import { BaseRestClient } from './lib/BaseRestClient.js';
import { REST_CLIENT_TYPE_ENUM, RestClientType } from './lib/requestUtils.js';
import {
OauthCreateFastApiKeyParams,
OauthGetAccessTokenParams,
OauthUpdateFastApiKeyParams,
SpotAccountTransferParams,
SpotAmendOrderParams,
SpotGetAssetPairsParams,
SpotGetClosedOrdersParams,
SpotGetDepositAddressesParams,
SpotGetDepositMethodsParams,
SpotGetDepositStatusParams,
SpotGetLedgersInfoParams,
SpotGetOHLCParams,
SpotGetOpenOrdersParams,
SpotGetOpenPositionsParams,
SpotGetOrderBookParams,
SpotGetPostTradeDataParams,
SpotGetRecentSpreadsParams,
SpotGetRecentTradesParams,
SpotGetTradesHistoryParams,
SpotGetWithdrawalAddressesParams,
SpotGetWithdrawalInfoParams,
SpotGetWithdrawalMethodsParams,
SpotGetWithdrawalsStatusParams,
SpotListEarnAllocationsParams,
SpotListEarnStrategiesParams,
SpotQueryLedgersParams,
SpotQueryOrdersParams,
SpotQueryTradesParams,
SpotRequestExportReportParams,
SpotSubmitOrderBatchParams,
SpotSubmitOrderParams,
SpotWalletTransferParams,
SpotWithdrawFundsParams,
} from './types/request/spot.types.js';
import { SpotAPISuccessResponse } from './types/response/shared.types.js';
import {
OauthCreateFastApiKeyResponse,
OauthFastApiKey,
OauthGetAccessTokenResponse,
OauthGetUserInfoResponse,
SpotAccountBalance,
SpotAccountTransferResponse,
SpotAssetInfo,
SpotAssetPair,
SpotAssetTickerInfo,
SpotBatchOrderResult,
SpotClosedOrdersResponse,
SpotCreditLines,
SpotDeleteExportReportResponse,
SpotDepositAddress,
SpotDepositMethod,
SpotDepositStatusResponse,
SpotEarnStrategy,
SpotExportReportStatus,
SpotExtendedBalance,
SpotLedgersInfoResponse,
SpotListEarnAllocationsResponse,
SpotOHLCResponse,
SpotOpenOrdersResponse,
SpotOpenPositionsResponse,
SpotOrderAmendsResponse,
SpotOrderBookResponse,
SpotPostTradeDataResponse,
SpotPreTradeData,
SpotQueryLedgersResponse,
SpotQueryOrdersResponse,
SpotQueryTradesResponse,
SpotRecentSpreadsResponse,
SpotRecentTradesResponse,
SpotRequestExportReportResponse,
SpotSubmitOrderResponse,
SpotSystemStatus,
SpotTradeBalance,
SpotTradesHistoryResponse,
SpotTradeVolume,
SpotWebSocketsTokenResponse,
SpotWithdrawalAddress,
SpotWithdrawalInfo,
SpotWithdrawalMethod,
SpotWithdrawalStatus,
} from './types/response/spot.types.js';
/**
* The SpotClient provides integration to the Kraken Spot API.
*
* Docs:
* - https://docs.kraken.com/api/docs/guides/spot-rest-intro/
* - https://docs.kraken.com/api/docs/rest-api/get-server-time
*/
export class SpotClient extends BaseRestClient {
getClientType(): RestClientType {
// Points to api.kraken.com
return REST_CLIENT_TYPE_ENUM.main;
}
/**
*
* Misc Utility Methods
*
*/
generateNewOrderID(): string {
// Generate a short UUID format (32 hex characters without dashes)
// Compatible with Kraken's cl_ord_id parameter
const hexChars = '0123456789abcdef';
let result = '';
for (let i = 0; i < 32; i++) {
result += hexChars[Math.floor(Math.random() * 16)];
}
return result;
}
/**
*
* Spot REST API - Market Data
*
*/
/**
* Get Server Time
*
* Get the server's time.
*/
getServerTime(): Promise<
SpotAPISuccessResponse<{
unixtime: number;
rfc1123: string;
}>
> {
return this.get('0/public/Time');
}
/**
* Get System Status
*
* Get the current system status or trading mode.
*/
getSystemStatus(): Promise<SpotAPISuccessResponse<SpotSystemStatus>> {
return this.get('0/public/SystemStatus');
}
/**
* Get Asset Info
*
* Get information about the assets that are available for deposit, withdrawal, trading and earn.
*/
getAssetInfo(params?: {
asset?: string;
aclass?: 'currency' | 'tokenized_asset';
}): Promise<SpotAPISuccessResponse<Record<string, SpotAssetInfo>>> {
return this.get('0/public/Assets', params);
}
/**
* Get Tradable Asset Pairs
*
* Get tradable asset pairs
*/
getAssetPairs(
params?: SpotGetAssetPairsParams,
): Promise<SpotAPISuccessResponse<Record<string, SpotAssetPair>>> {
return this.get('0/public/AssetPairs', params);
}
/**
* Get Ticker Information
*
* Get ticker information for all or requested markets.
* Note: Today's prices start at midnight UTC.
* Leaving the pair parameter blank will return tickers for all tradeable assets on Kraken.
*/
getTicker(params?: {
pair?: string;
asset_class?: 'tokenized_asset' | 'forex';
}): Promise<SpotAPISuccessResponse<Record<string, SpotAssetTickerInfo>>> {
return this.get('0/public/Ticker', params);
}
/**
* Get OHLC Data
*
* Retrieve OHLC market data. The last entry in the OHLC array is for the current, not-yet-committed timeframe,
* and will always be present, regardless of the value of since. Returns up to 720 of the most recent entries
* (older data cannot be retrieved, regardless of the value of since).
*/
getCandles(
params: SpotGetOHLCParams,
): Promise<SpotAPISuccessResponse<SpotOHLCResponse>> {
return this.get('0/public/OHLC', params);
}
/**
* Get Order Book
*
* Returns level 2 (L2) order book, which describes the individual price levels in the book with aggregated
* order quantities at each level.
*/
getOrderBook(
params: SpotGetOrderBookParams,
): Promise<SpotAPISuccessResponse<SpotOrderBookResponse>> {
return this.get('0/public/Depth', params);
}
/**
* Get Recent Trades
*
* Returns the last 1000 trades by default
*/
getRecentTrades(
params: SpotGetRecentTradesParams,
): Promise<SpotAPISuccessResponse<SpotRecentTradesResponse>> {
return this.get('0/public/Trades', params);
}
/**
* Get Recent Spreads
*
* Returns the last ~200 top-of-book spreads for a given pair
*/
getRecentSpreads(
params: SpotGetRecentSpreadsParams,
): Promise<SpotAPISuccessResponse<SpotRecentSpreadsResponse>> {
return this.get('0/public/Spread', params);
}
/**
*
* Spot REST API - Account Data
*
*/
/**
* Get Account Balance
*
* Retrieve all cash balances, net of pending withdrawals.
*/
getAccountBalance(params?: {
rebase_multiplier?: 'rebased' | 'base';
}): Promise<SpotAPISuccessResponse<SpotAccountBalance>> {
return this.postPrivate('0/private/Balance', { body: params });
}
/**
* Get Extended Balance
*
* Retrieve all extended account balances, including credits and held amounts.
* Balance available for trading is calculated as: available balance = balance + credit - credit_used - hold_trade
*/
getExtendedBalance(params?: {
rebase_multiplier?: 'rebased' | 'base';
}): Promise<SpotAPISuccessResponse<SpotExtendedBalance>> {
return this.postPrivate('0/private/BalanceEx', { body: params });
}
/**
* Get Credit Lines
*
* Retrieve all credit line details for VIPs with this functionality.
*/
getCreditLines(params?: {
rebase_multiplier?: 'rebased' | 'base';
}): Promise<SpotAPISuccessResponse<SpotCreditLines | null>> {
return this.postPrivate('0/private/CreditLines', { body: params });
}
/**
* Get Trade Balance
*
* Retrieve a summary of collateral balances, margin position valuations, equity and margin level.
*/
getTradeBalance(params?: {
rebase_multiplier?: 'rebased' | 'base';
}): Promise<SpotAPISuccessResponse<SpotTradeBalance>> {
return this.postPrivate('0/private/TradeBalance', { body: params });
}
/**
* Get Open Orders
*
* Retrieve information about currently open orders.
*/
getOpenOrders(
params?: SpotGetOpenOrdersParams,
): Promise<SpotAPISuccessResponse<SpotOpenOrdersResponse>> {
return this.postPrivate('0/private/OpenOrders', { body: params });
}
/**
* Get Closed Orders
*
* Retrieve information about orders that have been closed (filled or cancelled).
* 50 results are returned at a time, the most recent by default.
*/
getClosedOrders(
params?: SpotGetClosedOrdersParams,
): Promise<SpotAPISuccessResponse<SpotClosedOrdersResponse>> {
return this.postPrivate('0/private/ClosedOrders', { body: params });
}
/**
* Query Orders Info
*
* Retrieve information about specific orders.
*/
getOrders(
params: SpotQueryOrdersParams,
): Promise<SpotAPISuccessResponse<SpotQueryOrdersResponse>> {
return this.postPrivate('0/private/QueryOrders', { body: params });
}
/**
* Get Order Amends
*
* Retrieves an audit trail of amend transactions on the specified order.
* The list is ordered by ascending amend timestamp.
*/
getOrderAmends(params: {
order_id: string;
rebase_multiplier?: 'rebased' | 'base';
}): Promise<SpotAPISuccessResponse<SpotOrderAmendsResponse>> {
return this.postPrivate('0/private/OrderAmends', { body: params });
}
/**
* Get Trades History
*
* Retrieve information about trades/fills. 50 results are returned at a time, the most recent by default.
*/
getTradesHistory(
params?: SpotGetTradesHistoryParams,
): Promise<SpotAPISuccessResponse<SpotTradesHistoryResponse>> {
return this.postPrivate('0/private/TradesHistory', { body: params });
}
/**
* Query Trades Info
*
* Retrieve information about specific trades/fills.
*/
getTrades(
params: SpotQueryTradesParams,
): Promise<SpotAPISuccessResponse<SpotQueryTradesResponse>> {
return this.postPrivate('0/private/QueryTrades', { body: params });
}
/**
* Get Open Positions
*
* Get information about open margin positions.
*/
getOpenPositions(
params?: SpotGetOpenPositionsParams,
): Promise<SpotAPISuccessResponse<SpotOpenPositionsResponse>> {
return this.postPrivate('0/private/OpenPositions', { body: params });
}
/**
* Get Ledgers Info
*
* Retrieve information about ledger entries. 50 results are returned at a time, the most recent by default.
*/
getLedgersInfo(
params?: SpotGetLedgersInfoParams,
): Promise<SpotAPISuccessResponse<SpotLedgersInfoResponse>> {
return this.postPrivate('0/private/Ledgers', { body: params });
}
/**
* Query Ledgers
*
* Retrieve information about specific ledger entries.
*/
getLedgers(
params: SpotQueryLedgersParams,
): Promise<SpotAPISuccessResponse<SpotQueryLedgersResponse>> {
return this.postPrivate('0/private/QueryLedgers', { body: params });
}
/**
* Get Trade Volume
*
* Returns 30 day USD trading volume and resulting fee schedule for any asset pair(s) provided.
*/
getTradingVolume(params?: {
pair?: string;
rebase_multiplier?: 'rebased' | 'base';
}): Promise<SpotAPISuccessResponse<SpotTradeVolume>> {
return this.postPrivate('0/private/TradeVolume', { body: params });
}
/**
* Request Export Report
*
* Request export of trades or ledgers.
*/
requestLedgersExport(
params: SpotRequestExportReportParams,
): Promise<SpotAPISuccessResponse<SpotRequestExportReportResponse>> {
return this.postPrivate('0/private/AddExport', { body: params });
}
/**
* Get Export Report Status
*
* Get status of requested data exports.
*/
getLedgersExportStatus(params: {
report: 'trades' | 'ledgers';
}): Promise<SpotAPISuccessResponse<SpotExportReportStatus[]>> {
return this.postPrivate('0/private/ExportStatus', { body: params });
}
/**
* Retrieve Data Export
*
* Retrieve a processed data export (binary zip archive).
*/
getLedgersExport(params: { id: string }): Promise<any> {
return this.postPrivate('0/private/RetrieveExport', { body: params });
}
/**
* Delete Export Report
*
* Delete or cancel exported trades/ledgers report.
*/
deleteLedgersExport(params: {
id: string;
type: 'cancel' | 'delete';
}): Promise<SpotAPISuccessResponse<SpotDeleteExportReportResponse>> {
return this.postPrivate('0/private/RemoveExport', { body: params });
}
/**
*
* Spot REST API - Trading
*
*/
/**
* Add Order
*
* Place a new order.
* Note: See the getAssetPairs() endpoint for details on the available trading pairs, their price and quantity precisions,
* order minimums, available leverage, etc.
*/
submitOrder(
params: SpotSubmitOrderParams,
): Promise<SpotAPISuccessResponse<SpotSubmitOrderResponse>> {
return this.postPrivate('0/private/AddOrder', {
body: params,
});
}
/**
* Amend Order
*
* Amend an existing order. The order identifiers assigned by Kraken and/or client will stay the same.
* Queue priority in the order book will be maintained where possible.
*/
amendOrder(params: SpotAmendOrderParams): Promise<
SpotAPISuccessResponse<{
amend_id: string;
}>
> {
return this.postPrivate('0/private/AmendOrder', {
body: params,
});
}
/**
* Cancel Order
*
* Cancel a particular open order (or set of open orders) by txid, userref or cl_ord_id.
*/
cancelOrder(params: { txid?: string | number; cl_ord_id?: string }): Promise<
SpotAPISuccessResponse<{
count: number;
pending?: boolean;
}>
> {
return this.postPrivate('0/private/CancelOrder', {
body: params,
});
}
/**
* Cancel All Orders
*
* Cancel all open orders.
*/
cancelAllOrders(): Promise<
SpotAPISuccessResponse<{
count: number;
pending: boolean;
}>
> {
return this.postPrivate('0/private/CancelAll', { body: {} });
}
/**
* Cancel All Orders After X
*
* CancelAllOrdersAfter provides a "Dead Man's Switch" mechanism to protect the client from network malfunction,
* extreme latency or unexpected matching engine downtime. The client can send a request with a timeout (in seconds),
* that will start a countdown timer which will cancel all client orders when the timer expires.
*/
cancelAllOrdersAfter(params: { timeout: number }): Promise<
SpotAPISuccessResponse<{
currentTime: string;
triggerTime: string;
}>
> {
return this.postPrivate('0/private/CancelAllOrdersAfter', {
body: params,
});
}
/**
* Get Websockets Token
*
* An authentication token must be requested via this REST API endpoint in order to connect to and authenticate
* with the Websockets API. The token should be used within 15 minutes of creation.
*/
getWebSocketsToken(): Promise<
SpotAPISuccessResponse<SpotWebSocketsTokenResponse>
> {
return this.postPrivate('0/private/GetWebSocketsToken', { body: {} });
}
/**
* Add Order Batch
*
* Sends a collection of orders (minimum of 2 and maximum 15). All orders in batch are limited to a single pair.
* Validation is performed on the whole batch prior to submission. If an order fails validation, the whole batch will be rejected.
*/
submitBatchOrders(params: SpotSubmitOrderBatchParams): Promise<
SpotAPISuccessResponse<{
orders: SpotBatchOrderResult[];
}>
> {
return this.postPrivate('0/private/AddOrderBatch', {
body: params,
});
}
/**
* Cancel Order Batch
*
* Cancel multiple open orders by txid, userref or cl_ord_id (maximum 50 total unique IDs/references).
*/
cancelBatchOrders(params: {
orders?: Array<string | number>;
cl_ord_ids?: string[];
}): Promise<
SpotAPISuccessResponse<{
count: number;
}>
> {
return this.postPrivate('0/private/CancelOrderBatch', {
body: params,
});
}
/**
*
* Spot REST API - Funding
*
*/
/**
* Get Deposit Methods
*
* Retrieve methods available for depositing a particular asset.
*/
getDepositMethods(
params: SpotGetDepositMethodsParams,
): Promise<SpotAPISuccessResponse<SpotDepositMethod[]>> {
return this.postPrivate('0/private/DepositMethods', { body: params });
}
/**
* Get Deposit Addresses
*
* Retrieve (or generate a new) deposit addresses for a particular asset and method.
*/
getDepositAddresses(
params: SpotGetDepositAddressesParams,
): Promise<SpotAPISuccessResponse<SpotDepositAddress[]>> {
return this.postPrivate('0/private/DepositAddresses', { body: params });
}
/**
* Get Status of Recent Deposits
*
* Retrieve information about recent deposits. Results are sorted by recency.
*/
getDepositsStatus(
params?: SpotGetDepositStatusParams,
): Promise<SpotAPISuccessResponse<SpotDepositStatusResponse>> {
return this.postPrivate('0/private/DepositStatus', { body: params });
}
/**
* Get Withdrawal Methods
*
* Retrieve a list of withdrawal methods available for the user.
*/
getWithdrawalMethods(
params?: SpotGetWithdrawalMethodsParams,
): Promise<SpotAPISuccessResponse<SpotWithdrawalMethod[]>> {
return this.postPrivate('0/private/WithdrawMethods', { body: params });
}
/**
* Get Withdrawal Addresses
*
* Retrieve a list of withdrawal addresses available for the user.
*/
getWithdrawalAddresses(
params?: SpotGetWithdrawalAddressesParams,
): Promise<SpotAPISuccessResponse<SpotWithdrawalAddress[]>> {
return this.postPrivate('0/private/WithdrawAddresses', { body: params });
}
/**
* Get Withdrawal Information
*
* Retrieve fee information about potential withdrawals for a particular asset, key and amount.
*/
getWithdrawalInfo(
params: SpotGetWithdrawalInfoParams,
): Promise<SpotAPISuccessResponse<SpotWithdrawalInfo>> {
return this.postPrivate('0/private/WithdrawInfo', { body: params });
}
/**
* Withdraw Funds
*
* Make a withdrawal request.
*/
submitWithdrawal(params: SpotWithdrawFundsParams): Promise<
SpotAPISuccessResponse<{
refid: string;
}>
> {
return this.postPrivate('0/private/Withdraw', { body: params });
}
/**
* Get Status of Recent Withdrawals
*
* Retrieve information about recent withdrawals. Results are sorted by recency.
*/
getWithdrawalsStatus(
params?: SpotGetWithdrawalsStatusParams,
): Promise<SpotAPISuccessResponse<SpotWithdrawalStatus[]>> {
return this.postPrivate('0/private/WithdrawStatus', { body: params });
}
/**
* Request Withdrawal Cancellation
*
* Cancel a recently requested withdrawal, if it has not already been successfully processed.
*/
cancelWithdrawal(params: {
asset: string;
refid: string;
}): Promise<SpotAPISuccessResponse<boolean>> {
return this.postPrivate('0/private/WithdrawCancel', { body: params });
}
/**
* Request Wallet Transfer
*
* Transfer from a Kraken spot wallet to a Kraken Futures wallet.
* Note: Transfer in the other direction must be requested via the Kraken Futures API.
*/
submitTransferToFutures(params: SpotWalletTransferParams): Promise<
SpotAPISuccessResponse<{
refid: string;
}>
> {
return this.postPrivate('0/private/WalletTransfer', { body: params });
}
/**
*
* Subaccounts
*
*/
/**
* Create Subaccount
*
* Create a trading subaccount.
* Note: CreateSubaccount must be called using an API key from the master account.
*/
createSubaccount(params: {
username: string;
email: string;
}): Promise<SpotAPISuccessResponse<boolean>> {
return this.postPrivate('0/private/CreateSubaccount', { body: params });
}
/**
* Account Transfer
*
* Transfer funds to and from master and subaccounts.
* Note: AccountTransfer must be called using an API key from the master account.
*/
submitSubaccountTransfer(
params: SpotAccountTransferParams,
): Promise<SpotAPISuccessResponse<SpotAccountTransferResponse>> {
return this.postPrivate('0/private/AccountTransfer', { body: params });
}
/**
*
* Earn
*
*/
/**
* Allocate Earn Funds
*
* Allocate funds to the Strategy.
* This method is asynchronous. Use getAllocationStatus() to poll the result.
*/
allocateEarnFunds(params: {
amount: string;
strategy_id: string;
}): Promise<SpotAPISuccessResponse<boolean>> {
return this.postPrivate('0/private/Earn/Allocate', { body: params });
}
/**
* Deallocate Earn Funds
*
* Deallocate funds from a strategy.
* This method is asynchronous. Use getDeallocationStatus() to poll the result.
*/
deallocateEarnFunds(params: {
amount: string;
strategy_id: string;
}): Promise<SpotAPISuccessResponse<boolean>> {
return this.postPrivate('0/private/Earn/Deallocate', { body: params });
}
/**
* Get Allocation Status
*
* Get the status of the last allocation request.
*/
getEarnAllocationStatus(params: { strategy_id: string }): Promise<
SpotAPISuccessResponse<{
pending: boolean;
}>
> {
return this.postPrivate('0/private/Earn/AllocateStatus', { body: params });
}
/**
* Get Deallocation Status
*
* Get the status of the last deallocation request.
*/
getEarnDeallocationStatus(params: { strategy_id: string }): Promise<
SpotAPISuccessResponse<{
pending: boolean;
}>
> {
return this.postPrivate('0/private/Earn/DeallocateStatus', {
body: params,
});
}
/**
* List Earn Strategies
*
* List earn strategies along with their parameters.
* Returns only strategies that are available to the user based on geographic region.
*/
getEarnStrategies(params?: SpotListEarnStrategiesParams): Promise<
SpotAPISuccessResponse<{
items: SpotEarnStrategy[];
next_cursor?: string;
}>
> {
return this.postPrivate('0/private/Earn/Strategies', { body: params });
}
/**
* List Earn Allocations
*
* List all allocations for the user.
* By default all allocations are returned, even for strategies that have been used in the past and have zero balance now.
*/
getEarnAllocations(
params?: SpotListEarnAllocationsParams,
): Promise<SpotAPISuccessResponse<SpotListEarnAllocationsResponse>> {
return this.postPrivate('0/private/Earn/Allocations', { body: params });
}
/**
*
* Transparency
*
*/
/**
* Pre-Trade Data
*
* Returns the price levels in the order book with aggregated order quantities at each price level.
* The top 10 levels are returned for each trading pair.
*/
getPreTradeData(params: {
symbol: string;
}): Promise<SpotAPISuccessResponse<SpotPreTradeData>> {
return this.get('0/public/PreTrade', params);
}
/**
* Post-Trade Data
*
* Returns a list of trades on the spot exchange.
* If no filter parameters are specified, the last 1000 trades for all pairs are received.
*/
getPostTradeData(
params?: SpotGetPostTradeDataParams,
): Promise<SpotAPISuccessResponse<SpotPostTradeDataResponse>> {
return this.get('0/public/PostTrade', params);
}
/**
*
* Spot REST API - OAuth
*
*/
/**
* Get Access Token
*
* Retrieve the access token.
* Note: This endpoint uses Basic authentication (Authorization header with base64-encoded client credentials).
*/
getOAuthAccessToken(
params: OauthGetAccessTokenParams,
): Promise<OauthGetAccessTokenResponse> {
return this.post('oauth/token', { body: params });
}
/**
* Get User Info
*
* Returns the email address and IIBAN of the user.
* Note: Requires OAuth2 Bearer token. Scopes required: account.info:basic
*/
getOAuthUserInfo(): Promise<OauthGetUserInfoResponse> {
return this.getPrivate('oauth/userinfo');
}
/**
* Create Fast API Key
*
* Creates a Fast API key.
* Note: Requires OAuth2 Bearer token. Scopes required: account.fast-api-key:write
*/
createOAuthFastApiKey(
params: OauthCreateFastApiKeyParams,
): Promise<OauthCreateFastApiKeyResponse> {
return this.postPrivate('oauth/fast-api-key', { body: params });
}
/**
* Delete Fast API Key
*
* Deletes a Fast API key.
* Note: Requires OAuth2 Bearer token. Scopes required: account.fast-api-key:write
*/
deleteOAuthFastApiKey(params: {
api_key_name: string; // max 32 chars
}): Promise<{
result: boolean;
}> {
return this.deletePrivate('oauth/fast-api-key', { body: params });
}
/**
* Update Fast API Key
*
* Updates a Fast API key.
* Note: Requires OAuth2 Bearer token. Scopes required: account.fast-api-key:write
*/
updateOAuthFastApiKey(params: OauthUpdateFastApiKeyParams): Promise<{
result: boolean;
}> {
return this.putPrivate('oauth/fast-api-key', { body: params });
}
/**
* List Fast API Keys
*
* List all Fast API keys.
* Note: Requires OAuth2 Bearer token. Scopes required: account.fast-api-key:read
*/
listOAuthFastApiKeys(): Promise<{
result: OauthFastApiKey[];
}> {
return this.getPrivate('oauth/fast-api-keys');
}
}