-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.ts
5546 lines (5056 loc) · 178 KB
/
index.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
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
/**** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*** *
** _ _ _ _ *
* _ __ ___ __| | ___ | | ___ __ __ _| | _____ _ __ __ _ _ __ (_)*
*| '_ \ / _ \ / _` |/ _ \___| |/ / '__/ _` | |/ / _ \ '_ \ ___ / _` | '_ \| |*
*| | | | (_) | (_| | __/___| <| | | (_| | < __/ | | |___| (_| | |_) | |*
*|_| |_|\___/ \__,_|\___| |_|\_\_| \__,_|_|\_\___|_| |_| \__,_| .__/|_|*
* |_| *
* @link http://github.com/jpcx/node-kraken-api *
* *
* @license MIT *
* @copyright 2018-2022 @author Justin Collier <m@jpcx.dev> *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER **
* DEALINGS IN THE SOFTWARE. ***
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ****/
import { URLSearchParams } from "url";
import * as http from "http";
import * as https from "https";
import { Emitter } from "ts-ev";
import { crc32 } from "crc";
import crypto from "crypto";
import WebSocket from "ws";
/* constants {*/
/** Our user agent for REST request. */
export const _USER_AGENT = "node-kraken-api/2.2.2";
/** REST server hostname. */
export const _REST_HOSTNAME = "api.kraken.com";
/** WS public server hostname. */
export const _WS_PUB_HOSTNAME = "ws.kraken.com";
/** WS private server hostname. */
export const _WS_PRIV_HOSTNAME = "ws-auth.kraken.com";
/** REST server version. */
export const _REST_VERSION = "0";
/**
* Generates a unique number based on the current millisecond time.
* Guarantees that each number generated is greater than the last.
*/
export const _GENNONCE = (() => {
let prev = -1;
let next = -1;
return Object.freeze(() => {
next = Date.now();
if (next <= prev) next = prev + 1;
prev = next;
return next;
});
})();
/* constants }*/
/**
* Create a new node-kraken-api instance.
*
* @example
* // Create the API (key and secret optional)
* const kraken = new Kraken({ key: "...", secret: "..." });
*
* // REST API
*
* const { unixtime, rfc1123 } = await kraken.time();
* const { XXBT } = await kraken.balance();
*
* // note: all response properties are typed according to the documentation
* // but are listed as optional; they are not verified by this library.
*
* // WebSocket API
*
* // Subscribe to pair publications
*
* const ticker = await kraken.ws.ticker()
* .on("update", (update, pair) => console.log(update, pair))
* .on("error", (error, pair) => console.log(error, pair))
* .on("status", (status) => console.log(status)
* .subscribe("XBT/USD")
*
* // Subscribe to book publications
*
* const book = kraken.ws.book({ depth: 10 })
* // live book construction from "snapshot", "ask", and "bid" events.
* .on("mirror", (mirror, pair) => console.log(mirror, pair))
* .on("error", (error, pair) => console.log(error, pair))
* // resubscribes if there is a checksum validation issue (emits statuses).
* .on("status", (status) => console.log(status)
* .subscribe("XBT/USD", "ETH/USD"); // subscribe to multiple pairs at once
*
* // Subscribe to user publications (requires token)
*
* const { token } = await kraken.getWebSocketsToken();
*
* const ownTrades = await kraken.ws.ownTrades({ token: token! })
* .on("update", (update, sequence) => console.log(update, sequence))
* .on("error", (error) => console.log(error))
* .on("status", (status) => console.log(status)
* .subscribe()
*
* // make a private WS request
* await kraken.ws.cancelAll({ token });
*
* // unsubscribe from an existing subscription
* await book.unsubscribe("XBT/USD", "ETH/USD"); // specify some or all pairs
* await ownTrades.unsubscribe();
*/
export class Kraken {
private _gennonce: () => number;
private _auth: _Authenticator | null;
/** @deprecated */
private _legacy = _Legacy.Settings.defaults();
public timeout: number;
constructor({
key,
secret,
genotp,
gennonce = _GENNONCE,
timeout = 1000,
/** @deprecated */
pubMethods,
/** @deprecated */
privMethods,
/** @deprecated */
parse,
/** @deprecated */
dataFormatter,
}: Readonly<
{
/** REST API key. */
key?: string;
/** REST API secret. */
secret?: string;
/** REST API OTP generator. */
genotp?: () => string;
/**
* Nonce generator (the default is ms time with an incrementation guarantee).
* Note: Some other APIs use a spoofed microsecond time. If you are using an
* API key used by one of those APIs then you will need to use a custom
* nonce generator (e.g. () => Date.now() * 1000). See _GENNONCE for the
* default generation logic.
*/
gennonce?: () => number;
/** Connection timeout (default 1000). */
timeout?: number;
} & _Legacy.Settings
> = {}) {
/*· {*/
// verify settings
if (key && !secret) {
throw new Kraken.SettingsError("Key provided without secret");
}
if (!key && secret) {
throw new Kraken.SettingsError("Secret provided without key");
}
if (genotp && !key && !secret) {
throw new Kraken.SettingsError("OTPGen provided without key or secret");
}
if (timeout <= 0) {
throw new Kraken.SettingsError("Timeout must be > 0");
}
this.timeout = timeout;
this._gennonce = gennonce;
this._auth = key && secret ? new _Authenticator(key, secret, genotp) : null;
if (pubMethods) this._legacy.pubMethods = pubMethods;
if (privMethods) this._legacy.privMethods = privMethods;
if (parse) this._legacy.parse = parse;
if (dataFormatter) this._legacy.dataFormatter = dataFormatter;
_hidePrivates(this);
/*· }*/
}
/* Manual REST Requests {*/
/**
* Perform a manual REST request.
* See the named methods below for typed options and responses.
*/
public request(
endpoint: string,
options: NodeJS.Dict<any> | null = null,
type: "public" | "private" = "public",
encoding: "utf8" | "binary" = "utf8"
): Promise<any> {
return _request(endpoint, options, type, encoding, this.timeout, this._gennonce, this._auth);
}
/** @deprecated legacy request function */
public call(method: any, options?: any, cb?: (err: any, data: any) => any): any {
/*· {*/
let type: "public" | "private";
if (this._legacy.pubMethods.includes(method)) {
type = "public";
} else if (this._legacy.privMethods.includes(method)) {
type = "private";
} else {
throw Error(`Bad method: ${method}. See documentation and check settings.`);
}
const onceresponse = new Promise(async (resolve, reject) => {
try {
const res = _Legacy.parseNested(
await this.request(method, options || null, type, "utf8"),
this._legacy.parse
);
if (this._legacy.dataFormatter) {
resolve(this._legacy.dataFormatter(method, options, res));
} else {
resolve(res);
}
} catch (e) {
reject(e);
}
});
if (cb) {
onceresponse.then((data) => cb(null, data)).catch((err) => cb(err, null));
} else {
return onceresponse;
}
/*· }*/
}
/* Manual REST Requests }*/
/* REST API {*/
/**
* Get the server's time.
*/
public time(): Promise<Kraken.Time> {
return this.request("Time");
}
/**
* Get the current system status or trading mode.
*/
public systemStatus(): Promise<Kraken.SystemStatus> {
return this.request("SystemStatus");
}
/**
* Get information about the assets that are available for deposit, withdrawal, trading and staking.
*/
public assets(options?: {
/*· {*/
/**
* Comma delimited list of assets to get info on.
* @example "XBT,ETH".
*/
asset?: string;
/**
* Asset class. (optional, default: `currency`).
* @example "currency".
*/
aclass?: string;
/*· }*/
}): Promise<Kraken.Assets> {
return this.request("Assets", options);
}
/**
* Get tradable asset pairs
*/
public assetPairs(options?: {
/*· {*/
/**
* Asset pairs to get data for.
* @example "XXBTCZUSD,XETHXXBT".
*/
pair?: string;
/**
* Info to retrieve. (optional)
* * `info` = all info
* * `leverage` = leverage info
* * `fees` = fees schedule
* * `margin` = margin info
* @default "info".
*/
info?: string;
/*· }*/
}): Promise<Kraken.AssetPairs> {
return this.request("AssetPairs", options);
}
/**
* Note: Today's prices start at midnight UTC
*/
public ticker(options: {
/*· {*/
/**
* Asset pair to get data for.
* @example "XBTUSD".
*/
pair: string;
/*· }*/
}): Promise<Kraken.Ticker> {
return this.request("Ticker", options);
}
/**
* Note: the last entry in the OHLC array is for the current, not-yet-committed frame and will always be present, regardless of the value of `since`.
*/
public ohlc(options: {
/*· {*/
/**
* Asset pair to get data for.
* @example "XBTUSD".
*/
pair: string;
/**
* Time frame interval in minutes.
* @default 1.
* @example 60.
*/
interval?: number;
/**
* Return committed OHLC data since given ID.
* @example 1548111600.
*/
since?: number;
/*· }*/
}): Promise<Kraken.OHLC> {
return this.request("OHLC", options);
}
/**
* Get Order Book
*/
public depth(options: {
/*· {*/
/**
* Asset pair to get data for.
* @example "XBTUSD".
*/
pair: string;
/**
* maximum number of asks/bids.
* @default 100.
* @example 2.
*/
count?: number;
/*· }*/
}): Promise<Kraken.Depth> {
return this.request("Depth", options);
}
/**
* Returns the last 1000 trades by default
*/
public trades(options: {
/*· {*/
/**
* Asset pair to get data for.
* @example "XBTUSD".
*/
pair: string;
/**
* Return trade data since given timestamp.
* @example "1616663618".
*/
since?: string;
/*· }*/
}): Promise<Kraken.Trades> {
return this.request("Trades", options);
}
/**
* Get Recent Spreads
*/
public spread(options: {
/*· {*/
/**
* Asset pair to get data for.
* @example "XBTUSD".
*/
pair: string;
/**
* Return spread data since given ID.
* @example 1548122302.
*/
since?: number;
/*· }*/
}): Promise<Kraken.Spread> {
return this.request("Spread", options);
}
/**
* An authentication token must be requested via this REST API endpoint in order to connect to and authenticate with our [Websockets API](https://docs.kraken.com). The token should be used within 15 minutes of creation, but it does not expire once a successful Websockets connection and private subscription has been made and is maintained.
* > The 'Access WebSockets API' permission must be enabled for the API key in order to generate the authentication token.
*/
public getWebSocketsToken(): Promise<Kraken.GetWebSocketsToken> {
return this.request("GetWebSocketsToken", null, "private");
}
/**
* Retrieve all cash balances, net of pending withdrawals.
*/
public balance(): Promise<Kraken.Balance> {
return this.request("Balance", null, "private");
}
/**
* Retrieve a summary of collateral balances, margin position valuations, equity and margin level.
*/
public tradeBalance(options?: {
/*· {*/
/**
* Base asset used to determine balance.
* @default "ZUSD".
*/
asset?: string;
/*· }*/
}): Promise<Kraken.TradeBalance> {
return this.request("TradeBalance", options, "private");
}
/**
* Retrieve information about currently open orders.
*/
public openOrders(options?: {
/*· {*/
/**
* Whether or not to include trades related to position in output.
*/
trades?: boolean;
/**
* Restrict results to given user reference id.
*/
userref?: number;
/*· }*/
}): Promise<Kraken.OpenOrders> {
return this.request("OpenOrders", options, "private");
}
/**
* Retrieve information about orders that have been closed (filled or cancelled). 50 results are returned at a time, the most recent by default.
* **Note:** If an order's tx ID is given for `start` or `end` time, the order's opening time (`opentm`) is used
*/
public closedOrders(options?: {
/*· {*/
/**
* Whether or not to include trades related to position in output.
*/
trades?: boolean;
/**
* Restrict results to given user reference id.
*/
userref?: number;
/**
* Starting unix timestamp or order tx ID of results (exclusive).
*/
start?: number;
/**
* Ending unix timestamp or order tx ID of results (inclusive).
*/
end?: number;
/**
* Result offset for pagination.
*/
ofs?: number;
/**
* Which time to use to search.
* @default "both".
*/
closetime?: string;
/*· }*/
}): Promise<Kraken.ClosedOrders> {
return this.request("ClosedOrders", options, "private");
}
/**
* Retrieve information about specific orders.
*/
public queryOrders(options: {
/*· {*/
/**
* Whether or not to include trades related to position in output.
*/
trades?: boolean;
/**
* Restrict results to given user reference id.
*/
userref?: number;
/**
* Comma delimited list of transaction IDs to query info about (20 maximum).
*/
txid: string;
/*· }*/
}): Promise<Kraken.QueryOrders> {
return this.request("QueryOrders", options, "private");
}
/**
* Retrieve information about trades/fills. 50 results are returned at a time, the most recent by default.
* * Unless otherwise stated, costs, fees, prices, and volumes are specified with the precision for the asset pair (`pair_decimals` and `lot_decimals`), not the individual assets' precision (`decimals`).
*/
public tradesHistory(options?: {
/*· {*/
/**
* Type of trade.
* @default "all".
*/
type?: string;
/**
* Whether or not to include trades related to position in output.
*/
trades?: boolean;
/**
* Starting unix timestamp or trade tx ID of results (exclusive).
*/
start?: number;
/**
* Ending unix timestamp or trade tx ID of results (inclusive).
*/
end?: number;
/**
* Result offset for pagination.
*/
ofs?: number;
/*· }*/
}): Promise<Kraken.TradesHistory> {
return this.request("TradesHistory", options, "private");
}
/**
* Retrieve information about specific trades/fills.
*/
public queryTrades(options?: {
/*· {*/
/**
* Comma delimited list of transaction IDs to query info about (20 maximum).
*/
txid?: string;
/**
* Whether or not to include trades related to position in output.
*/
trades?: boolean;
/*· }*/
}): Promise<Kraken.QueryTrades> {
return this.request("QueryTrades", options, "private");
}
/**
* Get information about open margin positions.
*/
public openPositions(options?: {
/*· {*/
/**
* Comma delimited list of txids to limit output to.
*/
txid?: string;
/**
* Whether to include P&L calculations.
*/
docalcs?: boolean;
/**
* Consolidate positions by market/pair.
*/
consolidation?: string;
/*· }*/
}): Promise<Kraken.OpenPositions> {
return this.request("OpenPositions", options, "private");
}
/**
* Retrieve information about ledger entries. 50 results are returned at a time, the most recent by default.
*/
public ledgers(options?: {
/*· {*/
/**
* Comma delimited list of assets to restrict output to.
* @default "all".
*/
asset?: string;
/**
* Asset class.
* @default "currency".
*/
aclass?: string;
/**
* Type of ledger to retrieve.
* @default "all".
*/
type?: string;
/**
* Starting unix timestamp or ledger ID of results (exclusive).
*/
start?: number;
/**
* Ending unix timestamp or ledger ID of results (inclusive).
*/
end?: number;
/**
* Result offset for pagination.
*/
ofs?: number;
/*· }*/
}): Promise<Kraken.Ledgers> {
return this.request("Ledgers", options, "private");
}
/**
* Retrieve information about specific ledger entries.
*/
public queryLedgers(options?: {
/*· {*/
/**
* Comma delimited list of ledger IDs to query info about (20 maximum).
*/
id?: string;
/**
* Whether or not to include trades related to position in output.
*/
trades?: boolean;
/*· }*/
}): Promise<Kraken.QueryLedgers> {
return this.request("QueryLedgers", options, "private");
}
/**
* Note: If an asset pair is on a maker/taker fee schedule, the taker side is given in `fees` and maker side in `fees_maker`. For pairs not on maker/taker, they will only be given in `fees`.
*/
public tradeVolume(options: {
/*· {*/
/**
* Comma delimited list of asset pairs to get fee info on (optional).
*/
pair: string;
/**
* Whether or not to include fee info in results (optional).
*/
"fee-info"?: boolean;
/*· }*/
}): Promise<Kraken.TradeVolume> {
return this.request("TradeVolume", options, "private");
}
/**
* Request export of trades or ledgers.
*/
public addExport(options: {
/*· {*/
/**
* Type of data to export.
*/
report: string;
/**
* File format to export.
* @default "CSV".
*/
format?: string;
/**
* Description for the export.
*/
description: string;
/**
* Comma-delimited list of fields to include
* * `trades`: ordertxid, time, ordertype, price, cost, fee, vol, margin, misc, ledgers
* * `ledgers`: refid, time, type, aclass, asset, amount, fee, balance
* @default "all".
*/
fields?: string;
/**
* UNIX timestamp for report start time (default 1st of the current month).
*/
starttm?: number;
/**
* UNIX timestamp for report end time (default now).
*/
endtm?: number;
/*· }*/
}): Promise<Kraken.AddExport> {
return this.request("AddExport", options, "private");
}
/**
* Get status of requested data exports.
*/
public exportStatus(options: {
/*· {*/
/**
* Type of reports to inquire about.
*/
report: string;
/*· }*/
}): Promise<Kraken.ExportStatus> {
return this.request("ExportStatus", options, "private");
}
/**
* Retrieve a processed data export
*/
public retrieveExport(options: {
/*· {*/
/**
* Report ID to retrieve.
*/
id: string;
/*· }*/
}): Promise<Kraken.RetrieveExport> {
return this.request("RetrieveExport", options, "private", "binary");
}
/**
* Delete exported trades/ledgers report
*/
public removeExport(options: {
/*· {*/
/**
* ID of report to delete or cancel.
*/
id: string;
/**
* `delete` can only be used for reports that have already been processed. Use `cancel` for queued or processing reports.
*/
type: string;
/*· }*/
}): Promise<Kraken.RemoveExport> {
return this.request("RemoveExport", options, "private");
}
/**
* Place a new order.
* **Note**: See the [AssetPairs](#operation/getTradableAssetPairs) endpoint for details on the available trading pairs, their price and quantity precisions, order minimums, available leverage, etc.
*/
public addOrder(options: {
/*· {*/
/**
* User reference id
* `userref` is an optional user-specified integer id that can be associated with any number of orders. Many clients choose a `userref` corresponding to a unique integer id generated by their systems (e.g. a timestamp). However, because we don't enforce uniqueness on our side, it can also be used to easily group orders by pair, side, strategy, etc. This allows clients to more readily cancel or query information about orders in a particular group, with fewer API calls by using `userref` instead of our `txid`, where supported.
*/
userref?: number;
/**
* Order type
*/
ordertype: string;
/**
* Order direction (buy/sell).
*/
type: string;
/**
* Order quantity in terms of the base asset
* > Note: Volume can be specified as `0` for closing margin orders to automatically fill the requisite quantity.
*/
volume?: string;
/**
* Asset pair `id` or `altname`.
*/
pair: string;
/**
* Price
* * Limit price for `limit` orders
* * Trigger price for `stop-loss`, `stop-loss-limit`, `take-profit` and `take-profit-limit` orders
*/
price?: string;
/**
* Secondary Price
* * Limit price for `stop-loss-limit` and `take-profit-limit` orders
* > Note: Either `price` or `price2` can be preceded by `+`, `-`, or `#` to specify the order price as an offset relative to the last traded price. `+` adds the amount to, and `-` subtracts the amount from the last traded price. `#` will either add or subtract the amount to the last traded price, depending on the direction and order type used. Relative prices can be suffixed with a `%` to signify the relative amount as a percentage.
*/
price2?: string;
/**
* Amount of leverage desired (default = none)
*/
leverage?: string;
/**
* Comma delimited list of order flags
* * `post` post-only order (available when ordertype = limit)
* * `fcib` prefer fee in base currency (default if selling)
* * `fciq` prefer fee in quote currency (default if buying, mutually exclusive with `fcib`)
* * `nompp` disable [market price protection](https://support.kraken.com/hc/en-us/articles/201648183-Market-Price-Protection) for market orders
*/
oflags?: string;
/**
* Time-in-force of the order to specify how long it should remain in the order book before being cancelled. GTC (Good-'til-cancelled) is default if the parameter is omitted. IOC (immediate-or-cancel) will immediately execute the amount possible and cancel any remaining balance rather than resting in the book. GTD (good-'til-date), if specified, must coincide with a desired `expiretm`.
* @default "GTC".
*/
timeinforce?: string;
/**
* Scheduled start time. Can be specified as an absolute timestamp or as a number of seconds in the future.
* * `0` now (default)
* * `+<n>` schedule start time <n> seconds from now
* * `<n>` = unix timestamp of start time
*/
starttm?: string;
/**
* Expiration time
* * `0` no expiration (default)
* * `+<n>` = expire <n> seconds from now, minimum 5 seconds
* * `<n>` = unix timestamp of expiration time
*/
expiretm?: string;
/**
* Conditional close order type.
* > Note: [Conditional close orders](https://support.kraken.com/hc/en-us/articles/360038640052-Conditional-Close) are triggered by execution of the primary order in the same quantity and opposite direction, but once triggered are __independent orders__ that may reduce or increase net position.
*/
"close[ordertype]"?: string;
/**
* Conditional close order `price`
*/
"close[price]"?: string;
/**
* Conditional close order `price2`
*/
"close[price2]"?: string;
/**
* Validate inputs only. Do not submit order.
*/
validate?: boolean;
/*· }*/
}): Promise<Kraken.AddOrder> {
return this.request("AddOrder", options, "private");
}
/**
* Cancel a particular open order (or set of open orders) by `txid` or `userref`
*/
public cancelOrder(options: {
/*· {*/
/**
* Open order transaction ID (txid) or user reference (userref).
*/
txid: string | number;
/*· }*/
}): Promise<Kraken.CancelOrder> {
return this.request("CancelOrder", options, "private");
}
/**
* Cancel all open orders
*/
public cancelAll(): Promise<Kraken.CancelAll> {
return this.request("CancelAll", null, "private");
}
/**
* 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. The client has to keep sending new requests to push back the trigger time, or deactivate the mechanism by specifying a timeout of 0. If the timer expires, all orders are cancelled and then the timer remains disabled until the client provides a new (non-zero) timeout.
* The recommended use is to make a call every 15 to 30 seconds, providing a timeout of 60 seconds. This allows the client to keep the orders in place in case of a brief disconnection or transient delay, while keeping them safe in case of a network breakdown. It is also recommended to disable the timer ahead of regularly scheduled trading engine maintenance (if the timer is enabled, all orders will be cancelled when the trading engine comes back from downtime - planned or otherwise).
*/
public cancelAllOrdersAfter(options: {
/*· {*/
/**
* Duration (in seconds) to set/extend the timer by.
*/
timeout: number;
/*· }*/
}): Promise<Kraken.CancelAllOrdersAfter> {
return this.request("CancelAllOrdersAfter", options, "private");
}
/**
* Retrieve methods available for depositing a particular asset.
*/
public depositMethods(options: {
/*· {*/
/**
* Asset being deposited.
*/
asset: string;
/*· }*/
}): Promise<Kraken.DepositMethods> {
return this.request("DepositMethods", options, "private");
}
/**
* Retrieve (or generate a new) deposit addresses for a particular asset and method.
*/
public depositAddresses(options: {
/*· {*/
/**
* Asset being deposited.
*/
asset: string;
/**
* Name of the deposit method.
*/
method: string;
/**
* Whether or not to generate a new address.
*/
new?: boolean;
/*· }*/
}): Promise<Kraken.DepositAddresses> {
return this.request("DepositAddresses", options, "private");
}
/**
* Retrieve information about recent deposits made.
*/
public depositStatus(options: {
/*· {*/
/**
* Asset being deposited.
*/
asset: string;
/**
* Name of the deposit method.
*/
method?: string;
/*· }*/
}): Promise<Kraken.DepositStatus> {
return this.request("DepositStatus", options, "private");
}
/**
* Retrieve fee information about potential withdrawals for a particular asset, key and amount.
*/
public withdrawInfo(options: {
/*· {*/
/**
* Asset being withdrawn.
*/
asset: string;
/**
* Withdrawal key name, as set up on your account.
*/
key: string;
/**
* Amount to be withdrawn.
*/