-
Notifications
You must be signed in to change notification settings - Fork 14
/
kit.js
2700 lines (2360 loc) · 70.8 KB
/
kit.js
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
'use strict';
const WebSocket = require('ws');
const moment = require('moment');
const { createRequest, createSignature, generateHeaders, isDatetime, sanitizeDate } = require('./utils');
const { setWsHeartbeat } = require('ws-heartbeat/client');
const { each, union, isNumber, isString, isPlainObject, isBoolean, isObject, isArray } = require('lodash');
class HollaExKit {
constructor(
opts = {
apiURL: 'https://api.hollaex.com',
baseURL: '/v2',
apiKey: '',
apiSecret: '',
apiExpiresAfter: 60
}
) {
this.apiUrl = opts.apiURL || 'https://api.hollaex.com';
this.baseUrl = opts.baseURL || '/v2';
this.apiKey = opts.apiKey;
this.apiSecret = opts.apiSecret;
this.apiExpiresAfter = opts.apiExpiresAfter || 60;
this.headers = {
'content-type': 'application/json',
Accept: 'application/json',
'api-key': opts.apiKey
};
this.ws = null;
const [protocol, endpoint] = this.apiUrl.split('://');
this.wsUrl = (
opts.wsURL
? opts.wsURL
: protocol === 'https'
? `wss://${endpoint}/stream`
: `ws://${endpoint}/stream`
);
this.wsEvents = [];
this.wsReconnect = true;
this.wsReconnectInterval = 5000;
this.wsEventListeners = null;
this.wsConnected = () => this.ws && this.ws.readyState === WebSocket.OPEN;
}
/* Public Endpoints*/
/**
* Get exchange information
* @return {object} A json object with the exchange information
*/
getKit() {
return createRequest(
'GET',
`${this.apiUrl}${this.baseUrl}/kit`,
this.headers
);
}
/**
* Retrieve last, high, low, open and close price and volume within last 24 hours for a symbol
* @param {string} symbol - The currency pair symbol e.g. 'hex-usdt'
* @return {object} A JSON object with keys high(number), low(number), open(number), close(number), volume(number), last(number)
*/
getTicker(symbol = '') {
return createRequest(
'GET',
`${this.apiUrl}${this.baseUrl}/ticker?symbol=${symbol}`,
this.headers
);
}
/**
* Retrieve last, high, low, open and close price and volume within last 24 hours for all symbols
* @return {object} A JSON object with symbols as keys which contain high(number), low(number), open(number), close(number), volume(number), last(number)
*/
getTickers() {
return createRequest(
'GET',
`${this.apiUrl}${this.baseUrl}/tickers`,
this.headers
);
}
/**
* Retrieve orderbook containing lists of up to the last 20 bids and asks for a symbol
* @param {string} symbol - The currency pair symbol e.g. 'hex-usdt'
* @return {object} A JSON object with keys bids(array of active buy orders), asks(array of active sell orders), and timestamp(string)
*/
getOrderbook(symbol = '') {
return createRequest(
'GET',
`${this.apiUrl}${this.baseUrl}/orderbook?symbol=${symbol}`,
this.headers
);
}
/**
* Retrieve orderbook containing lists of up to the last 20 bids and asks for all symbols
* @return {object} A JSON object with the symbol-pairs as keys where the values are objects with keys bids(array of active buy orders), asks(array of active sell orders), and timestamp(string)
*/
getOrderbooks() {
return createRequest(
'GET',
`${this.apiUrl}${this.baseUrl}/orderbooks`,
this.headers
);
}
/**
* Retrieve list of up to the last 50 trades
* @param {object} opts - Optional parameters
* @param {string} opts.symbol - The currency pair symbol e.g. 'hex-usdt'
* @return {object} A JSON object with the symbol-pairs as keys where the values are arrays of objects with keys size(number), price(number), side(string), and timestamp(string)
*/
getTrades(opts = { symbol: null }) {
let path = `${this.apiUrl}${this.baseUrl}/trades`;
if (isString(opts.symbol)) {
path += `?symbol=${opts.symbol}`;
}
return createRequest('GET', path, this.headers);
}
/**
* Retrieve tick size, min price, max price, min size, and max size of each symbol-pair
* @return {object} A JSON object with the keys pairs(information on each symbol-pair such as tick_size, min/max price, and min/max size) and currencies(array of all currencies involved in hollaEx)
*/
getConstants() {
return createRequest(
'GET',
`${this.apiUrl}${this.baseUrl}/constants`,
this.headers
);
}
/* Private Endpoints*/
/**
* Retrieve user's personal information
* @return {string} A JSON object showing user's information such as id, email, bank_account, crypto_wallet, balance, etc
*/
getUser() {
const verb = 'GET';
const path = `${this.baseUrl}/user`;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/**
* Retrieve user's wallet balance
* @return {object} A JSON object with the keys updated_at(string), usdt_balance(number), usdt_pending(number), usdt_available(number), hex_balance, hex_pending, hex_available, eth_balance, eth_pending, eth_available, bch_balance, bch_pending, bch_available
*/
getBalance() {
const verb = 'GET';
const path = `${this.baseUrl}/user/balance`;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/**
* Retrieve list of the user's deposits
* @param {object} opts - Optional parameters
* @param {string} opts.currency - The currency to filter by, pass undefined to receive data on all currencies
* @param {boolean} opts.status - Confirmed status of the deposits to get. Leave blank to get all confirmed and unconfirmed deposits
* @param {boolean} opts.dismissed - Dismissed status of the deposits to get. Leave blank to get all dismissed and undismissed deposits
* @param {boolean} opts.rejected - Rejected status of the deposits to get. Leave blank to get all rejected and unrejected deposits
* @param {boolean} opts.processing - Processing status of the deposits to get. Leave blank to get all processing and unprocessing deposits
* @param {boolean} opts.waiting - Waiting status of the deposits to get. Leave blank to get all waiting and unwaiting deposits
* @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
* @param {number} opts.page - Page of trades data. Default: 1
* @param {string} opts.orderBy - The field to order data by e.g. amount, id.
* @param {string} opts.order - Ascending (asc) or descending (desc).
* @param {string} opts.startDate - Start date of query in ISO8601 format.
* @param {string} opts.endDate - End date of query in ISO8601 format.
* @param {string} opts.transactionId - Deposits with specific transaction ID.
* @param {string} opts.address - Deposits with specific address.
* @return {object} A JSON object with the keys count(total number of user's deposits) and data(array of deposits as objects with keys id(number), type(string), amount(number), transaction_id(string), currency(string), created_at(string), status(boolean), fee(number), dismissed(boolean), rejected(boolean), description(string))
*/
getDeposits(
opts = {
currency: null,
status: null,
dismissed: null,
rejected: null,
processing: null,
waiting: null,
limit: null,
page: null,
orderBy: null,
order: null,
startDate: null,
endDate: null,
transactionId: null,
address: null
}
) {
const verb = 'GET';
let path = `${this.baseUrl}/user/deposits`;
let params = '?'
if (isString(opts.currency)) {
params += `¤cy=${opts.currency}`;
}
if (isNumber(opts.limit)) {
params += `&limit=${opts.limit}`;
}
if (isNumber(opts.page)) {
params += `&page=${opts.page}`;
}
if (isString(opts.orderBy)) {
params += `&order_by=${opts.orderBy}`;
}
if (isString(opts.order)) {
params += `&order=${opts.order}`;
}
if (isDatetime(opts.startDate)) {
params += `&start_date=${sanitizeDate(opts.startDate)}`;
}
if (isDatetime(opts.endDate)) {
params += `&end_date=${sanitizeDate(opts.endDate)}`;
}
if (isString(opts.address)) {
params += `&address=${opts.address}`;
}
if (isString(opts.transactionId)) {
params += `&transaction_id=${opts.transactionId}`;
}
if (isBoolean(opts.status)) {
params += `&status=${opts.status}`;
}
if (isBoolean(opts.dismissed)) {
params += `&dismissed=${opts.dismissed}`;
}
if (isBoolean(opts.rejected)) {
params += `&rejected=${opts.rejected}`;
}
if (isBoolean(opts.processing)) {
params += `&processing=${opts.processing}`;
}
if (isBoolean(opts.waiting)) {
params += `&waiting=${opts.waiting}`;
}
if (params.length > 1) path += params;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/****** Withdrawals ******/
/**
* Retrieve list of the user's withdrawals
* @param {object} opts - Optional parameters
* @param {string} opts.currency - The currency to filter by, pass undefined to receive data on all currencies
* @param {boolean} opts.status - Confirmed status of the withdrawals to get. Leave blank to get all confirmed and unconfirmed withdrawals
* @param {boolean} opts.dismissed - Dismissed status of the withdrawals to get. Leave blank to get all dismissed and undismissed withdrawals
* @param {boolean} opts.rejected - Rejected status of the withdrawals to get. Leave blank to get all rejected and unrejected withdrawals
* @param {boolean} opts.processing - Processing status of the withdrawals to get. Leave blank to get all processing and unprocessing withdrawals
* @param {boolean} opts.waiting - Waiting status of the withdrawals to get. Leave blank to get all waiting and unwaiting withdrawals
* @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
* @param {number} opts.page - Page of trades data. Default: 1
* @param {string} opts.orderBy - The field to order data by e.g. amount, id.
* @param {string} opts.order - Ascending (asc) or descending (desc).
* @param {string} opts.startDate - Start date of query in ISO8601 format.
* @param {string} opts.endDate - End date of query in ISO8601 format.
* @param {string} opts.transactionId - Withdrawals with specific transaction ID.
* @param {string} opts.address - Withdrawals with specific address.
* @return {object} A JSON object with the keys count(total number of user's withdrawals) and data(array of withdrawals as objects with keys id(number), type(string), amount(number), transaction_id(string), currency(string), created_at(string), status(boolean), fee(number), dismissed(boolean), rejected(boolean), description(string))
*/
getWithdrawals(
opts = {
currency: null,
status: null,
dismissed: null,
rejected: null,
processing: null,
waiting: null,
limit: null,
page: null,
orderBy: null,
order: null,
startDate: null,
endDate: null,
transactionId: null,
address: null
}
) {
const verb = 'GET';
let path = `${this.baseUrl}/user/withdrawals`;
let params = '?'
if (isString(opts.currency)) {
params += `¤cy=${opts.currency}`;
}
if (isNumber(opts.limit)) {
params += `&limit=${opts.limit}`;
}
if (isNumber(opts.page)) {
params += `&page=${opts.page}`;
}
if (isString(opts.orderBy)) {
params += `&order_by=${opts.orderBy}`;
}
if (isString(opts.order)) {
params += `&order=${opts.order}`;
}
if (isDatetime(opts.startDate)) {
params += `&start_date=${sanitizeDate(opts.startDate)}`;
}
if (isDatetime(opts.endDate)) {
params += `&end_date=${sanitizeDate(opts.endDate)}`;
}
if (isString(opts.address)) {
params += `&address=${opts.address}`;
}
if (isString(opts.transactionId)) {
params += `&transaction_id=${opts.transactionId}`;
}
if (isBoolean(opts.status)) {
params += `&status=${opts.status}`;
}
if (isBoolean(opts.dismissed)) {
params += `&dismissed=${opts.dismissed}`;
}
if (isBoolean(opts.rejected)) {
params += `&rejected=${opts.rejected}`;
}
if (isBoolean(opts.processing)) {
params += `&processing=${opts.processing}`;
}
if (isBoolean(opts.waiting)) {
params += `&waiting=${opts.waiting}`;
}
if (params.length > 1) path += params;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/**
* Make a withdrawal
* @param {string} currency - The currency to withdrawal
* @param {number} amount - The amount of currency to withdrawal
* @param {string} address - The recipient's wallet address
* @param {object} opts - Optional parameters.
* @param {string} opts.network - Crypto network of currency being withdrawn.
* @return {object} A JSON object {message:"Success"}
*/
makeWithdrawal(currency, amount, address, opts = {
network: null,
}) {
const verb = 'POST';
const path = `${this.baseUrl}/user/withdrawal`;
const data = {
currency,
amount,
address
};
if (opts.network) {
data.network = opts.network;
}
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter,
data
);
return createRequest(verb, `${this.apiUrl}${path}`, headers, { data });
}
/**
* Retrieve list of the user's completed trades
* @param {object} opts - Optional parameters
* @param {string} opts.symbol - The symbol-pair to filter by, pass undefined to receive data on all currencies
* @param {number} opts.limit - Amount of trades per page
* @param {number} opts.page - Page of trades data
* @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
* @param {string} opts.order - Ascending (asc) or descending (desc). Default: desc
* @param {string} opts.startDate - Start date of query in ISO8601 format
* @param {string} opts.endDate - End date of query in ISO8601 format
* @param {string} opts.format - Custom format of data set. Enum: ['all', 'csv']
* @return {object} A JSON object with the keys count(total number of user's completed trades) and data(array of up to the user's last 50 completed trades as objects with keys side(string), symbol(string), size(number), price(number), timestamp(string), and fee(number))
*/
getUserTrades(
opts = {
symbol: null,
limit: null,
page: null,
orderBy: null,
order: null,
startDate: null,
endDate: null,
format: null
}
) {
const verb = 'GET';
let path = `${this.baseUrl}/user/trades`;
let params = '?';
if (isString(opts.symbol)) {
params += `&symbol=${opts.symbol}`;
}
if (isNumber(opts.limit)) {
params += `&limit=${opts.limit}`;
}
if (isNumber(opts.page)) {
params += `&page=${opts.page}`;
}
if (isString(opts.orderBy)) {
params += `&order_by=${opts.orderBy}`;
}
if (isString(opts.order)) {
params += `&order=${opts.order}`;
}
if (isDatetime(opts.startDate)) {
params += `&start_date=${sanitizeDate(opts.startDate)}`;
}
if (isDatetime(opts.endDate)) {
params += `&end_date=${sanitizeDate(opts.endDate)}`;
}
if (isString(opts.format) && ['csv', 'all'].includes(opts.format)) {
params += `&format=${opts.format}`;
}
if (params.length > 1) path += params;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/****** Orders ******/
/**
* Retrieve information of a user's specific order
* @param {string} orderId - The id of the desired order
* @return {object} The selected order as a JSON object with keys created_at(string), title(string), symbol(string), side(string), size(number), type(string), price(number), id(string), created_by(number), filled(number)
*/
getOrder(orderId) {
const verb = 'GET';
const path = `${this.baseUrl}/order?order_id=${orderId}`;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/**
* Retrieve information of all the user's active orders
* @param {object} opts - Optional parameters
* @param {string} opts.symbol - The currency pair symbol to filter by e.g. 'hex-usdt', leave empty to retrieve information of orders of all symbols
* @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
* @param {number} opts.page - Page of trades data. Default: 1
* @param {string} opts.orderBy - The field to order data by e.g. amount, id.
* @param {string} opts.order - Ascending (asc) or descending (desc).
* @param {string} opts.startDate - Start date of query in ISO8601 format.
* @param {string} opts.endDate - End date of query in ISO8601 format.
* @return {object} A JSON array of objects containing the user's active orders
*/
getOrders(
opts = {
symbol: null,
side: null,
status: null,
open: null,
limit: null,
page: null,
orderBy: null,
order: null,
startDate: null,
endDate: null
}
) {
const verb = 'GET';
let path = `${this.baseUrl}/orders`;
let params = '?';
if (isString(opts.symbol)) {
params += `&symbol=${opts.symbol}`;
}
if (isString(opts.side) && (opts.side.toLowerCase() === 'buy' || opts.side.toLowerCase() === 'sell')) {
params += `&side=${opts.side}`;
}
if (isString(opts.status)) {
params += `&status=${opts.status}`;
}
if (isBoolean(opts.open)) {
params += `&open=${opts.open}`;
}
if (isNumber(opts.limit)) {
params += `&limit=${opts.limit}`;
}
if (isNumber(opts.page)) {
params += `&page=${opts.page}`;
}
if (isString(opts.orderBy)) {
params += `&order_by=${opts.orderBy}`;
}
if (isString(opts.order)) {
params += `&order=${opts.order}`;
}
if (isDatetime(opts.startDate)) {
params += `&start_date=${sanitizeDate(opts.startDate)}`;
}
if (isDatetime(opts.endDate)) {
params += `&end_date=${sanitizeDate(opts.endDate)}`;
}
if (params.length > 1) path += params;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/**
* Create a new order
* @param {string} symbol - The currency pair symbol e.g. 'hex-usdt'
* @param {string} side - The side of the order e.g. 'buy', 'sell'
* @param {number} size - The amount of currency to order
* @param {string} type - The type of order to create e.g. 'market', 'limit'
* @param {number} price - The price at which to order (only required if type is 'limit')
* @param {object} opts - Optional parameters
* @param {number} opts.stop - Stop order price
* @param {object} opts.meta - Additional meta parameters in an object
* @param {boolean} opts.meta.post_only - Whether or not the order should only be made if market maker.
* @param {string} opts.meta.note - Additional note to add to order data.
* @return {object} The new order as a JSON object with keys symbol(string), side(string), size(number), type(string), price(number), id(string), created_by(number), and filled(number)
*/
createOrder(
symbol,
side,
size,
type,
price = 0,
opts = {
stop: null,
meta: null
}
) {
const verb = 'POST';
const path = `${this.baseUrl}/order`;
const data = { symbol, side, size, type, price };
if (isPlainObject(opts.meta)) {
data.meta = opts.meta;
}
if (isNumber(opts.stop)) {
data.stop = opts.stop;
}
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter,
data
);
return createRequest(verb, `${this.apiUrl}${path}`, headers, { data });
}
/**
* Cancel a user's specific order
* @param {string} orderId - The id of the order to be cancelled
* @return {object} The cancelled order as a JSON object with keys symbol(string), side(string), size(number), type(string), price(number), id(string), created_by(number), and filled(number)
*/
cancelOrder(orderId) {
const verb = 'DELETE';
const path = `${this.baseUrl}/order?order_id=${orderId}`;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/**
* Cancel all the active orders of a user, filtered by currency pair symbol
* @param {string} symbol - The currency pair symbol to filter by e.g. 'hex-usdt'
* @return {array} A JSON array of objects containing the cancelled orders
*/
cancelAllOrders(symbol) {
if (!isString(symbol)) {
throw new Error('You must provide a symbol to cancel all orders for');
}
const verb = 'DELETE';
let path = `${this.baseUrl}/order/all?symbol=${symbol}`;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/**
* Retrieve price conversion
* @param {array} assets - Assets to convert
* @param {string} opts.quote - Quote coin to convert to
* @param {number} opts.amount - Amount to convert
* @return {object} A JSON object with conversion info
*/
getOraclePrice(
assets,
opts = {
quote: null,
amount: null
}
) {
const verb = 'GET';
let path = `${this.baseUrl}/oracle/prices`;
let params = '?';
if (isArray(assets)) {
params += `&assets=${assets}`;
}
if (isString(opts.quote)) {
params += `"e=${opts.quote}`;
}
if (isNumber(opts.amount)) {
params += `&amount=${opts.amount}`;
}
if (params.length > 1) path += params;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/**
* Get trade history HOLCV for all pairs
* @param {array} assets - The list of assets to get the mini charts for
* @param {string} opts.from - Start Date
* @param {string} opts.to - End data
* @param {string} opts.quote - Quote asset to receive prices based on
* @return {object} A JSON object with trade history info
*/
getMiniCharts(
assets,
opts = {
from: null,
to: null,
quote: null,
}
) {
const verb = 'GET';
let path = `${this.baseUrl}/minicharts`;
let params = '?';
if (isArray(assets)) {
params += `&assets=${opts.assets}`;
}
if (isString(opts.from)) {
params += `&from=${opts.from}`;
}
if (isString(opts.to)) {
params += `&to=${opts.to}`;
}
if (isString(opts.quote)) {
params += `"e=${opts.quote}`;
}
if (params.length > 1) path += params;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/**
* Get Quick Trade Quote
* @param {string} spending_currency - Currency symbol of the spending currency
* @param {string} receiving_currency - Currency symbol of the receiving currency
* @param {string} opts.spending_amount - Spending amount
* @param {string} opts.receiving_amount - Receiving amount
*/
getQuickTradeQuote(
spending_currency,
receiving_currency,
opts = {
spending_amount: null,
receiving_amount: null,
}
) {
const verb = 'GET';
let path = `${this.baseUrl}/quick-trade`;
let params = '?';
if (isString(spending_currency)) {
params += `&spending_currency=${spending_currency}`;
}
if (isString(receiving_currency)) {
params += `&receiving_currency=${receiving_currency}`;
}
if (isString(opts.spending_amount)) {
params += `&spending_amount=${opts.spending_amount}`;
}
if (isString(opts.receiving_amount)) {
params += `&receiving_amount=${opts.receiving_amount}`;
}
if (params.length > 1) path += params;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/**
* Execute Order
* @param {string} token - Token
*/
executeOrder(
token
) {
const verb = 'POST';
let path = `${this.baseUrl}/order/execute`;
const data = {
token
};
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter,
data
);
return createRequest(verb, `${this.apiUrl}${path}`, headers, { data });
}
/**
* Get admin exchange information
* @return {object} A json object with the admin exchange information
*/
getExchangeInfo() {
const verb = 'GET';
const path = `${this.baseUrl}/admin/exchange`;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/**
* Retrieve list of the user's deposits by admin
* @param {object} opts - Optional parameters
* @param {number} opts.userId - The identifier of the user to filter by
* @param {string} opts.currency - The currency to filter by, pass undefined to receive data on all currencies
* @param {number} opts.limit - Amount of deposits per page. Maximum: 50. Default: 50
* @param {number} opts.page - Page of deposit data. Default: 1
* @param {string} opts.orderBy - The field to order data by e.g. amount, id.
* @param {string} opts.order - Ascending (asc) or descending (desc).
* @param {string} opts.startDate - Start date of query in ISO8601 format.
* @param {string} opts.endDate - End date of query in ISO8601 format.
* @param {boolean} opts.status - Confirmed status of the deposits to get. Leave blank to get all confirmed and unconfirmed deposits
* @param {boolean} opts.dismissed - Dismissed status of the deposits to get. Leave blank to get all dismissed and undismissed deposits
* @param {boolean} opts.rejected - Rejected status of the deposits to get. Leave blank to get all rejected and unrejected deposits
* @param {boolean} opts.processing - Processing status of the deposits to get. Leave blank to get all processing and unprocessing deposits
* @param {boolean} opts.waiting - Waiting status of the deposits to get. Leave blank to get all waiting and unwaiting deposits
* @param {string} opts.transactionId - Deposits with specific transaction ID.
* @param {string} opts.address - Deposits with specific address.
* @param {string} opts.format - Custom format of data set. Enum: ['all', 'csv']
* @return {object} A JSON object with the keys count(total number of user's deposits) and data(array of deposits as objects with keys id(number), type(string), amount(number), transaction_id(string), currency(string), created_at(string), status(boolean), fee(number), dismissed(boolean), rejected(boolean), description(string))
*/
getExchangeDeposits(
opts = {
userId: null,
currency: null,
limit: null,
page: null,
orderBy: null,
order: null,
startDate: null,
endDate: null,
status: null,
dismissed: null,
rejected: null,
processing: null,
waiting: null,
transactionId: null,
address: null,
format: null
}
) {
const verb = 'GET';
let path = `${this.baseUrl}/admin/deposits`;
let params = '?';
if (isNumber(opts.userId)) {
params += `&user_id=${opts.userId}`;
}
if (isString(opts.currency)) {
params += `¤cy=${opts.currency}`;
}
if (isNumber(opts.limit)) {
params += `&limit=${opts.limit}`;
}
if (isNumber(opts.page)) {
params += `&page=${opts.page}`;
}
if (isString(opts.orderBy)) {
params += `&order_by=${opts.orderBy}`;
}
if (isString(opts.order) && (opts.order === 'asc' || opts.order === 'desc')) {
params += `&order=${opts.order}`;
}
if (isDatetime(opts.startDate)) {
params += `&start_date=${sanitizeDate(opts.startDate)}`;
}
if (isDatetime(opts.endDate)) {
params += `&end_date=${sanitizeDate(opts.endDate)}`;
}
if (isBoolean(opts.status)) {
params += `&status=${opts.status}`;
}
if (isBoolean(opts.dismissed)) {
params += `&dismissed=${opts.dismissed}`;
}
if (isBoolean(opts.rejected)) {
params += `&rejected=${opts.rejected}`;
}
if (isBoolean(opts.processing)) {
params += `&processing=${opts.processing}`;
}
if (isBoolean(opts.waiting)) {
params += `&waiting=${opts.waiting}`;
}
if (isString(opts.transactionId)) {
params += `&transaction_id=${opts.transactionId}`;
}
if (isString(opts.address)) {
params += `&address=${opts.address}`;
}
if (isString(opts.format) && ['csv', 'all'].includes(opts.format)) {
params += `&format=${opts.format}`;
}
if (params.length > 1) path += params;
const headers = generateHeaders(
this.headers,
this.apiSecret,
verb,
path,
this.apiExpiresAfter
);
return createRequest(verb, `${this.apiUrl}${path}`, headers);
}
/**
* Retrieve list of the user's withdrawals by admin
* @param {object} opts - Optional parameters
* @param {number} opts.userId - The identifier of the user to filter by
* @param {string} opts.currency - The currency to filter by, pass undefined to receive data on all currencies
* @param {boolean} opts.status - Confirmed status of the withdrawals to get. Leave blank to get all confirmed and unconfirmed withdrawals
* @param {boolean} opts.dismissed - Dismissed status of the withdrawals to get. Leave blank to get all dismissed and undismissed withdrawals
* @param {boolean} opts.rejected - Rejected status of the withdrawals to get. Leave blank to get all rejected and unrejected withdrawals
* @param {boolean} opts.processing - Processing status of the withdrawals to get. Leave blank to get all processing and unprocessing withdrawals
* @param {boolean} opts.waiting - Waiting status of the withdrawals to get. Leave blank to get all waiting and unwaiting withdrawals
* @param {number} opts.limit - Amount of withdrawals per page. Maximum: 50. Default: 50
* @param {number} opts.page - Page of withdrawal data. Default: 1
* @param {string} opts.orderBy - The field to order data by e.g. amount, id.
* @param {string} opts.order - Ascending (asc) or descending (desc).