hollaex-node-lib 1.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/.drone.yml +59 -0
- package/.editorconfig +10 -0
- package/.eslintrc.json +3 -0
- package/LICENSE +1 -1
- package/README.md +271 -262
- package/example/hollaex.js +7 -16
- package/index.js +7 -446
- package/kit.js +896 -0
- package/package.json +19 -8
- package/utils.js +49 -4
- package/.prettierignore.json +0 -1
- package/.prettierrc.json +0 -8
package/index.js
CHANGED
|
@@ -1,451 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
const EventEmitter = require('events');
|
|
3
|
-
const moment = require('moment');
|
|
4
|
-
const { each } = require('lodash');
|
|
5
|
-
const { createRequest, createSignature, generateHeaders } = require('./utils');
|
|
1
|
+
'use strict';
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
opts = {
|
|
10
|
-
apiURL: 'https://api.hollaex.com',
|
|
11
|
-
baseURL: '/v1',
|
|
12
|
-
apiKey: '',
|
|
13
|
-
apiSecret: '',
|
|
14
|
-
apiExpiresAfter: 60
|
|
15
|
-
}
|
|
16
|
-
) {
|
|
17
|
-
this._url = opts.apiURL + opts.baseURL || 'https://api.hollaex.com/v1';
|
|
18
|
-
this._wsUrl = opts.apiURL || 'https://api.hollaex.com';
|
|
19
|
-
this._baseUrl = opts.baseURL || '/v1';
|
|
20
|
-
this.apiKey = opts.apiKey;
|
|
21
|
-
this.apiSecret = opts.apiSecret;
|
|
22
|
-
this.apiExpiresAfter = opts.apiExpiresAfter || 60;
|
|
23
|
-
this._headers = {
|
|
24
|
-
'content-type': 'application/json',
|
|
25
|
-
Accept: 'application/json',
|
|
26
|
-
'api-key': opts.apiKey,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/* Public */
|
|
31
|
-
/* events: ticker, orderbooks, trades, constant */
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Retrieve last, high, low, open and close price and volume within last 24 hours
|
|
35
|
-
* @param {string} symbol - The currency pair symbol e.g. 'hex-usdt'
|
|
36
|
-
* @return {string} A stringified JSON object with keys high(number), low(number), open(number), close(number), volume(number), last(number)
|
|
37
|
-
*/
|
|
38
|
-
getTicker(symbol) {
|
|
39
|
-
return createRequest(
|
|
40
|
-
'GET',
|
|
41
|
-
`${this._url}/ticker?symbol=${symbol}`,
|
|
42
|
-
this._headers
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Retrieve orderbook containing lists of up to the last 20 bids and asks
|
|
48
|
-
* @param {string} symbol - The currency pair symbol e.g. 'hex-usdt', leave empty to get orderbook for all symbol-pairs
|
|
49
|
-
* @return {string} A stringified 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)
|
|
50
|
-
*/
|
|
51
|
-
getOrderbook(symbol = '') {
|
|
52
|
-
return createRequest(
|
|
53
|
-
'GET',
|
|
54
|
-
`${this._url}/orderbooks?symbol=${symbol}`,
|
|
55
|
-
this._headers
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Retrieve list of up to the last 50 trades
|
|
61
|
-
* @param {string} symbol - The currency pair symbol e.g. 'hex-usdt', leave empty to get trades for all symbol-pairs
|
|
62
|
-
* @return {string} A stringified 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)
|
|
63
|
-
*/
|
|
64
|
-
getTrade(symbol = '') {
|
|
65
|
-
return createRequest(
|
|
66
|
-
'GET',
|
|
67
|
-
`${this._url}/trades?symbol=${symbol}`,
|
|
68
|
-
this._headers
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Retrieve tick size, min price, max price, min size, and max size of each symbol-pair
|
|
74
|
-
* @return {string} A stringified 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)
|
|
75
|
-
*/
|
|
76
|
-
getConstant() {
|
|
77
|
-
return createRequest('GET', `${this._url}/constant`, this._headers);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/*********************************************************************************************************
|
|
81
|
-
|
|
82
|
-
/* Private */
|
|
83
|
-
/* events: user, balance, deposits, withdrawals, trades */
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Retrieve user's personal information
|
|
87
|
-
* @return {string} A stringified JSON object showing user's information such as id, email, bank_account, crypto_wallet, balance, etc
|
|
88
|
-
*/
|
|
89
|
-
getUser() {
|
|
90
|
-
const verb = 'GET';
|
|
91
|
-
const path = this._baseUrl + '/user';
|
|
92
|
-
const headers = generateHeaders(this._headers, this.apiSecret, verb, path, this.apiExpiresAfter);
|
|
93
|
-
return createRequest(
|
|
94
|
-
verb,
|
|
95
|
-
`${this._url}/user`,
|
|
96
|
-
headers
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Retrieve user's wallet balance
|
|
102
|
-
* @return {string} A stringified 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
|
|
103
|
-
*/
|
|
104
|
-
getBalance() {
|
|
105
|
-
const verb = 'GET';
|
|
106
|
-
const path = this._baseUrl + '/user/balance';
|
|
107
|
-
const headers = generateHeaders(this._headers, this.apiSecret, verb, path, this.apiExpiresAfter);
|
|
108
|
-
return createRequest(
|
|
109
|
-
verb,
|
|
110
|
-
`${this._url}/user/balance`,
|
|
111
|
-
headers
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Retrieve list of the user's deposits
|
|
117
|
-
* @param {string} currency The currency to filter by, pass undefined to receive data on all currencies
|
|
118
|
-
* @param {number} limit The upper limit of deposits to return, max = 100
|
|
119
|
-
* @param {number} page The page of data to receive
|
|
120
|
-
* @param {string} orderBy The field to order data by e.g. amount, created_at
|
|
121
|
-
* @param {string} order asc or desc
|
|
122
|
-
* @return {string} A stringified 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))
|
|
123
|
-
*/
|
|
124
|
-
getDeposit(currency, limit = 50, page = 1, orderBy, order = 'asc') {
|
|
125
|
-
const verb = 'GET';
|
|
126
|
-
const path = this._baseUrl + `/user/deposits?limit=${limit}&page=${page}¤cy=${currency}&order_by=${orderBy}&order=${order}`;
|
|
127
|
-
const headers = generateHeaders(this._headers, this.apiSecret, verb, path, this.apiExpiresAfter);
|
|
128
|
-
return createRequest(
|
|
129
|
-
verb,
|
|
130
|
-
`${
|
|
131
|
-
this._url
|
|
132
|
-
}/user/deposits?limit=${limit}&page=${page}¤cy=${currency}&order_by=${orderBy}&order=${order}`,
|
|
133
|
-
headers
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/****** Withdrawals ******/
|
|
138
|
-
/**
|
|
139
|
-
* Retrieve list of the user's withdrawals
|
|
140
|
-
* @param {string} currency The currency to filter by, pass undefined to receive data on all currencies
|
|
141
|
-
* @param {number} limit The upper limit of withdrawals to return, max = 100
|
|
142
|
-
* @param {number} page The page of data to receive
|
|
143
|
-
* @param {string} orderBy The field to order data by e.g. amount, created_at
|
|
144
|
-
* @param {string} order asc or desc
|
|
145
|
-
* @return {string} A stringified 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))
|
|
146
|
-
*/
|
|
147
|
-
getWithdrawal(currency, limit = 50, page = 1, orderBy, order = 'asc') {
|
|
148
|
-
const verb = 'GET';
|
|
149
|
-
const path = this._baseUrl + `/user/withdrawals?limit=${limit}&page=${page}¤cy=${currency}&order_by=${orderBy}&order=${order}`;
|
|
150
|
-
const headers = generateHeaders(this._headers, this.apiSecret, verb, path, this.apiExpiresAfter);
|
|
151
|
-
return createRequest(
|
|
152
|
-
verb,
|
|
153
|
-
`${
|
|
154
|
-
this._url
|
|
155
|
-
}/user/withdrawals?limit=${limit}&page=${page}¤cy=${currency}&order_by=${orderBy}&order=${order}`,
|
|
156
|
-
headers
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// /**
|
|
161
|
-
// * Retrieve the withdrawal/transaction fee for a certain currency
|
|
162
|
-
// * @param {string} currency - The currency to find a fee for
|
|
163
|
-
// * @return {string} A stringified JSON object with the key fee(number)
|
|
164
|
-
// */
|
|
165
|
-
// getWithdrawalFee(currency) {
|
|
166
|
-
// if (currency === '') {
|
|
167
|
-
// currency = undefined;
|
|
168
|
-
// }
|
|
169
|
-
// return createRequest(
|
|
170
|
-
// 'GET',
|
|
171
|
-
// `${this._url}/user/withdraw/${currency}/fee`,
|
|
172
|
-
// this._headers
|
|
173
|
-
// );
|
|
174
|
-
// }
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Make a withdrawal request
|
|
178
|
-
* @param {string} currency - The currency to withdrawal
|
|
179
|
-
* @param {number} amount - The amount of currency to withdrawal
|
|
180
|
-
* @param {string} address - The recipient's wallet address
|
|
181
|
-
* @return {string} A stringified JSON object {message:"Success"}
|
|
182
|
-
*/
|
|
183
|
-
requestWithdrawal(currency, amount, address) {
|
|
184
|
-
const verb = 'POST';
|
|
185
|
-
const path = this._baseUrl + '/user/request-withdrawal';
|
|
186
|
-
const data = { currency, amount, address, fee: 0 };
|
|
187
|
-
const headers = generateHeaders(this._headers, this.apiSecret, verb, path, this.apiExpiresAfter, data);
|
|
188
|
-
return createRequest(
|
|
189
|
-
verb,
|
|
190
|
-
`${this._url}/user/request-withdrawal`,
|
|
191
|
-
headers,
|
|
192
|
-
data
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Retrieve list of the user's completed trades
|
|
198
|
-
* @param {string} symbol The symbol-pair to filter by, pass undefined to receive data on all currencies
|
|
199
|
-
* @param {number} limit The upper limit of completed trades to return, max = 100
|
|
200
|
-
* @param {number} page The page of data to receive
|
|
201
|
-
* @return {string} A stringified 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))
|
|
202
|
-
*/
|
|
203
|
-
getUserTrade(symbol, limit = 50, page = 1) {
|
|
204
|
-
const verb = 'GET';
|
|
205
|
-
let queryString = `?limit=${limit}&page=${page}`;
|
|
206
|
-
if (symbol) {
|
|
207
|
-
queryString += `&symbol=${symbol}`;
|
|
208
|
-
}
|
|
209
|
-
const path = this._baseUrl + `/user/trades${queryString}`;
|
|
210
|
-
const headers = generateHeaders(this._headers, this.apiSecret, verb, path, this.apiExpiresAfter);
|
|
211
|
-
return createRequest(
|
|
212
|
-
verb,
|
|
213
|
-
`${this._url}/user/trades${queryString}`,
|
|
214
|
-
headers
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/****** Orders ******/
|
|
219
|
-
/**
|
|
220
|
-
* Retrieve information of a user's specific order
|
|
221
|
-
* @param {string} orderId - The id of the desired order
|
|
222
|
-
* @return {string} The selected order as a stringified 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)
|
|
223
|
-
*/
|
|
224
|
-
getOrder(orderId) {
|
|
225
|
-
const verb = 'GET';
|
|
226
|
-
const path = this._baseUrl + `/user/orders/${orderId}`;
|
|
227
|
-
const headers = generateHeaders(this._headers, this.apiSecret, verb, path, this.apiExpiresAfter);
|
|
228
|
-
return createRequest(
|
|
229
|
-
verb,
|
|
230
|
-
`${this._url}/user/orders/${orderId}`,
|
|
231
|
-
headers
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Retrieve information of all the user's active orders
|
|
237
|
-
* @param {string} symbol - The currency pair symbol to filter by e.g. 'hex-usdt', leave empty to retrieve information of orders of all symbols
|
|
238
|
-
* @return {string} A stringified JSON array of objects containing the user's active orders
|
|
239
|
-
*/
|
|
240
|
-
getAllOrder(symbol = '') {
|
|
241
|
-
const verb = 'GET';
|
|
242
|
-
const path = this._baseUrl + `/user/orders?symbol=${symbol}`;
|
|
243
|
-
const headers = generateHeaders(this._headers, this.apiSecret, verb, path, this.apiExpiresAfter);
|
|
244
|
-
return createRequest(
|
|
245
|
-
verb,
|
|
246
|
-
`${this._url}/user/orders?symbol=${symbol}`,
|
|
247
|
-
headers
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Create a new order
|
|
253
|
-
* @param {string} symbol - The currency pair symbol e.g. 'hex-usdt'
|
|
254
|
-
* @param {string} side - The side of the order e.g. 'buy', 'sell'
|
|
255
|
-
* @param {number} size - The amount of currency to order
|
|
256
|
-
* @param {string} type - The type of order to create e.g. 'market', 'limit'
|
|
257
|
-
* @param {number} price - The price at which to order (only required if type is 'limit')
|
|
258
|
-
* @return {string} The new order as a stringified JSON object with keys symbol(string), side(string), size(number), type(string), price(number), id(string), created_by(number), and filled(number)
|
|
259
|
-
*/
|
|
260
|
-
createOrder(symbol, side, size, type, price) {
|
|
261
|
-
const verb = 'POST';
|
|
262
|
-
const path = this._baseUrl + '/order';
|
|
263
|
-
const data = { symbol, side, size, type, price };
|
|
264
|
-
const headers = generateHeaders(this._headers, this.apiSecret, verb, path, this.apiExpiresAfter, data);
|
|
265
|
-
return createRequest(verb, `${this._url}/order`, headers, data);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Cancel a user's specific order
|
|
270
|
-
* @param {string} orderId - The id of the order to be cancelled
|
|
271
|
-
* @return {string} The cancelled order as a stringified JSON object with keys symbol(string), side(string), size(number), type(string), price(number), id(string), created_by(number), and filled(number)
|
|
272
|
-
*/
|
|
273
|
-
cancelOrder(orderId) {
|
|
274
|
-
const verb = 'DELETE';
|
|
275
|
-
const path = this._baseUrl + `/user/orders/${orderId}`;
|
|
276
|
-
const headers = generateHeaders(this._headers, this.apiSecret, verb, path, this.apiExpiresAfter);
|
|
277
|
-
return createRequest(
|
|
278
|
-
verb,
|
|
279
|
-
`${this._url}/user/orders/${orderId}`,
|
|
280
|
-
headers
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Cancel all the user's active orders, can filter by currency pair symbol
|
|
286
|
-
* @param {string} symbol - The currency pair symbol to filter by e.g. 'hex-usdt', leave empty to cancel orders of all symbols
|
|
287
|
-
* @return {string} A stringified JSON array of objects containing the cancelled orders
|
|
288
|
-
*/
|
|
289
|
-
cancelAllOrder(symbol = '') {
|
|
290
|
-
const verb = 'DELETE';
|
|
291
|
-
const path = this._baseUrl + `/user/orders?symbol=${symbol}`;
|
|
292
|
-
const headers = generateHeaders(this._headers, this.apiSecret, verb, path, this.apiExpiresAfter);
|
|
293
|
-
return createRequest(
|
|
294
|
-
verb,
|
|
295
|
-
`${this._url}/user/orders?symbol=${symbol}`,
|
|
296
|
-
headers
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Connect to hollaEx websocket and listen to an event
|
|
302
|
-
* @param {string} event - The event to listen to
|
|
303
|
-
* @return {class} A new socket class that listens to the hollaEx websocket server and emits the event being passed
|
|
304
|
-
*/
|
|
305
|
-
connect(events) {
|
|
306
|
-
const apiExpires = moment().unix() + this.apiExpiresAfter;
|
|
307
|
-
const signature = createSignature(this.apiSecret, 'CONNECT', '/socket', apiExpires);
|
|
308
|
-
return new Socket(events, this._wsUrl, this.apiKey, signature, apiExpires);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/*******************
|
|
313
|
-
Websocket
|
|
314
|
-
*******************/
|
|
315
|
-
class Socket extends EventEmitter {
|
|
316
|
-
constructor(events = '', url, apiKey, apiSignature, apiExpires) {
|
|
317
|
-
super();
|
|
318
|
-
this.events = events;
|
|
319
|
-
this.url = url;
|
|
320
|
-
this.apiKey = apiKey;
|
|
321
|
-
this.apiSignature = apiSignature;
|
|
322
|
-
this.apiExpires = apiExpires;
|
|
323
|
-
this.connect(this.events, this.url, this.apiKey, this.apiSignature, this.apiExpires);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
disconnect() {
|
|
327
|
-
each(this.ioLink, (ioLink) => {
|
|
328
|
-
ioLink.close();
|
|
329
|
-
});
|
|
330
|
-
this.ioLink = [];
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
connect(events, url, apiKey, apiSignature, apiExpires) {
|
|
334
|
-
if (!Array.isArray(events)) {
|
|
335
|
-
this.subs = {};
|
|
336
|
-
this.ioLink = [];
|
|
337
|
-
events = events.split(':');
|
|
338
|
-
let [event, symbol] = events;
|
|
339
|
-
switch (event) {
|
|
340
|
-
case 'orderbook':
|
|
341
|
-
case 'trades':
|
|
342
|
-
// case 'ticker':
|
|
343
|
-
if (symbol) {
|
|
344
|
-
this.ioLink.push(io(`${url}/realtime`, { query: { symbol } }));
|
|
345
|
-
} else {
|
|
346
|
-
this.ioLink.push(io(`${url}/realtime`));
|
|
347
|
-
}
|
|
348
|
-
this.ioLink[this.ioLink.length - 1].on(event, (data) => {
|
|
349
|
-
this.emit(event, data);
|
|
350
|
-
});
|
|
351
|
-
this.ioLink[this.ioLink.length - 1].on('error', (error) => {
|
|
352
|
-
this.emit('error', error);
|
|
353
|
-
});
|
|
354
|
-
this.ioLink[this.ioLink.length - 1].once('disconnect', (data) => {
|
|
355
|
-
this.emit('disconnect', `Soscket.io disconnected from server due to: ${data}.`);
|
|
356
|
-
this.subs = this._events;
|
|
357
|
-
this.removeAllListeners();
|
|
358
|
-
});
|
|
359
|
-
this.ioLink[this.ioLink.length - 1].once('reconnect', (attempts) => {
|
|
360
|
-
this._events = this.subs;
|
|
361
|
-
this.emit('reconnect', `Successfully reconnected after ${attempts} attempts.`);
|
|
362
|
-
});
|
|
363
|
-
break;
|
|
364
|
-
case 'user':
|
|
365
|
-
this.ioLink.push(io(`${url}/user`, {
|
|
366
|
-
query: {
|
|
367
|
-
'api-key': apiKey,
|
|
368
|
-
'api-signature': apiSignature,
|
|
369
|
-
'api-expires': apiExpires
|
|
370
|
-
}
|
|
371
|
-
}));
|
|
372
|
-
|
|
373
|
-
this.ioLink[this.ioLink.length - 1].on('user', (data) => {
|
|
374
|
-
this.emit('userInfo', data);
|
|
375
|
-
});
|
|
376
|
-
this.ioLink[this.ioLink.length - 1].on('wallet', (data) => {
|
|
377
|
-
this.emit('userWallet', data);
|
|
378
|
-
});
|
|
379
|
-
this.ioLink[this.ioLink.length - 1].on('orders', (data) => {
|
|
380
|
-
this.emit('userOrder', data);
|
|
381
|
-
});
|
|
382
|
-
this.ioLink[this.ioLink.length - 1].on('trades', (data) => {
|
|
383
|
-
this.emit('userTrades', data);
|
|
384
|
-
});
|
|
385
|
-
this.ioLink[this.ioLink.length - 1].on('update', (data) => {
|
|
386
|
-
this.emit('userUpdate', data);
|
|
387
|
-
});
|
|
388
|
-
this.ioLink[this.ioLink.length - 1].on('error', (error) => {
|
|
389
|
-
this.emit('error', error);
|
|
390
|
-
});
|
|
391
|
-
this.ioLink[this.ioLink.length - 1].once('disconnect', (data) => {
|
|
392
|
-
this.emit('disconnect', `Socket.io disconnected from server due to: ${data}.`);
|
|
393
|
-
this.subs = this._events;
|
|
394
|
-
this.removeAllListeners();
|
|
395
|
-
});
|
|
396
|
-
this.ioLink[this.ioLink.length - 1].once('reconnect', (attempts) => {
|
|
397
|
-
this._events = this.subs;
|
|
398
|
-
this.emit('reconnect', `Successfully reconnected after ${attempts} attempts.`);
|
|
399
|
-
});
|
|
400
|
-
break;
|
|
401
|
-
case 'all':
|
|
402
|
-
this.ioLink.push(io(`${url}/realtime`));
|
|
403
|
-
|
|
404
|
-
this.ioLink[this.ioLink.length - 1].on('orderbook', (data) => {
|
|
405
|
-
this.emit('orderbook', data);
|
|
406
|
-
});
|
|
407
|
-
this.ioLink[this.ioLink.length - 1].on('trades', (data) => {
|
|
408
|
-
this.emit('trades', data);
|
|
409
|
-
});
|
|
3
|
+
const Kit = require('./kit');
|
|
410
4
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
'api-expires': apiExpires
|
|
416
|
-
}
|
|
417
|
-
}));
|
|
418
|
-
this.ioLink[this.ioLink.length - 1].on('user', (data) => {
|
|
419
|
-
this.emit('userInfo', data);
|
|
420
|
-
});
|
|
421
|
-
this.ioLink[this.ioLink.length - 1].on('wallet', (data) => {
|
|
422
|
-
this.emit('userWallet', data);
|
|
423
|
-
});
|
|
424
|
-
this.ioLink[this.ioLink.length - 1].on('orders', (data) => {
|
|
425
|
-
this.emit('userOrder', data);
|
|
426
|
-
});
|
|
427
|
-
this.ioLink[this.ioLink.length - 1].on('trades', (data) => {
|
|
428
|
-
this.emit('userTrade', data);
|
|
429
|
-
});
|
|
430
|
-
this.ioLink[this.ioLink.length - 1].on('update', (data) => {
|
|
431
|
-
this.emit('userUpdate', data);
|
|
432
|
-
});
|
|
433
|
-
this.ioLink[this.ioLink.length - 1].on('error', (error) => {
|
|
434
|
-
this.emit('error', error);
|
|
435
|
-
});
|
|
436
|
-
this.ioLink[this.ioLink.length - 1].once('disconnect', (data) => {
|
|
437
|
-
this.emit('disconnect', `Socket.io disconnected from server due to: ${data}.`);
|
|
438
|
-
this.subs = this._events;
|
|
439
|
-
this.removeAllListeners();
|
|
440
|
-
});
|
|
441
|
-
this.ioLink[this.ioLink.length - 1].once('reconnect', (attempts) => {
|
|
442
|
-
this._events = this.subs;
|
|
443
|
-
this.emit('reconnect', `Successfully reconnected after ${attempts} attempts.`);
|
|
444
|
-
});
|
|
445
|
-
break;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
5
|
+
// To maintain backwards compatibility for `const { Kit } = require("hollaex-node-lib")`
|
|
6
|
+
class BackwardsCompatibleKit extends Kit {
|
|
7
|
+
static get Kit() {
|
|
8
|
+
return Kit;
|
|
448
9
|
}
|
|
449
10
|
}
|
|
450
11
|
|
|
451
|
-
module.exports =
|
|
12
|
+
module.exports = BackwardsCompatibleKit;
|