hollaex-node-lib 2.1.0 → 2.12.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/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "hollaex-node-lib",
3
- "version": "2.1.0",
3
+ "version": "2.12.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
- }
package/NETWORK_README.md DELETED
@@ -1,338 +0,0 @@
1
- # hollaex-node-lib
2
-
3
- Nodejs library for operators of HollaEx Kit enabled exchanges to connect to the HollaEx Network.
4
-
5
- ## Usage
6
-
7
- ```javascript
8
- const { Network } = require('hollaex-node-lib');
9
-
10
- const client = new Network({
11
- apiKey: '<MY_API_KEY>',
12
- apiSecret: '<MY_API_SECRET>'
13
- activation_code: '<MY_ACTIVATION_CODE>'
14
- });
15
- ```
16
- You must pass your `apiKey`, `apiSecret`, and `activation_code` generated for your HollaEx-Enabled exchange. If you know your exchange's ID, pass the field `exchange_id`.
17
-
18
- You can also pass the field `apiExpiresAfter` which is the length of time in seconds each request is valid for. The default value is `60`.
19
-
20
- ### Example:
21
-
22
- ```javascript
23
- const client = new Network({
24
- apiKey: '<MY_API_KEY>',
25
- apiSecret: '<MY_API_SECRET>'
26
- activation_code: '<MY_ACTIVATION_CODE>'
27
- });
28
-
29
- client
30
- .init()
31
- .then((res) => {
32
- console.log('Exchange info: ', res);
33
- })
34
- .catch((err) => {
35
- console.log(err);
36
- });
37
-
38
- client
39
- .getPublicTrades({ symbol: 'xht-usdt' })
40
- .then((res) => {
41
- console.log('Public trades: ', res);
42
- })
43
- .catch((err) => {
44
- console.log(err);
45
- });
46
- ```
47
-
48
- ### Available functions:
49
-
50
- - **Optional parameters are all contained within an object parameter called `opts`**
51
-
52
- | Command | Parameters | Description |
53
- | - | - | - |
54
- | `init`| | Initialize your Kit for HollaEx Network. Must have passed activation_code in constructor |
55
- | `getTicker` | **symbol** | Last, high, low, open and close price and volume within the last 24 hours |
56
- | `getTickers` | | Last, high, low, open and close price and volume within the last 24 hours for all symbols |
57
- | `getOrderbook` | **symbol** | Orderbook containing list of bids and asks |
58
- | `getOrderbooks` | | Orderbook containing list of bids and asks for all symbols |
59
- | `getPublicTrades` | **symbol** (_optional_) | List of last trades |
60
- | `getTradesHistory` | **symbol** (_optional_), **side** (_optional_), **limit** (_optional_, _default_=`50`, _max_=`100`), **page** (_optional_, _default_=`1`), **orderBy** (_optional_, _default_=`id`), **order** (_optional_, _default_=`asc`, `asc` or `desc`), **startDate** (_optional_, _default_=`0`, _format_=`ISO8601`), **endDate** (_optional_, _default_=`NOW`, _format_=`ISO8601`) | List of trades in paginated form |
61
- | `getGeneratedFees` | **startDate** (_optional_, _default_=`0`, _format_=`ISO8601`), **endDate** (_optional_, _default_=`NOW`, _format_=`ISO8601`) | List of generated fees for the exchange |
62
- | `settleFees` | | Settle exchange's fees |
63
- | `getUser` | **userId** (_optional_) | User's personal information |
64
- | `getUsers` | | Get all user's for your exchange |
65
- | `createUser` | **email** (_optional_) | Create a user on the Network |
66
- | `getBalance` | | Exchange's wallet balance |
67
- | `getUserBalance` | **userId** | User's wallet balance |
68
- | `createUserCryptoAddress` | **userId**, **crypto**, **network** (_optional_) | Create a crypto address for a user |
69
- | `mintAsset` | **userId**, **currency**, **amount**, **description** (_optional_), **transactionId** (_optional_), **status** (_optional_, _default_=`true`) | Mint an asset that is created by the operator for a user |
70
- | `updatePendingMint` | **transactionId**, **status** (_optional_), **dismissed** (_optional_), **rejected** (_optional_), **updatedTransactionId** (_optional_) | Update a pending mint |
71
- | `burnAsset` | **userId**, **currency**, **amount**, **description** (_optional_), **transactionId** (_optional_), **status** (_optional_, _default_=`true`) | Burn an asset that is created by the operator from a user |
72
- | `updatePendingBurn` | **transactionId**, **status** (_optional_), **dismissed** (_optional_), **rejected** (_optional_), **updatedTransactionId** (_optional_) | Update a pending burn |
73
- | `getDeposits` | **currency** (_optional_), **status** (_optional_), **dismissed** (_optional_), **rejected** (_optional_), **processing** (_optional_), **waiting** (_optional_), **limit** (_optional_, _default_=`50`, _max_=`100`), **page** (_optional_, _default_=`1`), **orderBy** (_optional_, _default_=`id`), **order** (_optional_, _default_=`asc`, `asc` or `desc`), **startDate** (_optional_, _default_=`0`, _format_=`ISO8601`), **endDate** (_optional_, _default_=`NOW`, _format_=`ISO8601`), **transactionId** (_optional_), **address** (_optional_) | Exchanges's list of all deposits |
74
- | `getUserDeposits` | **userId**, **currency** (_optional_), **status** (_optional_), **dismissed** (_optional_), **rejected** (_optional_), **processing** (_optional_), **waiting** (_optional_), **limit** (_optional_, _default_=`50`, _max_=`100`), **page** (_optional_, _default_=`1`), **orderBy** (_optional_, _default_=`id`), **order** (_optional_, _default_=`asc`, `asc` or `desc`), **startDate** (_optional_, _default_=`0`, _format_=`ISO8601`), **endDate** (_optional_, _default_=`NOW`, _format_=`ISO8601`), **transactionId** (_optional_), **address** (_optional_) | User's list of all deposits |
75
- | `getWithdrawals` | **currency** (_optional_), **status** (_optional_), **dismissed** (_optional_), **rejected** (_optional_), **processing** (_optional_), **waiting** (_optional_), **limit** (_optional_, _default_=`50`, _max_=`100`), **page** (_optional_, _default_=`1`), **orderBy** (_optional_, _default_=`id`), **order** (_optional_, _default_=`asc`, `asc` or `desc`), **startDate** (_optional_, _default_=`0`, _format_=`ISO8601`), **endDate** (_optional_, _default_=`NOW`, _format_=`ISO8601`), **transactionId** (_optional_), **address** (_optional_) | Exchange's list of all withdrawals |
76
- | `getUserWithdrawals` | **userId**, **currency** (_optional_), **limit** (_optional_, _default_=`50`, _max_=`100`), **page** (_optional_, _default_=`1`), **orderBy** (_optional_, _default_=`id`), **order** (_optional_, _default_=`asc`, `asc` or `desc`), **startDate** (_optional_, _default_=`0`, _format_=`ISO8601`), **endDate** (_optional_, _default_=`NOW`, _format_=`ISO8601`), **transactionId** (_optional_), **address** (_optional_) | User's list of all withdrawals |
77
- | `performWithdrawal` | **userId**, **address**, **currency**, **amount**, **network** (_optional_) | Create a withdrawal for an exchange's user on the network |
78
- | `cancelWithdrawal` | **userId**, **withdrawalId** | Cancel a pending withdrawal |
79
- | `checkTransaction` | **userId**, **transactionId**, **address**, **isTestnet** (_optional_) | Check transaction in network. Will update transaction status on Kit accordingly |
80
- | `transferAsset` | **senderId**, **receiverId**, **currency**, **amount**, **description** (_optional_), **email** (_optional_, _default_=`true`) | Transfer funds between two users |
81
- | `getTrades` | **symbol** (_optional_), **limit** (_optional_, _default_=`50`, _max_=`100`), **page** (_optional_, _default_=`1`), **orderBy** (_optional_, _default_=`id`), **order** (_optional_, _default_=`desc`, `asc` or `desc`), **startDate** (_optional_, _default_=`0`, _format_=`ISO8601`), **endDate** (_optional_, _default_=`NOW`, _format_=`ISO8601`) | Exchange's list of all trades |
82
- | `getUserTrades` | **userId**, **symbol** (_optional_), **limit** (_optional_, _default_=`50`, _max_=`100`), **page** (_optional_, _default_=`1`), **orderBy** (_optional_, _default_=`id`), **order** (_optional_, _default_=`desc`, `asc` or `desc`), **startDate** (_optional_, _default_=`0`, _format_=`ISO8601`), **endDate** (_optional_, _default_=`NOW`, _format_=`ISO8601`) | User's list of all trades |
83
- | `getUserStats` | **userId** | Get sum of user trades and its stats |
84
- | `getOrder` | **userId**, **orderId** | Get specific information about a certain order |
85
- | `getOrders` | **symbol** (_optional_), **side** (_optional_), **status** (_optional_), **limit** (_optional_, _default_=`50`, _max_=`100`), **page** (_optional_, _default_=`1`), **orderBy** (_optional_, _default_=`id`), **order** (_optional_, _default_=`desc`, _enum_=`asc`, `desc`), **startDate** (_optional_, _default_=`0`, _format_=`ISO8601`), **endDate** (_optional_, _default_=`NOW`, _format_=`ISO8601`) | Get the list of all orders for the exchange |
86
- | `getUserOrders` | **userId**, **symbol** (_optional_), **side** (_optional_), **status** (_optional_), **limit** (_optional_, _default_=`50`, _max_=`100`), **page** (_optional_, _default_=`1`), **orderBy** (_optional_, _default_=`id`), **order** (_optional_, _default_=`desc`, _enum_=`asc`, `desc`), **startDate** (_optional_, _default_=`0`, _format_=`ISO8601`), **endDate** (_optional_, _default_=`NOW`, _format_=`ISO8601`) | Get the list of all orders for a user |
87
- | `createOrder` | **userId**, **symbol**, **side** (`buy` or `sell`), **size**, **type** (`market` or `limit`), **price**, **feeData** (object with `fee_structure` and `fee_coin`, `fee_structure` is an object with `maker` and `taker` fee percentages and is required), **stop** (_optional_), **meta** (_optional_, object with optional properties e.g. `post_only`) | Create a new order |
88
- | `cancelOrder` | **userId**, **orderId** | Cancel a specific order with its ID |
89
- | `cancelAllOrders` | **userId**, **symbol** (_optional_) | Cancel all open order. It can be filtered by passing the symbol |
90
- | `getPublicTrades` | **symbol** (_optional_) | Get public trades on Network |
91
- | `getChart` | **from**, **to**, **symbol**, **resolution** | Get TradingView trade history HOLCV |
92
- | `getCharts` | **from**, **to**, **resolution** | Get TradingView trade history HOLCV for all pairs |
93
- | `getUdfConfig` | | Get TradingView udf config |
94
- | `getUdfHistory` | **from**, **to**, **symbol**, **resolution** | Get TradingView udf history HOLCV |
95
- | `getUdfSymbols` | **symbol** | Get TradingView udf symbols |
96
- | `getOraclePrices` | **assets** (an array of assets to get converted prices), **quote** (_optional_, _default_=`usdt`), **amount** (_optional_, _default_=`1`) | Get converted quote amount for an asset |
97
-
98
- ### Websocket
99
-
100
- #### Functions
101
-
102
- You can connect and subscribe to different websocket channels for realtime updates.
103
-
104
- To connect, use the `connect` function with the channels you want to subscribe to in an array as the parameter. The connection will reconnect on it's own unless you call `disconnect`.
105
-
106
- ```javascript
107
- client.connect(['orderbook', 'trade']);
108
- ```
109
-
110
- To disconnect the websocket, call `disconnect`.
111
-
112
- ```javascript
113
- client.disconnect();
114
- ```
115
-
116
- To subscribe to more channels after connection, use `subscribe`.
117
-
118
- ```javascript
119
- client.subscribe(['order:1', 'wallet:1']);
120
- ```
121
-
122
- To unsubscribe from channels after connection, use `unsubscribe`.
123
-
124
- ```javascript
125
- client.unsubscribe(['orderbook']);
126
- ```
127
-
128
- #### Channels
129
-
130
- Here is the list of channels you can subscribe to:
131
-
132
- - `orderbook`
133
- - `trades`
134
- - `order` (Only available with authentication. Receive order updates for a user of your exchange)
135
- - `wallet` (Only available with authentication. Receive balance updates for a user of your exchange)
136
-
137
- For public channels (`orderbook`, `trade`), you can subscribe to specific symbols as follows:
138
- `orderbook:xht-usdt`, `trade:xht-usdt`. Not passing a symbol will subscribe to all symbols.
139
-
140
- For private channels (`order`, `trade`), you must also pass the user's ID on the HollaEx Network as follows:
141
- `order:1`, `wallet:23`. Not passing an ID will give an error.
142
-
143
- #### Events
144
-
145
- After connecting to the websocket, you can listen for events coming from the server by using the `on` function for the `ws` property of the client.
146
- The events available are default websocket events e.g. `message`, `open`, `close`, `error`, `unexpected-response`, etc.
147
-
148
- ```javascript
149
- client.ws.on('message', (data) => {
150
- data = JSON.parse(data);
151
- console.log(data);
152
- });
153
- ```
154
-
155
- These are exapmles of data responses from the server.
156
-
157
- - **orderbook**: Updates related to the user's private information are as follows:
158
-
159
- ```json
160
- {
161
- "topic": "orderbook",
162
- "action": "partial",
163
- "symbol": "xht-usdt",
164
- "data": {
165
- "bids": [
166
- [0.1, 0.1],
167
- ...
168
- ],
169
- "asks": [
170
- [1, 1],
171
- ...
172
- ],
173
- "timestamp": "2020-12-15T06:45:27.766Z"
174
- },
175
- "time": 1608015328
176
- }
177
- ```
178
-
179
- - **trade**: Updates related to the user's private information are as follows:
180
-
181
- ```json
182
- {
183
- "topic": "trade",
184
- "action": "partial",
185
- "symbol": "xht-usdt",
186
- "data": [
187
- {
188
- "size": 0.012,
189
- "price": 300,
190
- "side": "buy",
191
- "timestamp": "2020-12-15T07:25:28.887Z"
192
- },
193
- ...
194
- ],
195
- "time": 1608015328
196
- }
197
- ```
198
-
199
- - **wallet**: Updates related to the user's private information are as follows:
200
-
201
- ```json
202
- {
203
- "topic": "wallet",
204
- "action": "partial",
205
- "user_id": 1,
206
- "data": {
207
- "usdt_balance": 1,
208
- "usdt_available": 1,
209
- "xht_balance": 1,
210
- "xht_available": 1,
211
- "xmr_balance": 1,
212
- "xmr_available": 1,
213
- "btc_balance": 1,
214
- "btc_available": 1,
215
- "eth_balance": 1,
216
- "eth_available": 1,
217
- ...,
218
- "updated_at": "2020-12-15T08:41:24.048Z"
219
- },
220
- "time": 1608021684
221
- }
222
- ```
223
-
224
- - **order**: Websocket messages relating the the user's orders.
225
- - The `status` of the order can be `new`, `pfilled`, `filled`, and `canceled`.
226
- - The `action` of the data determines what caused it to happen. All three are explained below:
227
-
228
- - `partial`: All previous and current orders. Is the first order data received when connecting. Max: 50. Descending order.
229
-
230
- ```json
231
- {
232
- "topic": "order",
233
- "action": "partial",
234
- "user_id": 1,
235
- "data": [
236
- {
237
- "id": "7d3d9545-b7e6-4e7f-84a0-a39efa4cb173",
238
- "side": "buy",
239
- "symbol": "xht-usdt",
240
- "type": "limit",
241
- "size": 0.1,
242
- "filled": 0,
243
- "price": 1,
244
- "stop": null,
245
- "status": "new",
246
- "fee": 0,
247
- "fee_coin": "xht",
248
- "meta": {},
249
- "fee_structure": {
250
- "maker": 0.1,
251
- "taker": 0.1
252
- },
253
- "created_at": "2020-11-30T07:45:43.819Z",
254
- "created_by": 1
255
- },
256
- ...
257
- ],
258
- "time": 1608022610
259
- }
260
- ```
261
-
262
- - `insert`: When user's order is added. The status of the order can be either `new`, `pfilled`, or `filled`.
263
-
264
- ```json
265
- {
266
- "topic": "order",
267
- "action": "insert",
268
- "user_id": 1,
269
- "symbol": "xht-usdt",
270
- "data": [
271
- {
272
- "id": "7d3d9545-b7e6-4e7f-84a0-a39efa4cb173",
273
- "side": "buy",
274
- "symbol": "xht-usdt",
275
- "type": "limit",
276
- "size": 0.1,
277
- "filled": 0,
278
- "price": 1,
279
- "stop": null,
280
- "status": "new",
281
- "fee": 0,
282
- "fee_coin": "xht",
283
- "meta": {},
284
- "fee_structure": {
285
- "maker": 0.1,
286
- "taker": 0.1
287
- },
288
- "created_at": "2020-11-30T07:45:43.819Z",
289
- "updated_at": "2020-12-15T08:56:45.066Z",
290
- "created_by": 1
291
- },
292
- ...
293
- ],
294
- "time": 1608022610
295
- }
296
- ```
297
-
298
- - `update`: When user's order status is updated. Status can be `pfilled`, `filled`, and `canceled`.
299
-
300
- ```json
301
- {
302
- "topic": "order",
303
- "action": "insert",
304
- "user_id": 1,
305
- "symbol": "xht-usdt",
306
- "data": [
307
- {
308
- "id": "7d3d9545-b7e6-4e7f-84a0-a39efa4cb173",
309
- "side": "buy",
310
- "symbol": "xht-usdt",
311
- "type": "limit",
312
- "size": 0.1,
313
- "filled": 0,
314
- "price": 1,
315
- "stop": null,
316
- "status": "new",
317
- "fee": 0,
318
- "fee_coin": "xht",
319
- "meta": {},
320
- "fee_structure": {
321
- "maker": 0.1,
322
- "taker": 0.1
323
- },
324
- "created_at": "2020-11-30T07:45:43.819Z",
325
- "updated_at": "2020-12-15T08:56:45.066Z",
326
- "created_by": 1
327
- },
328
- ...
329
- ],
330
- "time": 1608022610
331
- }
332
- ```
333
-
334
- ## Documentation
335
-
336
- For adding additional functionalities simply go to index.js and add more features.
337
- You can read more about api documentation at https://apidocs.hollaex.com
338
- You should create your token on the platform in setting->api keys
package/example/ws.js DELETED
@@ -1,164 +0,0 @@
1
- const { Network } = require('../index');
2
- const { random } = require('lodash');
3
- // require('dotenv').load();
4
-
5
- const API_KEY = 'test';
6
- const API_SECRET = 'test';
7
- const client = new Network({ apiKey: API_KEY, apiSecret: API_SECRET, activation_code: '123', exchange_id: 6 });
8
-
9
- client.connect(['orderbook']);
10
- let i = 1;
11
- client.ws.on('message', (data) => {
12
- console.log(i)
13
- i++
14
- console.log(data);
15
- });
16
-
17
- // client
18
- // .performWithdrawal(10093, '0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7', 'usdt', 0.01)
19
- // .then((data) => {
20
- // console.log(data);
21
- // })
22
- // .catch((err) => {
23
- // console.log(err);
24
- // });
25
-
26
- // client
27
- // // // .createUser('ali+1@bitholla.com')
28
- // // // .mintAsset(7, 'usdt', 2000, { description: 'test' })
29
- // .createOrder(
30
- // 8,
31
- // 'xht-usdt',
32
- // 'sell',
33
- // 0.1, 'limit', 0.1,
34
- // {
35
- // fee_structure: {
36
- // maker: 0,
37
- // taker: 0
38
- // },
39
- // fee_coin: 'abc'
40
- // },
41
-
42
- // )
43
- // // .cancelAllOrders(8)
44
- // .then((data) => {
45
- // console.log(data);
46
- // })
47
- // .catch((err) => {
48
- // console.log(err);
49
- // });
50
-
51
-
52
- /*
53
- for (let i = 0; i< 500 ; i++) {
54
- let side = 'buy';
55
- if (random(0 ,1) > 0.5) {
56
- side = 'sell';
57
- }
58
- client
59
- // .createUser('ali+1@bitholla.com')
60
- // .mintAsset(7, 'usdt', 2000, { description: 'test' })
61
- .createOrder(
62
- 7,
63
- 'btc-usdt',
64
- side,
65
- random(0.0001, 0.001), 'limit', Number(random(40000, 50000).toFixed(3)),
66
- {
67
- fee_structure: {
68
- maker: 0,
69
- taker: 0
70
- },
71
- fee_coin: 'abc'
72
- },
73
-
74
- )
75
- // .cancelAllOrders(8)
76
- .then((data) => {
77
- console.log(data);
78
- })
79
- .catch((err) => {
80
- console.log(err);
81
- });
82
-
83
- client
84
- // .createUser('ali+1@bitholla.com')
85
- // .mintAsset(7, 'usdt', 2000, { description: 'test' })
86
- .createOrder(
87
- 7,
88
- 'eth-btc',
89
- side,
90
- random(0.0001, 0.001), 'limit', Number(random(0.01, 0.000001).toFixed(3)),
91
- {
92
- fee_structure: {
93
- maker: 0,
94
- taker: 0
95
- },
96
- fee_coin: 'abc'
97
- },
98
-
99
- )
100
- // .cancelAllOrders(8)
101
- .then((data) => {
102
- console.log(data);
103
- })
104
- .catch((err) => {
105
- console.log(err);
106
- });
107
- if (random(0 ,1) > 0.5) {
108
- side = 'buy';
109
- }
110
- client
111
- // .createUser('ali+1@bitholla.com')
112
- // .mintAsset(7, 'usdt', 2000, { description: 'test' })
113
- .createOrder(
114
- 8,
115
- 'xht-usdt',
116
- side,
117
- random(1, 100), 'limit', Number(random(0.1, 0.2).toFixed(3)),
118
- {
119
- fee_structure: {
120
- maker: 0,
121
- taker: 0
122
- },
123
- fee_coin: 'abc'
124
- },
125
-
126
- )
127
- // .cancelAllOrders(7)
128
- .then((data) => {
129
- console.log(data);
130
- })
131
- .catch((err) => {
132
- console.log(err);
133
- });
134
-
135
- }
136
-
137
- // connect to websocket
138
- /*
139
- events (emitted) : trades (trades), orderbook (orderbook), user (userInfo, userWallet, userOrder, userTrades, userUpdate), all
140
-
141
- symbols : xht-usdt
142
- */
143
-
144
- // const socket1 = client.connect('trades:xht-usdt');
145
-
146
- // socket1.on('trades', (data) => {
147
- // console.log(data);
148
- // });
149
-
150
- // const socket2 = client.connect('all');
151
-
152
- // socket2.on('orderbook', (data) => {
153
- // console.log(data);
154
- // });
155
-
156
- // // You have to use a token to use these otherwise the socket disconnects
157
- // socket2.on('userInfo', (data) => {
158
- // console.log(data);
159
- // });
160
-
161
-
162
- // setTimeout(() => {
163
- // socket2.disconnect();
164
- // }, 5000);