hollaex-node-lib 2.15.3 → 2.16.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/README.md CHANGED
@@ -12,12 +12,15 @@ const hollaex = require('hollaex-node-lib');
12
12
  const client = new hollaex();
13
13
  ```
14
14
 
15
- You can pass the `apiURL` and `baseURL` of the HollaEx-Enabled exchange to connect to. You can also pass your `apiKey` and `apiSecret` generated from the HollaEx-Enabled exchange.
15
+ You can pass custom `apiURL`, `wsURL` and `baseURL` of the HollaEx-Enabled exchange to connect to. `apiURL` is `https://api.hollaex.com` for HollaEx Pro and for your custom exchange it would be something like `https://myexchange.com/api`.
16
+ `wsURL` is the websocket URL for the socket connection and you should pass your stream URL. For HollaEx Pro it is `wss://api.hollaex.com/stream` and for your exchange it would be something like `wss://myexchange.com/stream`. `baseURL` is not required and it is set by default to `/v2` unless you need to connect to an older version of HollaEx.
17
+
18
+ You can also pass your `apiKey` and `apiSecret` generated from the HollaEx-Enabled exchange to use private requests that require authentication. For public endpoints `apiKey` and `apiSecret` are not required.
16
19
 
17
20
  ```javascript
18
21
  const client = new hollaex({
19
22
  apiURL: '<EXCHANGE_API_URL>',
20
- baseURL: '<EXCHANGE_BASE_URL>',
23
+ wsURL: '<EXCHANGE_WS_URL>',
21
24
  apiKey: '<MY_API_KEY>',
22
25
  apiSecret: '<MY_API_SECRET>'
23
26
  });
@@ -30,7 +33,7 @@ You can also pass the field `apiExpiresAfter` which is the length of time in sec
30
33
  ```javascript
31
34
  const client = new hollaex({
32
35
  apiURL: '<EXCHANGE_API_URL>',
33
- baseURL: '<EXCHANGE_BASE_URL>',
36
+ wsURL: '<EXCHANGE_API_URL>',
34
37
  apiKey: '<MY_API_KEY>',
35
38
  apiSecret: '<MY_API_SECRET>'
36
39
  });
@@ -109,6 +112,7 @@ client
109
112
  | `getExchangeUserReferrer` | <ul><li>**userId**: The identifier of the user to filter by</li></ul> | Retrieve user's referer info by admin |
110
113
  | `sendExchangeUserEmail` | <ul><li>**userId**: The identifier of the user</li><li>**mailType**: The mail type for the email payload</li><li>**data**: The content of the mail</li></ul> | Send email to exchange user account by admin |
111
114
  | `sendRawEmail` | <ul><li>**receivers**: The array of emails to send mail</li><li>**html**: The stringified html content</li><li>**opts.title**: The title of the mail</li><li>**opts.text**: The text of the mail</li></ul> | Send email to users with custom html by admin |
115
+ | `getOraclePrice` | <ul><li>**assets**: Assets to convert</li><li>**opts.quote**: Quote coin to convert to</li><li>**opts.amount**: Amount to convert</li></ul> | Retrieve price conversion |
112
116
 
113
117
 
114
118
  ### Websocket
@@ -3,7 +3,13 @@ require('dotenv').load();
3
3
 
4
4
  const API_KEY = process.env.API_KEY || '';
5
5
  const API_SECRET = process.env.API_SECRET || '';
6
- const client = new HollaEx({ apiKey: API_KEY, apiSecret: API_SECRET });
6
+ const client = new HollaEx({
7
+ apiURL: 'https://api.hollaex.com',
8
+ wsURL: 'wss://api.hollaex.com/stream',
9
+ baseURL: '/v2',
10
+ apiKey: API_KEY,
11
+ apiSecret: API_SECRET
12
+ });
7
13
 
8
14
  client
9
15
  .getTicker('xht-usdt')
@@ -22,12 +28,12 @@ client
22
28
  symbols : xht-usdt
23
29
  */
24
30
 
25
- // client.connect(['orderbook']);
31
+ client.connect(['orderbook:xht-usdt']);
26
32
 
27
- // client.ws.on('message', (data) => {
28
- // data = JSON.parse(data);
29
- // console.log(data);
30
- // });
33
+ client.ws.on('message', (data) => {
34
+ data = JSON.parse(data);
35
+ console.log(data);
36
+ });
31
37
 
32
38
 
33
39
 
package/kit.js CHANGED
@@ -4,7 +4,7 @@ const WebSocket = require('ws');
4
4
  const moment = require('moment');
5
5
  const { createRequest, createSignature, generateHeaders, isDatetime, sanitizeDate } = require('./utils');
6
6
  const { setWsHeartbeat } = require('ws-heartbeat/client');
