hollaex-node-lib 2.1.0 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/kit.js CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  const WebSocket = require('ws');
4
4
  const moment = require('moment');
5
- const { createRequest, createSignature, generateHeaders } = require('./utils');
5
+ const { createRequest, createSignature, generateHeaders, isDatetime, sanitizeDate } = require('./utils');
6
6
  const { setWsHeartbeat } = require('ws-heartbeat/client');
7
7
  const { each, union, isNumber, isString, isPlainObject, isBoolean } = require('lodash');
8
-
9
8
  class HollaExKit {
10
9
  constructor(
11
10
  opts = {
@@ -178,10 +177,10 @@ class HollaExKit {
178
177
  * @param {boolean} opts.waiting - Waiting status of the deposits to get. Leave blank to get all waiting and unwaiting deposits
179
178
  * @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
180
179
  * @param {number} opts.page - Page of trades data. Default: 1
181
- * @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
182
- * @param {string} opts.order - Ascending (asc) or descending (desc). Default: asc
183
- * @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
184
- * @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
180
+ * @param {string} opts.orderBy - The field to order data by e.g. amount, id.
181
+ * @param {string} opts.order - Ascending (asc) or descending (desc).
182
+ * @param {string} opts.startDate - Start date of query in ISO8601 format.
183
+ * @param {string} opts.endDate - End date of query in ISO8601 format.
185
184
  * @param {string} opts.transactionId - Deposits with specific transaction ID.
186
185
  * @param {string} opts.address - Deposits with specific address.
187
186
  * @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))
@@ -194,12 +193,12 @@ class HollaExKit {
194
193
  rejected: null,
195
194
  processing: null,
196
195
  waiting: null,
197
- limit: 50,
198
- page: 1,
199
- orderBy: 'id',
200
- order: 'asc',
201
- startDate: 0,
202
- endDate: moment().toISOString(),
196
+ limit: null,
197
+ page: null,
198
+ orderBy: null,
199
+ order: null,
200
+ startDate: null,
201
+ endDate: null,
203
202
  transactionId: null,
204
203
  address: null
205
204
  }
@@ -227,12 +226,12 @@ class HollaExKit {
227
226
  path += `&order=${opts.order}`;
228
227
  }
229
228
 
230
- if (isString(opts.startDate)) {
231
- path += `&start_date=${opts.startDate}`;
229
+ if (isDatetime(opts.startDate)) {
230
+ path += `&start_date=${sanitizeDate(opts.startDate)}`;
232
231
  }
233
232
 
234
- if (isString(opts.endDate)) {
235
- path += `&end_date=${opts.endDate}`;
233
+ if (isDatetime(opts.endDate)) {
234
+ path += `&end_date=${sanitizeDate(opts.endDate)}`;
236
235
  }
237
236
 
238
237
  if (isString(opts.address)) {
@@ -285,10 +284,10 @@ class HollaExKit {
285
284
  * @param {boolean} opts.waiting - Waiting status of the withdrawals to get. Leave blank to get all waiting and unwaiting withdrawals
286
285
  * @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
287
286
  * @param {number} opts.page - Page of trades data. Default: 1
288
- * @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
289
- * @param {string} opts.order - Ascending (asc) or descending (desc). Default: asc
290
- * @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
291
- * @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
287
+ * @param {string} opts.orderBy - The field to order data by e.g. amount, id.
288
+ * @param {string} opts.order - Ascending (asc) or descending (desc).
289
+ * @param {string} opts.startDate - Start date of query in ISO8601 format.
290
+ * @param {string} opts.endDate - End date of query in ISO8601 format.
292
291
  * @param {string} opts.transactionId - Withdrawals with specific transaction ID.
293
292
  * @param {string} opts.address - Withdrawals with specific address.
294
293
  * @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))
@@ -301,12 +300,12 @@ class HollaExKit {
301
300
  rejected: null,
302
301
  processing: null,
303
302
  waiting: null,
304
- limit: 50,
305
- page: 1,
306
- orderBy: 'id',
307
- order: 'asc',
308
- startDate: 0,
309
- endDate: moment().toISOString(),
303
+ limit: null,
304
+ page: null,
305
+ orderBy: null,
306
+ order: null,
307
+ startDate: null,
308
+ endDate: null,
310
309
  transactionId: null,
311
310
  address: null
312
311
  }
@@ -334,12 +333,12 @@ class HollaExKit {
334
333
  path += `&order=${opts.order}`;
335
334
  }
336
335
 
337
- if (isString(opts.startDate)) {
338
- path += `&start_date=${opts.startDate}`;
336
+ if (isDatetime(opts.startDate)) {
337
+ path += `&start_date=${sanitizeDate(opts.startDate)}`;
339
338
  }
340
339
 
341
- if (isString(opts.endDate)) {
342
- path += `&end_date=${opts.endDate}`;
340
+ if (isDatetime(opts.endDate)) {
341
+ path += `&end_date=${sanitizeDate(opts.endDate)}`;
343
342
  }
344
343
 
345
344
  if (isString(opts.address)) {
@@ -381,31 +380,25 @@ class HollaExKit {
381
380
  }
382
381
 
383
382
  /**
384
- * Make a withdrawal request
383
+ * Make a withdrawal
385
384
  * @param {string} currency - The currency to withdrawal
386
385
  * @param {number} amount - The amount of currency to withdrawal
387
386
  * @param {string} address - The recipient's wallet address
388
387
  * @param {object} opts - Optional parameters.
389
388
  * @param {string} opts.network - Crypto network of currency being withdrawn.
390
- * @param {string} opts.otpCode - Otp code for user if otp is enabled.
391
389
  * @return {object} A JSON object {message:"Success"}
392
390
  */
393
- requestWithdrawal(currency, amount, address, opts = {
391
+ makeWithdrawal(currency, amount, address, opts = {
394
392
  network: null,
395
- otpCode: null
396
393
  }) {
397
394
  const verb = 'POST';
398
- const path = `${this.baseUrl}/user/request-withdrawal`;
395
+ const path = `${this.baseUrl}/user/withdrawal`;
399
396
  const data = {
400
397
  currency,
401
398
  amount,
402
399
  address
403
400
  };
404
401
 
405
- if (opts.network) {
406
- data.otp_code = opts.otpCode;
407
- }
408
-
409
402
  if (opts.network) {
410
403
  data.network = opts.network;
411
404
  }
@@ -418,30 +411,32 @@ class HollaExKit {
418
411
  this.apiExpiresAfter,
419
412
  data
420
413
  );
421
- return createRequest(verb, `${this.apiUrl}${path}`, headers, data);
414
+ return createRequest(verb, `${this.apiUrl}${path}`, headers, { data });
422
415
  }
423
416
 
424
417
  /**
425
418
  * Retrieve list of the user's completed trades
426
419
  * @param {object} opts - Optional parameters
427
420
  * @param {string} opts.symbol - The symbol-pair to filter by, pass undefined to receive data on all currencies
428
- * @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
429
- * @param {number} opts.page - Page of trades data. Default: 1
421
+ * @param {number} opts.limit - Amount of trades per page
422
+ * @param {number} opts.page - Page of trades data
430
423
  * @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
431
424
  * @param {string} opts.order - Ascending (asc) or descending (desc). Default: desc
432
- * @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
433
- * @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
425
+ * @param {string} opts.startDate - Start date of query in ISO8601 format
426
+ * @param {string} opts.endDate - End date of query in ISO8601 format
427
+ * @param {string} opts.format - Custom format of data set. Enum: ['all', 'csv']
434
428
  * @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))
435
429
  */
436
430
  getUserTrades(
437
431
  opts = {
438
432
  symbol: null,
439
- limit: 50,
440
- page: 1,
441
- orderBy: 'id',
442
- order: 'desc',
443
- startDate: 0,
444
- endDate: moment().toISOString()
433
+ limit: null,
434
+ page: null,
435
+ orderBy: null,
436
+ order: null,
437
+ startDate: null,
438
+ endDate: null,
439
+ format: null
445
440
  }
446
441
  ) {
447
442
  const verb = 'GET';
@@ -467,12 +462,16 @@ class HollaExKit {
467
462
  path += `&order=${opts.order}`;
468
463
  }
469
464
 
470
- if (isString(opts.startDate)) {
471
- path += `&start_date=${opts.startDate}`;
465
+ if (isDatetime(opts.startDate)) {
466
+ path += `&start_date=${sanitizeDate(opts.startDate)}`;
467
+ }
468
+
469
+ if (isDatetime(opts.endDate)) {
470
+ path += `&end_date=${sanitizeDate(opts.endDate)}`;
472
471
  }
473
472
 
474
- if (isString(opts.endDate)) {
475
- path += `&end_date=${opts.endDate}`;
473
+ if (isString(opts.format)) {
474
+ path += `&format=${opts.format}`;
476
475
  }
477
476
 
478
477
  const headers = generateHeaders(
@@ -482,6 +481,7 @@ class HollaExKit {
482
481
  path,
483
482
  this.apiExpiresAfter
484
483
  );
484
+
485
485
  return createRequest(verb, `${this.apiUrl}${path}`, headers);
486
486
  }
487
487
 
@@ -510,10 +510,10 @@ class HollaExKit {
510
510
  * @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
511
511
  * @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
512
512
  * @param {number} opts.page - Page of trades data. Default: 1
513
- * @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
514
- * @param {string} opts.order - Ascending (asc) or descending (desc). Default: desc
515
- * @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
516
- * @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
513
+ * @param {string} opts.orderBy - The field to order data by e.g. amount, id.
514
+ * @param {string} opts.order - Ascending (asc) or descending (desc).
515
+ * @param {string} opts.startDate - Start date of query in ISO8601 format.
516
+ * @param {string} opts.endDate - End date of query in ISO8601 format.
517
517
  * @return {object} A JSON array of objects containing the user's active orders
518
518
  */
519
519
  getOrders(
@@ -522,12 +522,12 @@ class HollaExKit {
522
522
  side: null,
523
523
  status: null,
524
524
  open: null,
525
- limit: 50,
526
- page: 1,
527
- orderBy: 'id',
528
- order: 'desc',
529
- startDate: 0,
530
- endDate: moment().toISOString()
525
+ limit: null,
526
+ page: null,
527
+ orderBy: null,
528
+ order: null,
529
+ startDate: null,
530
+ endDate: null
531
531
  }
532
532
  ) {
533
533
  const verb = 'GET';
@@ -565,12 +565,12 @@ class HollaExKit {
565
565
  path += `&order=${opts.order}`;
566
566
  }
567
567
 
568
- if (isString(opts.startDate)) {
569
- path += `&start_date=${opts.startDate}`;
568
+ if (isDatetime(opts.startDate)) {
569
+ path += `&start_date=${sanitizeDate(opts.startDate)}`;
570
570
  }
571
571
 
572
- if (isString(opts.endDate)) {
573
- path += `&end_date=${opts.endDate}`;
572
+ if (isDatetime(opts.endDate)) {
573
+ path += `&end_date=${sanitizeDate(opts.endDate)}`;
574
574
  }
575
575
 
576
576
  const headers = generateHeaders(
@@ -593,6 +593,8 @@ class HollaExKit {
593
593
  * @param {object} opts - Optional parameters
594
594
  * @param {number} opts.stop - Stop order price
595
595
  * @param {object} opts.meta - Additional meta parameters in an object
596
+ * @param {boolean} opts.meta.post_only - Whether or not the order should only be made if market maker.
597
+ * @param {string} opts.meta.note - Additional note to add to order data.
596
598
  * @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)
597
599
  */
598
600
  createOrder(
@@ -626,7 +628,7 @@ class HollaExKit {
626
628
  this.apiExpiresAfter,
627
629
  data
628
630
  );
629
- return createRequest(verb, `${this.apiUrl}${path}`, headers, data);
631
+ return createRequest(verb, `${this.apiUrl}${path}`, headers, { data });
630
632
  }
631
633
 
632
634
  /**
@@ -648,19 +650,17 @@ class HollaExKit {
648
650
  }
649
651
 
650
652
  /**
651
- * Cancel all the user's active orders, can filter by currency pair symbol
652
- * @param {object} opts - Optional parameters
653
- * @param {string} opts.symbol - The currency pair symbol to filter by e.g. 'hex-usdt', leave empty to cancel orders of all symbols
653
+ * Cancel all the active orders of a user, filtered by currency pair symbol
654
+ * @param {string} symbol - The currency pair symbol to filter by e.g. 'hex-usdt'
654
655
  * @return {array} A JSON array of objects containing the cancelled orders
655
656
  */
656
- cancelAllOrders(opts = { symbol: null }) {
657
- const verb = 'DELETE';
658
- let path = `${this.baseUrl}/order/all`;
659
-
660
- if (isString(opts.symbol)) {
661
- path += `?symbol=${opts.symbol}`;
657
+ cancelAllOrders(symbol) {
658
+ if (!isString(symbol)) {
659
+ throw new Error('You must provide a symbol to cancel all orders for');
662
660
  }
663
661
 
662
+ const verb = 'DELETE';
663
+ let path = `${this.baseUrl}/order/all?symbol=${symbol}`;
664
664
  const headers = generateHeaders(
665
665
  this.headers,
666
666
  this.apiSecret,
@@ -668,6 +668,7 @@ class HollaExKit {
668
668
  path,
669
669
  this.apiExpiresAfter
670
670
  );
671
+
671
672
  return createRequest(verb, `${this.apiUrl}${path}`, headers);
672
673
  }
673
674
 
@@ -782,38 +783,21 @@ class HollaExKit {
782
783
  if (!this.wsEvents.includes(event) || this.initialConnection) {
783
784
  const [topic, symbol] = event.split(':');
784
785
  switch (topic) {
785
- case 'orderbook':
786
- case 'trade':
787
- if (symbol) {
788
- if (!this.wsEvents.includes(topic)) {
789
- this.ws.send(
790
- JSON.stringify({
791
- op: 'subscribe',
792
- args: [`${topic}:${symbol}`]
793
- })
794
- );
795
- if (!this.initialConnection) {
796
- this.wsEvents = union(this.wsEvents, [event]);
797
- }
798
- }
799
- } else {
786
+ case 'orderbook':
787
+ case 'trade':
788
+ if (symbol) {
789
+ if (!this.wsEvents.includes(topic)) {
800
790
  this.ws.send(
801
791
  JSON.stringify({
802
792
  op: 'subscribe',
803
- args: [topic]
793
+ args: [`${topic}:${symbol}`]
804
794
  })
805
795
  );
806
796
  if (!this.initialConnection) {
807
- this.wsEvents = this.wsEvents.filter(
808
- (e) => !e.includes(`${topic}:`)
809
- );
810
797
  this.wsEvents = union(this.wsEvents, [event]);
811
798
  }
812
799
  }
813
- break;
814
- case 'order':
815
- case 'wallet':
816
- case 'deposit':
800
+ } else {
817
801
  this.ws.send(
818
802
  JSON.stringify({
819
803
  op: 'subscribe',
@@ -821,11 +805,28 @@ class HollaExKit {
821
805
  })
822
806
  );
823
807
  if (!this.initialConnection) {
808
+ this.wsEvents = this.wsEvents.filter(
809
+ (e) => !e.includes(`${topic}:`)
810
+ );
824
811
  this.wsEvents = union(this.wsEvents, [event]);
825
812
  }
826
- break;
827
- default:
828
- break;
813
+ }
814
+ break;
815
+ case 'order':
816
+ case 'wallet':
817
+ case 'deposit':
818
+ this.ws.send(
819
+ JSON.stringify({
820
+ op: 'subscribe',
821
+ args: [topic]
822
+ })
823
+ );
824
+ if (!this.initialConnection) {
825
+ this.wsEvents = union(this.wsEvents, [event]);
826
+ }
827
+ break;
828
+ default:
829
+ break;
829
830
  }
830
831
  }
831
832
  });
@@ -844,38 +845,38 @@ class HollaExKit {
844
845
  if (this.wsEvents.includes(event)) {
845
846
  const [topic, symbol] = event.split(':');
846
847
  switch (topic) {
847
- case 'orderbook':
848
- case 'trade':
849
- if (symbol) {
850
- this.ws.send(
851
- JSON.stringify({
852
- op: 'unsubscribe',
853
- args: [`${topic}:${symbol}`]
854
- })
855
- );
856
- } else {
857
- this.ws.send(
858
- JSON.stringify({
859
- op: 'unsubscribe',
860
- args: [topic]
861
- })
862
- );
863
- }
864
- this.wsEvents = this.wsEvents.filter((e) => e !== event);
865
- break;
866
- case 'order':
867
- case 'wallet':
868
- case 'deposit':
848
+ case 'orderbook':
849
+ case 'trade':
850
+ if (symbol) {
851
+ this.ws.send(
852
+ JSON.stringify({
853
+ op: 'unsubscribe',
854
+ args: [`${topic}:${symbol}`]
855
+ })
856
+ );
857
+ } else {
869
858
  this.ws.send(
870
859
  JSON.stringify({
871
860
  op: 'unsubscribe',
872
861
  args: [topic]
873
862
  })
874
863
  );
875
- this.wsEvents = this.wsEvents.filter((e) => e !== event);
876
- break;
877
- default:
878
- break;
864
+ }
865
+ this.wsEvents = this.wsEvents.filter((e) => e !== event);
866
+ break;
867
+ case 'order':
868
+ case 'wallet':
869
+ case 'deposit':
870
+ this.ws.send(
871
+ JSON.stringify({
872
+ op: 'unsubscribe',
873
+ args: [topic]
874
+ })
875
+ );
876
+ this.wsEvents = this.wsEvents.filter((e) => e !== event);
877
+ break;
878
+ default:
879
+ break;
879
880
  }
880
881
  }
881
882
  });
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "hollaex-node-lib",
3
- "version": "2.1.0",
3
+ "version": "2.14.0",
4
4
  "description": "hollaex api and websocket library for nodejs",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
+ "file-type": "16.5.2",
8
+ "is-base64": "1.1.0",
7
9
  "lodash": "4.17.13",
8
10
  "moment": "2.24.0",
9
11
  "request": "2.88.0",
@@ -15,19 +17,27 @@
15
17
  "chai": "4.2.0",
16
18
  "dotenv": "6.2.0",
17
19
  "eslint": "5.13.0",
18
- "mocha": "5.2.0",
19
- "prettier": "1.16.4"
20
+ "husky": "4.3.8",
21
+ "lint-staged": "12.1.3",
22
+ "mocha": "5.2.0"
20
23
  },
21
24
  "scripts": {
22
25
  "start": "node index.js",
23
26
  "test": "mocha test/test.js --timeout 10000",
24
- "prettier": "prettier --config .prettierrc.json --ignore-path .prettierignore.json --write \"./**/*.{js,json,css,scss,md}\"",
25
- "eslint": "eslint --config .eslintrc.json ./"
27
+ "lint": "eslint --fix ."
28
+ },
29
+ "husky": {
30
+ "hooks": {
31
+ "pre-commit": "lint-staged"
32
+ }
33
+ },
34
+ "lint-staged": {
35
+ "*.js": "eslint --fix"
26
36
  },
27
37
  "repository": {
28
38
  "type": "git",
29
39
  "url": "https://github.com/bitholla/hollaex-node-lib"
30
40
  },
31
41
  "author": "bitHolla Inc",
32
- "license": "ISC"
42
+ "license": "MIT"
33
43
  }
package/utils.js CHANGED
@@ -1,14 +1,23 @@
1
1
  const rp = require('request-promise');
2
2
  const crypto = require('crypto');
3
3
  const moment = require('moment');
4
+ const { isDate } = require('lodash');
4
5
 
5
- const createRequest = (verb, url, headers, data) => {
6
+ const createRequest = (verb, url, headers, opts = { data: null, formData: null }) => {
6
7
  const requestObj = {
7
8
  headers,
8
9
  url,
9
- body: data,
10
10
  json: true
11
11
  };
12
+
13
+ if (opts.data) {
14
+ requestObj.body = opts.data;
15
+ }
16
+
17
+ if (opts.formData) {
18
+ requestObj.formData = opts.formData;
19
+ }
20
+
12
21
  return rp[verb.toLowerCase()](requestObj);
13
22
  };
14
23
 
@@ -46,10 +55,31 @@ const parameterError = (parameter, msg) => {
46
55
  return new Error(`Parameter ${parameter} error: ${msg}`);
47
56
  };
48
57
 
58
+ const isDatetime = (date, formats = [ moment.ISO_8601 ]) => {
59
+ return moment(date, formats, true).isValid();
60
+ };
61
+
62
+ const sanitizeDate = (date) => {
63
+ let result = date;
64
+ if (isDate(result)) {
65
+ result = moment(result).toISOString();
66
+ }
67
+
68
+ return result;
69
+ };
70
+
71
+ const isUrl = (url) => {
72
+ const pattern = /^(^|\s)((http(s)?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)$/;
73
+ return pattern.test(url);
74
+ };
75
+
49
76
  module.exports = {
50
77
  createRequest,
51
78
  createSignature,
52
79
  generateHeaders,
53
80
  checkKit,
54
- parameterError
81
+ parameterError,
82
+ isDatetime,
83
+ sanitizeDate,
84
+ isUrl
55
85
  };
@@ -1 +0,0 @@
1
- {}
package/.prettierrc.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "tabWidth": 2,
3
- "useTabs": true,
4
- "semi": true,
5
- "singleQuote": true,
6
- "bracketSpacing": true,
7
- "arrowParens": "always"
8
- }