7
- const { each, union, isNumber, isString, isPlainObject, isBoolean, isObject, isArray } = require('lodash');
7
+ const { each, union, isNumber, isString, isPlainObject, isBoolean, isObject } = require('lodash');
8
8
  class HollaExKit {
9
9
  constructor(
10
10
  opts = {
@@ -27,10 +27,13 @@ class HollaExKit {
27
27
  };
28
28
  this.ws = null;
29
29
  const [protocol, endpoint] = this.apiUrl.split('://');
30
- this.wsUrl =
31
- protocol === 'https'
32
- ? `wss://${endpoint}/stream`
33
- : `ws://${endpoint}/stream`;
30
+ this.wsUrl = (
31
+ opts.wsURL
32
+ ? opts.wsURL
33
+ : protocol === 'https'
34
+ ? `wss://${endpoint}/stream`
35
+ : `ws://${endpoint}/stream`
36
+ );
34
37
  this.wsEvents = [];
35
38
  this.wsReconnect = true;
36
39
  this.wsReconnectInterval = 5000;
@@ -470,7 +473,7 @@ class HollaExKit {
470
473
  path += `&end_date=${sanitizeDate(opts.endDate)}`;
471
474
  }
472
475
 
473
- if (isString(opts.format)) {
476
+ if (isString(opts.format) && ['csv', 'all'].includes(opts.format)) {
474
477
  path += `&format=${opts.format}`;
475
478
  }
476
479
 
@@ -672,6 +675,44 @@ class HollaExKit {
672
675
  return createRequest(verb, `${this.apiUrl}${path}`, headers);
673
676
  }
674
677
 
678
+ /**
679
+ * Retrieve price conversion
680
+ * @param {array} assets - Assets to convert
681
+ * @param {string} opts.quote - Quote coin to convert to
682
+ * @param {number} opts.amount - Amount to convert
683
+ * @return {object} A JSON object with conversion info
684
+ */
685
+ getOraclePrice(
686
+ assets,
687
+ opts = {
688
+ quote: null,
689
+ amount: null
690
+ }
691
+ ) {
692
+ const verb = 'GET';
693
+ let path = `${this.baseUrl}/oracle/prices?`;
694
+
695
+ if (isArray(assets)) {
696
+ path += `&assets=${assets}`;
697
+ }
698
+
699
+ if (isString(opts.quote)) {
700
+ path += `&quote=${opts.quote}`;
701
+ }
702
+
703
+ if (isNumber(opts.amount)) {
704
+ path += `&amount=${opts.amount}`;
705
+ }
706
+
707
+ const headers = generateHeaders(
708
+ this.headers,
709
+ this.apiSecret,
710
+ verb,
711
+ path,
712
+ this.apiExpiresAfter
713
+ );
714
+ return createRequest(verb, `${this.apiUrl}${path}`, headers);
715
+ }
675
716
 
676
717
  /**
677
718
  * Get admin exchange information
@@ -795,7 +836,7 @@ class HollaExKit {
795
836
  path += `&address=${opts.address}`;
796
837
  }
797
838
 
798
- if (isString(opts.format) && opts.format === 'csv') {
839
+ if (isString(opts.format) && ['csv', 'all'].includes(opts.format)) {
799
840
  path += `&format=${opts.format}`;
800
841
  }
801
842
 
@@ -913,7 +954,7 @@ class HollaExKit {
913
954
  path += `&waiting=${opts.waiting}`;
914
955
  }
915
956
 
916
- if (isString(opts.format) && opts.format === 'csv') {
957
+ if (isString(opts.format) && ['csv', 'all'].includes(opts.format)) {
917
958
  path += `&format=${opts.format}`;
918
959
  }
919
960
 
@@ -1371,6 +1412,7 @@ class HollaExKit {
1371
1412
  orderBy: null,
1372
1413
  order: null,
1373
1414
  startDate: null,
1415
+ endDate: null,
1374
1416
  format: null
1375
1417
  }
1376
1418
  ) {
@@ -1405,11 +1447,11 @@ class HollaExKit {
1405
1447
  path += `&start_date=${sanitizeDate(opts.startDate)}`;
1406
1448
  }
1407
1449
 
1408
- if (isDatetime(opts.startDate)) {
1409
- path += `&end_date=${sanitizeDate(opts.startDate)}`;
1450
+ if (isDatetime(opts.endDate)) {
1451
+ path += `&end_date=${sanitizeDate(opts.endDate)}`;
1410
1452
  }
1411
1453
 
1412
- if (isString(opts.format) && opts.format === 'csv') {
1454
+ if (isString(opts.format) && ['csv', 'all'].includes(opts.format)) {
1413
1455
  path += `&format=${opts.format}`;
1414
1456
  }
1415
1457
 
@@ -1617,7 +1659,7 @@ class HollaExKit {
1617
1659
  path += `&end_date=${sanitizeDate(opts.endDate)}`;
1618
1660
  }
1619
1661
 
1620
- if (isString(opts.format) && opts.format === 'csv') {
1662
+ if (isString(opts.format) && ['csv', 'all'].includes(opts.format)) {
1621
1663
  path += `&format=${opts.format}`;
1622
1664
  }
1623
1665
 
@@ -1911,7 +1953,7 @@ class HollaExKit {
1911
1953
  path += `&end_date=${sanitizeDate(opts.endDate)}`;
1912
1954
  }
1913
1955
 
1914
- if (isString(opts.format) && opts.format === 'csv') {
1956
+ if (isString(opts.format) && ['csv', 'all'].includes(opts.format)) {
1915
1957
  path += `&format=${opts.format}`;
1916
1958
  }
1917
1959
 
@@ -2028,7 +2070,7 @@ class HollaExKit {
2028
2070
  path += `&end_date=${sanitizeDate(opts.endDate)}`;
2029
2071
  }
2030
2072
 
2031
- if (isString(opts.format) && opts.format === 'csv') {
2073
+ if (isString(opts.format) && ['csv', 'all'].includes(opts.format)) {
2032
2074
  path += `&format=${opts.format}`;
2033
2075
  }
2034
2076
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hollaex-node-lib",
3
- "version": "2.15.3",
3
+ "version": "2.16.0",
4
4
  "description": "hollaex api and websocket library for nodejs",
5
5
  "main": "index.js",
6
6
  "dependencies": {