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/.drone.yml +59 -0
- package/.editorconfig +10 -0
- package/.eslintrc.json +3 -0
- package/README.md +17 -19
- package/example/hollaex.js +7 -16
- package/index.js +8 -5
- package/kit.js +120 -112
- package/package.json +16 -6
- package/utils.js +33 -3
- package/.prettierignore.json +0 -1
- package/.prettierrc.json +0 -8
- package/NETWORK_README.md +0 -338
- package/example/ws.js +0 -164
- package/network.js +0 -2255
package/network.js
DELETED
|
@@ -1,2255 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const moment = require('moment');
|
|
4
|
-
const {
|
|
5
|
-
isBoolean,
|
|
6
|
-
isPlainObject,
|
|
7
|
-
isNumber,
|
|
8
|
-
isString,
|
|
9
|
-
isArray,
|
|
10
|
-
isDate
|
|
11
|
-
} = require('lodash');
|
|
12
|
-
const {
|
|
13
|
-
createRequest,
|
|
14
|
-
generateHeaders,
|
|
15
|
-
checkKit,
|
|
16
|
-
createSignature,
|
|
17
|
-
parameterError
|
|
18
|
-
} = require('./utils');
|
|
19
|
-
const WebSocket = require('ws');
|
|
20
|
-
const { setWsHeartbeat } = require('ws-heartbeat/client');
|
|
21
|
-
const { reject } = require('bluebird');
|
|
22
|
-
|
|
23
|
-
class HollaExNetwork {
|
|
24
|
-
constructor(
|
|
25
|
-
opts = {
|
|
26
|
-
apiUrl: 'https://api.hollaex.network',
|
|
27
|
-
baseUrl: '/v2',
|
|
28
|
-
apiKey: '',
|
|
29
|
-
apiSecret: '',
|
|
30
|
-
apiExpiresAfter: 60,
|
|
31
|
-
activation_code: undefined // kit activation code used only for exchange operators to initialize the exchange
|
|
32
|
-
}
|
|
33
|
-
) {
|
|
34
|
-
this.apiUrl = opts.apiUrl || 'https://api.hollaex.network';
|
|
35
|
-
this.baseUrl = opts.baseUrl || '/v2';
|
|
36
|
-
this.apiKey = opts.apiKey;
|
|
37
|
-
this.apiSecret = opts.apiSecret;
|
|
38
|
-
this.apiExpiresAfter = opts.apiExpiresAfter || 60;
|
|
39
|
-
this.headers = {
|
|
40
|
-
'content-type': 'application/json',
|
|
41
|
-
Accept: 'application/json',
|
|
42
|
-
'api-key': opts.apiKey
|
|
43
|
-
};
|
|
44
|
-
this.activation_code = opts.activation_code;
|
|
45
|
-
this.exchange_id = opts.exchange_id;
|
|
46
|
-
const [ protocol, endpoint ] = this.apiUrl.split('://');
|
|
47
|
-
this.wsUrl =
|
|
48
|
-
protocol === 'https'
|
|
49
|
-
? `wss://${endpoint}/stream?exchange_id=${this.exchange_id}`
|
|
50
|
-
: `ws://${endpoint}/stream?exchange_id=${this.exchange_id}`;
|
|
51
|
-
this.ws = null;
|
|
52
|
-
this.wsEvents = [];
|
|
53
|
-
this.wsReconnect = true;
|
|
54
|
-
this.wsReconnectInterval = 5000;
|
|
55
|
-
this.wsEventListeners = null;
|
|
56
|
-
this.wsConnected = () => this.ws && this.ws.readyState === WebSocket.OPEN;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/* Kit Operator Network Endpoints*/
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Initialize your Kit for HollaEx Network. Must have passed activation_code in constructor
|
|
63
|
-
* @return {object} Your exchange values
|
|
64
|
-
*/
|
|
65
|
-
async init() {
|
|
66
|
-
checkKit(this.activation_code);
|
|
67
|
-
const verb = 'GET';
|
|
68
|
-
const path = `${this.baseUrl}/network/init/${
|
|
69
|
-
this.activation_code
|
|
70
|
-
}`;
|
|
71
|
-
const headers = generateHeaders(
|
|
72
|
-
this.headers,
|
|
73
|
-
this.apiSecret,
|
|
74
|
-
verb,
|
|
75
|
-
path,
|
|
76
|
-
this.apiExpiresAfter
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
let exchange = await createRequest(
|
|
80
|
-
verb,
|
|
81
|
-
`${this.apiUrl}${path}`,
|
|
82
|
-
headers
|
|
83
|
-
);
|
|
84
|
-
this.exchange_id = exchange.id;
|
|
85
|
-
return exchange;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Create a user for the exchange on the network
|
|
90
|
-
* @param {string} email - Email of new user
|
|
91
|
-
* @return {object} Created user's values on network
|
|
92
|
-
*/
|
|
93
|
-
createUser(email) {
|
|
94
|
-
checkKit(this.exchange_id);
|
|
95
|
-
|
|
96
|
-
if (!email) {
|
|
97
|
-
return reject(parameterError('email', 'cannot be null'));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const verb = 'POST';
|
|
101
|
-
const path = `${this.baseUrl}/network/${
|
|
102
|
-
this.exchange_id
|
|
103
|
-
}/signup`;
|
|
104
|
-
const data = { email };
|
|
105
|
-
const headers = generateHeaders(
|
|
106
|
-
this.headers,
|
|
107
|
-
this.apiSecret,
|
|
108
|
-
verb,
|
|
109
|
-
path,
|
|
110
|
-
this.apiExpiresAfter,
|
|
111
|
-
data
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers, data);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Get all trades for the exchange on the network
|
|
119
|
-
* @param {object} opts - Optional parameters.
|
|
120
|
-
* @param {string} opts.symbol - Symbol of trades. Leave blank to get trades for all symbols
|
|
121
|
-
* @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
|
|
122
|
-
* @param {number} opts.page - Page of trades data. Default: 1
|
|
123
|
-
* @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
|
|
124
|
-
* @param {string} opts.order - Ascending (asc) or descending (desc). Default: desc
|
|
125
|
-
* @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
|
|
126
|
-
* @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
|
|
127
|
-
* @return {object} Fields: Count, Data. Count is the number of trades on the page. Data is an array of trades
|
|
128
|
-
*/
|
|
129
|
-
getTrades(
|
|
130
|
-
opts = {
|
|
131
|
-
symbol: null,
|
|
132
|
-
limit: 50,
|
|
133
|
-
page: 1,
|
|
134
|
-
orderBy: 'id',
|
|
135
|
-
order: 'desc',
|
|
136
|
-
startDate: null,
|
|
137
|
-
endDate: null
|
|
138
|
-
}
|
|
139
|
-
) {
|
|
140
|
-
checkKit(this.exchange_id);
|
|
141
|
-
const verb = 'GET';
|
|
142
|
-
|
|
143
|
-
let path = `${this.baseUrl}/network/${this.exchange_id}/user/trades?`;
|
|
144
|
-
|
|
145
|
-
if (isNumber(opts.limit)) {
|
|
146
|
-
path += `&limit=${opts.limit}`;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (isNumber(opts.page)) {
|
|
150
|
-
path += `&page=${opts.page}`;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (isString(opts.orderBy)) {
|
|
154
|
-
path += `&order_by=${opts.orderBy}`;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (isString(opts.order)) {
|
|
158
|
-
path += `&order=${opts.order}`;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (isString(opts.startDate)) {
|
|
162
|
-
path += `&start_date=${opts.startDate}`;
|
|
163
|
-
} else if (isDate(opts.startDate)) {
|
|
164
|
-
path += `&start_date=${opts.startDate.toISOString()}`;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (isString(opts.endDate)) {
|
|
168
|
-
path += `&end_date=${opts.endDate}`;
|
|
169
|
-
} else if (isDate(opts.endDate)) {
|
|
170
|
-
path += `&end_date=${opts.endDate.toISOString()}`;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (opts.symbol) {
|
|
174
|
-
path += `&symbol=${opts.symbol}`;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const headers = generateHeaders(this.headers, this.apiSecret, verb, path, this.apiExpiresAfter);
|
|
178
|
-
|
|
179
|
-
return createRequest(
|
|
180
|
-
verb,
|
|
181
|
-
`${this.apiUrl}${path}`,
|
|
182
|
-
headers
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Get all trades for a user on the network
|
|
188
|
-
* @param {number} userId - User id on network. Leave blank to get all trades for the exchange
|
|
189
|
-
* @param {object} opts - Optional parameters.
|
|
190
|
-
* @param {string} opts.symbol - Symbol of trades. Leave blank to get trades for all symbols
|
|
191
|
-
* @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
|
|
192
|
-
* @param {number} opts.page - Page of trades data. Default: 1
|
|
193
|
-
* @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
|
|
194
|
-
* @param {string} opts.order - Ascending (asc) or descending (desc). Default: desc
|
|
195
|
-
* @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
|
|
196
|
-
* @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
|
|
197
|
-
* @return {object} Fields: Count, Data. Count is the number of trades on the page. Data is an array of trades
|
|
198
|
-
*/
|
|
199
|
-
getUserTrades(
|
|
200
|
-
userId,
|
|
201
|
-
opts = {
|
|
202
|
-
symbol: null,
|
|
203
|
-
limit: 50,
|
|
204
|
-
page: 1,
|
|
205
|
-
orderBy: 'id',
|
|
206
|
-
order: 'desc',
|
|
207
|
-
startDate: null,
|
|
208
|
-
endDate: null
|
|
209
|
-
}
|
|
210
|
-
) {
|
|
211
|
-
checkKit(this.exchange_id);
|
|
212
|
-
|
|
213
|
-
if (!userId) {
|
|
214
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const verb = 'GET';
|
|
218
|
-
|
|
219
|
-
let path = `${this.baseUrl}/network/${this.exchange_id}/user/trades?user_id=${userId}`;
|
|
220
|
-
|
|
221
|
-
if (isNumber(opts.limit)) {
|
|
222
|
-
path += `&limit=${opts.limit}`;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (isNumber(opts.page)) {
|
|
226
|
-
path += `&page=${opts.page}`;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (isString(opts.orderBy)) {
|
|
230
|
-
path += `&order_by=${opts.orderBy}`;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (isString(opts.order)) {
|
|
234
|
-
path += `&order=${opts.order}`;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (isString(opts.startDate)) {
|
|
238
|
-
path += `&start_date=${opts.startDate}`;
|
|
239
|
-
} else if (isDate(opts.startDate)) {
|
|
240
|
-
path += `&start_date=${opts.startDate.toISOString()}`;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (isString(opts.endDate)) {
|
|
244
|
-
path += `&end_date=${opts.endDate}`;
|
|
245
|
-
} else if (isDate(opts.endDate)) {
|
|
246
|
-
path += `&end_date=${opts.endDate.toISOString()}`;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (opts.symbol) {
|
|
250
|
-
path += `&symbol=${opts.symbol}`;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const headers = generateHeaders(
|
|
254
|
-
this.headers,
|
|
255
|
-
this.apiSecret,
|
|
256
|
-
verb,
|
|
257
|
-
path,
|
|
258
|
-
this.apiExpiresAfter
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Get user network data
|
|
266
|
-
* @param {number} userId - User's network id
|
|
267
|
-
* @return {object} User network data
|
|
268
|
-
*/
|
|
269
|
-
getUser(userId) {
|
|
270
|
-
checkKit(this.exchange_id);
|
|
271
|
-
|
|
272
|
-
if (!userId) {
|
|
273
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const verb = 'GET';
|
|
277
|
-
const path = `${this.baseUrl}/network/${
|
|
278
|
-
this.exchange_id
|
|
279
|
-
}/user?user_id=${userId}`;
|
|
280
|
-
const headers = generateHeaders(
|
|
281
|
-
this.headers,
|
|
282
|
-
this.apiSecret,
|
|
283
|
-
verb,
|
|
284
|
-
path,
|
|
285
|
-
this.apiExpiresAfter
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Get all users for the exchange on the network
|
|
293
|
-
* @return {object} Fields: Count, Data. Count is the number of users for the exchange on the network. Data is an array of users
|
|
294
|
-
*/
|
|
295
|
-
getUsers() {
|
|
296
|
-
checkKit(this.exchange_id);
|
|
297
|
-
const verb = 'GET';
|
|
298
|
-
const path = `${this.baseUrl}/network/${this.exchange_id}/users`;
|
|
299
|
-
const headers = generateHeaders(
|
|
300
|
-
this.headers,
|
|
301
|
-
this.apiSecret,
|
|
302
|
-
verb,
|
|
303
|
-
path,
|
|
304
|
-
this.apiExpiresAfter
|
|
305
|
-
);
|
|
306
|
-
|
|
307
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Create a crypto address for user
|
|
312
|
-
* @param {number} userId - User id on network.
|
|
313
|
-
* @param {string} crypto - Crypto to create address for.
|
|
314
|
-
* @param {object} opts - Optional parameters.
|
|
315
|
-
* @param {string} opts.network - Crypto's blockchain network
|
|
316
|
-
* @return {object} Object with new address
|
|
317
|
-
*/
|
|
318
|
-
createUserCryptoAddress(userId, crypto, opts = {
|
|
319
|
-
network: null
|
|
320
|
-
}) {
|
|
321
|
-
checkKit(this.exchange_id);
|
|
322
|
-
|
|
323
|
-
if (!userId) {
|
|
324
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
325
|
-
} else if (!crypto) {
|
|
326
|
-
return reject(parameterError('crypto', 'cannot be null'));
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const verb = 'GET';
|
|
330
|
-
let path = `${this.baseUrl}/network/${this.exchange_id}/create-address?user_id=${userId}&crypto=${crypto}`;
|
|
331
|
-
|
|
332
|
-
if (opts.network) {
|
|
333
|
-
path += `&network=${opts.network}`;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const headers = generateHeaders(
|
|
337
|
-
this.headers,
|
|
338
|
-
this.apiSecret,
|
|
339
|
-
verb,
|
|
340
|
-
path,
|
|
341
|
-
this.apiExpiresAfter
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Create a withdrawal for an exchange's user on the network
|
|
349
|
-
* @param {number} userId - User id on network
|
|
350
|
-
* @param {string} address - Address to send withdrawal to
|
|
351
|
-
* @param {string} currency - Curreny to withdraw
|
|
352
|
-
* @param {number} amount - Amount to withdraw
|
|
353
|
-
* @param {object} opts - Optional parameters.
|
|
354
|
-
* @param {string} opts.network - Specify crypto currency network
|
|
355
|
-
* @return {object} Withdrawal made on the network
|
|
356
|
-
*/
|
|
357
|
-
performWithdrawal(userId, address, currency, amount, opts = {
|
|
358
|
-
network: null
|
|
359
|
-
}) {
|
|
360
|
-
checkKit(this.exchange_id);
|
|
361
|
-
|
|
362
|
-
if (!userId) {
|
|
363
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
364
|
-
} else if (!address) {
|
|
365
|
-
return reject(parameterError('address', 'cannot be null'));
|
|
366
|
-
} else if (!currency) {
|
|
367
|
-
return reject(parameterError('currency', 'cannot be null'));
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
const verb = 'POST';
|
|
371
|
-
const path = `${this.baseUrl}/network/${
|
|
372
|
-
this.exchange_id
|
|
373
|
-
}/withdraw?user_id=${userId}`;
|
|
374
|
-
const data = { address, currency, amount };
|
|
375
|
-
if (opts.network) {
|
|
376
|
-
data.network = opts.network;
|
|
377
|
-
}
|
|
378
|
-
const headers = generateHeaders(
|
|
379
|
-
this.headers,
|
|
380
|
-
this.apiSecret,
|
|
381
|
-
verb,
|
|
382
|
-
path,
|
|
383
|
-
this.apiExpiresAfter,
|
|
384
|
-
data
|
|
385
|
-
);
|
|
386
|
-
|
|
387
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers, data);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Cancel a withdrawal for an exchange's user on the network
|
|
392
|
-
* @param {number} userId - User id on network
|
|
393
|
-
* @param {string} withdrawalId - Withdrawal's id on network (not transaction id).
|
|
394
|
-
* @return {object} Withdrawal canceled on the network
|
|
395
|
-
*/
|
|
396
|
-
cancelWithdrawal(userId, withdrawalId) {
|
|
397
|
-
checkKit(this.exchange_id);
|
|
398
|
-
|
|
399
|
-
if (!userId) {
|
|
400
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
401
|
-
} else if (!withdrawalId) {
|
|
402
|
-
return reject(parameterError('withdrawalId', 'cannot be null'));
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
const verb = 'DELETE';
|
|
406
|
-
const path = `${this.baseUrl}/network/${
|
|
407
|
-
this.exchange_id
|
|
408
|
-
}/withdraw?user_id=${userId}&id=${withdrawalId}`;
|
|
409
|
-
const headers = generateHeaders(
|
|
410
|
-
this.headers,
|
|
411
|
-
this.apiSecret,
|
|
412
|
-
verb,
|
|
413
|
-
path,
|
|
414
|
-
this.apiExpiresAfter
|
|
415
|
-
);
|
|
416
|
-
|
|
417
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Get all deposits for the exchange on the network
|
|
422
|
-
* @param {object} opts - Optional parameters.
|
|
423
|
-
* @param {string} opts.currency - Currency of deposits. Leave blank to get deposits for all currencies
|
|
424
|
-
* @param {boolean} opts.status - Confirmed status of the deposits to get. Leave blank to get all confirmed and unconfirmed deposits
|
|
425
|
-
* @param {boolean} opts.dismissed - Dismissed status of the deposits to get. Leave blank to get all dismissed and undismissed deposits
|
|
426
|
-
* @param {boolean} opts.rejected - Rejected status of the deposits to get. Leave blank to get all rejected and unrejected deposits
|
|
427
|
-
* @param {boolean} opts.processing - Processing status of the deposits to get. Leave blank to get all processing and unprocessing deposits
|
|
428
|
-
* @param {boolean} opts.waiting - Waiting status of the deposits to get. Leave blank to get all waiting and unwaiting deposits
|
|
429
|
-
* @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
|
|
430
|
-
* @param {number} opts.page - Page of trades data. Default: 1
|
|
431
|
-
* @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
|
|
432
|
-
* @param {string} opts.order - Ascending (asc) or descending (desc). Default: asc
|
|
433
|
-
* @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
|
|
434
|
-
* @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
|
|
435
|
-
* @param {string} opts.transactionId - Deposit with specific transaction ID.
|
|
436
|
-
* @param {string} opts.address - Deposits with specific address.
|
|
437
|
-
* @return {object} Fields: Count, Data. Count is the number of deposits on the page. Data is an array of deposits
|
|
438
|
-
*/
|
|
439
|
-
getDeposits(
|
|
440
|
-
opts = {
|
|
441
|
-
currency: null,
|
|
442
|
-
status: null,
|
|
443
|
-
dismissed: null,
|
|
444
|
-
rejected: null,
|
|
445
|
-
processing: null,
|
|
446
|
-
waiting: null,
|
|
447
|
-
limit: 50,
|
|
448
|
-
page: 1,
|
|
449
|
-
orderBy: 'id',
|
|
450
|
-
order: 'asc',
|
|
451
|
-
startDate: null,
|
|
452
|
-
endDate: null,
|
|
453
|
-
transactionId: null,
|
|
454
|
-
address: null
|
|
455
|
-
}
|
|
456
|
-
) {
|
|
457
|
-
checkKit(this.exchange_id);
|
|
458
|
-
const verb = 'GET';
|
|
459
|
-
|
|
460
|
-
let path = `${this.baseUrl}/network/${
|
|
461
|
-
this.exchange_id
|
|
462
|
-
}/deposits?`;
|
|
463
|
-
|
|
464
|
-
if (isNumber(opts.limit)) {
|
|
465
|
-
path += `&limit=${opts.limit}`;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
if (isNumber(opts.page)) {
|
|
469
|
-
path += `&page=${opts.page}`;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
if (isString(opts.orderBy)) {
|
|
473
|
-
path += `&order_by=${opts.orderBy}`;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
if (isString(opts.order)) {
|
|
477
|
-
path += `&order=${opts.order}`;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
if (isString(opts.address)) {
|
|
481
|
-
path += `&address=${opts.address}`;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
if (isString(opts.transactionId)) {
|
|
485
|
-
path += `&transaction_id=${opts.transactionId}`;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
if (isString(opts.startDate)) {
|
|
489
|
-
path += `&start_date=${opts.startDate}`;
|
|
490
|
-
} else if (isDate(opts.startDate)) {
|
|
491
|
-
path += `&start_date=${opts.startDate.toISOString()}`;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
if (isString(opts.endDate)) {
|
|
495
|
-
path += `&end_date=${opts.endDate}`;
|
|
496
|
-
} else if (isDate(opts.endDate)) {
|
|
497
|
-
path += `&end_date=${opts.endDate.toISOString()}`;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
if (opts.currency) {
|
|
501
|
-
path += `¤cy=${opts.currency}`;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
if (isBoolean(opts.status)) {
|
|
505
|
-
path += `&status=${opts.status}`;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
if (isBoolean(opts.dismissed)) {
|
|
509
|
-
path += `&dismissed=${opts.dismissed}`;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
if (isBoolean(opts.rejected)) {
|
|
513
|
-
path += `&rejected=${opts.rejected}`;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
if (isBoolean(opts.processing)) {
|
|
517
|
-
path += `&processing=${opts.processing}`;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
if (isBoolean(opts.waiting)) {
|
|
521
|
-
path += `&waiting=${opts.waiting}`;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
const headers = generateHeaders(
|
|
525
|
-
this.headers,
|
|
526
|
-
this.apiSecret,
|
|
527
|
-
verb,
|
|
528
|
-
path,
|
|
529
|
-
this.apiExpiresAfter
|
|
530
|
-
);
|
|
531
|
-
|
|
532
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
/**
|
|
536
|
-
* Get all deposits for a user on the network
|
|
537
|
-
* @param {number} userId - User id on network. Leave blank to get all deposits for the exchange
|
|
538
|
-
* @param {object} opts - Optional parameters.
|
|
539
|
-
* @param {string} opts.currency - Currency of deposits. Leave blank to get deposits for all currencies
|
|
540
|
-
* @param {boolean} opts.status - Confirmed status of the deposits to get. Leave blank to get all confirmed and unconfirmed deposits
|
|
541
|
-
* @param {boolean} opts.dismissed - Dismissed status of the deposits to get. Leave blank to get all dismissed and undismissed deposits
|
|
542
|
-
* @param {boolean} opts.rejected - Rejected status of the deposits to get. Leave blank to get all rejected and unrejected deposits
|
|
543
|
-
* @param {boolean} opts.processing - Processing status of the deposits to get. Leave blank to get all processing and unprocessing deposits
|
|
544
|
-
* @param {boolean} opts.waiting - Waiting status of the deposits to get. Leave blank to get all waiting and unwaiting deposits
|
|
545
|
-
* @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
|
|
546
|
-
* @param {number} opts.page - Page of trades data. Default: 1
|
|
547
|
-
* @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
|
|
548
|
-
* @param {string} opts.order - Ascending (asc) or descending (desc). Default: asc
|
|
549
|
-
* @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
|
|
550
|
-
* @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
|
|
551
|
-
* @param {string} opts.transactionId - Deposit with specific transaction ID.
|
|
552
|
-
* @param {string} opts.address - Deposits with specific address.
|
|
553
|
-
* @return {object} Fields: Count, Data. Count is the number of deposits on the page. Data is an array of deposits
|
|
554
|
-
*/
|
|
555
|
-
getUserDeposits(
|
|
556
|
-
userId,
|
|
557
|
-
opts = {
|
|
558
|
-
currency: null,
|
|
559
|
-
status: null,
|
|
560
|
-
dismissed: null,
|
|
561
|
-
rejected: null,
|
|
562
|
-
processing: null,
|
|
563
|
-
waiting: null,
|
|
564
|
-
limit: 50,
|
|
565
|
-
page: 1,
|
|
566
|
-
orderBy: 'id',
|
|
567
|
-
order: 'asc',
|
|
568
|
-
startDate: null,
|
|
569
|
-
endDate: null,
|
|
570
|
-
transactionId: null,
|
|
571
|
-
address: null
|
|
572
|
-
}
|
|
573
|
-
) {
|
|
574
|
-
checkKit(this.exchange_id);
|
|
575
|
-
|
|
576
|
-
if (!userId) {
|
|
577
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
const verb = 'GET';
|
|
581
|
-
|
|
582
|
-
let path = `${this.baseUrl}/network/${
|
|
583
|
-
this.exchange_id
|
|
584
|
-
}/deposits?user_id=${userId}`;
|
|
585
|
-
|
|
586
|
-
if (isNumber(opts.limit)) {
|
|
587
|
-
path += `&limit=${opts.limit}`;
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
if (isNumber(opts.page)) {
|
|
591
|
-
path += `&page=${opts.page}`;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
if (isString(opts.orderBy)) {
|
|
595
|
-
path += `&order_by=${opts.orderBy}`;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
if (isString(opts.order)) {
|
|
599
|
-
path += `&order=${opts.order}`;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
if (isString(opts.address)) {
|
|
603
|
-
path += `&address=${opts.address}`;
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
if (isString(opts.transactionId)) {
|
|
607
|
-
path += `&transaction_id=${opts.transactionId}`;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
if (isString(opts.startDate)) {
|
|
611
|
-
path += `&start_date=${opts.startDate}`;
|
|
612
|
-
} else if (isDate(opts.startDate)) {
|
|
613
|
-
path += `&start_date=${opts.startDate.toISOString()}`;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
if (isString(opts.endDate)) {
|
|
617
|
-
path += `&end_date=${opts.endDate}`;
|
|
618
|
-
} else if (isDate(opts.endDate)) {
|
|
619
|
-
path += `&end_date=${opts.endDate.toISOString()}`;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
if (opts.currency) {
|
|
623
|
-
path += `¤cy=${opts.currency}`;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
if (isBoolean(opts.status)) {
|
|
627
|
-
path += `&status=${opts.status}`;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
if (isBoolean(opts.dismissed)) {
|
|
631
|
-
path += `&dismissed=${opts.dismissed}`;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
if (isBoolean(opts.rejected)) {
|
|
635
|
-
path += `&rejected=${opts.rejected}`;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
if (isBoolean(opts.processing)) {
|
|
639
|
-
path += `&processing=${opts.processing}`;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
if (isBoolean(opts.waiting)) {
|
|
643
|
-
path += `&waiting=${opts.waiting}`;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
const headers = generateHeaders(
|
|
647
|
-
this.headers,
|
|
648
|
-
this.apiSecret,
|
|
649
|
-
verb,
|
|
650
|
-
path,
|
|
651
|
-
this.apiExpiresAfter
|
|
652
|
-
);
|
|
653
|
-
|
|
654
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
/**
|
|
658
|
-
* Get all withdrawals for the exchange on the network
|
|
659
|
-
* @param {object} opts - Optional parameters.
|
|
660
|
-
* @param {string} opts.currency - Currency of withdrawals. Leave blank to get withdrawals for all currencies
|
|
661
|
-
* @param {boolean} opts.status - Confirmed status of the withdrawals to get. Leave blank to get all confirmed and unconfirmed withdrawals
|
|
662
|
-
* @param {boolean} opts.dismissed - Dismissed status of the withdrawals to get. Leave blank to get all dismissed and undismissed withdrawals
|
|
663
|
-
* @param {boolean} opts.rejected - Rejected status of the withdrawals to get. Leave blank to get all rejected and unrejected withdrawals
|
|
664
|
-
* @param {boolean} opts.processing - Processing status of the withdrawals to get. Leave blank to get all processing and unprocessing withdrawals
|
|
665
|
-
* @param {boolean} opts.waiting - Waiting status of the withdrawals to get. Leave blank to get all waiting and unwaiting withdrawals
|
|
666
|
-
* @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
|
|
667
|
-
* @param {number} opts.page - Page of trades data. Default: 1
|
|
668
|
-
* @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
|
|
669
|
-
* @param {string} opts.order - Ascending (asc) or descending (desc). Default: asc
|
|
670
|
-
* @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
|
|
671
|
-
* @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
|
|
672
|
-
* @param {string} opts.transactionId - Withdrawals with specific transaction ID.
|
|
673
|
-
* @param {string} opts.address - Withdrawals with specific address.
|
|
674
|
-
* @return {object} Fields: Count, Data. Count is the number of withdrawals on the page. Data is an array of withdrawals
|
|
675
|
-
*/
|
|
676
|
-
getWithdrawals(
|
|
677
|
-
opts = {
|
|
678
|
-
currency: null,
|
|
679
|
-
status: null,
|
|
680
|
-
dismissed: null,
|
|
681
|
-
rejected: null,
|
|
682
|
-
processing: null,
|
|
683
|
-
waiting: null,
|
|
684
|
-
limit: 50,
|
|
685
|
-
page: 1,
|
|
686
|
-
orderBy: 'id',
|
|
687
|
-
order: 'asc',
|
|
688
|
-
startDate: null,
|
|
689
|
-
endDate: null,
|
|
690
|
-
transactionId: null,
|
|
691
|
-
address: null
|
|
692
|
-
}
|
|
693
|
-
) {
|
|
694
|
-
checkKit(this.exchange_id);
|
|
695
|
-
const verb = 'GET';
|
|
696
|
-
|
|
697
|
-
let path = `${this.baseUrl}/network/${
|
|
698
|
-
this.exchange_id
|
|
699
|
-
}/withdrawals?`;
|
|
700
|
-
|
|
701
|
-
if (isNumber(opts.limit)) {
|
|
702
|
-
path += `&limit=${opts.limit}`;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
if (isNumber(opts.page)) {
|
|
706
|
-
path += `&page=${opts.page}`;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
if (isString(opts.orderBy)) {
|
|
710
|
-
path += `&order_by=${opts.orderBy}`;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
if (isString(opts.order)) {
|
|
714
|
-
path += `&order=${opts.order}`;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
if (isString(opts.address)) {
|
|
718
|
-
path += `&address=${opts.address}`;
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
if (isString(opts.transactionId)) {
|
|
722
|
-
path += `&transaction_id=${opts.transactionId}`;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
if (isString(opts.startDate)) {
|
|
726
|
-
path += `&start_date=${opts.startDate}`;
|
|
727
|
-
} else if (isDate(opts.startDate)) {
|
|
728
|
-
path += `&start_date=${opts.startDate.toISOString()}`;
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
if (isString(opts.endDate)) {
|
|
732
|
-
path += `&end_date=${opts.endDate}`;
|
|
733
|
-
} else if (isDate(opts.endDate)) {
|
|
734
|
-
path += `&end_date=${opts.endDate.toISOString()}`;
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
if (opts.currency) {
|
|
738
|
-
path += `¤cy=${opts.currency}`;
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
if (isBoolean(opts.status)) {
|
|
742
|
-
path += `&status=${opts.status}`;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
if (isBoolean(opts.dismissed)) {
|
|
746
|
-
path += `&dismissed=${opts.dismissed}`;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
if (isBoolean(opts.rejected)) {
|
|
750
|
-
path += `&rejected=${opts.rejected}`;
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
if (isBoolean(opts.processing)) {
|
|
754
|
-
path += `&processing=${opts.processing}`;
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
if (isBoolean(opts.waiting)) {
|
|
758
|
-
path += `&waiting=${opts.waiting}`;
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
const headers = generateHeaders(
|
|
762
|
-
this.headers,
|
|
763
|
-
this.apiSecret,
|
|
764
|
-
verb,
|
|
765
|
-
path,
|
|
766
|
-
this.apiExpiresAfter
|
|
767
|
-
);
|
|
768
|
-
|
|
769
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
/**
|
|
773
|
-
* Get all withdrawals for a user on the network
|
|
774
|
-
* @param {number} userId - User id on network. Leave blank to get all withdrawals for the exchange
|
|
775
|
-
* @param {object} opts - Optional parameters.
|
|
776
|
-
* @param {string} opts.currency - Currency of withdrawals. Leave blank to get withdrawals for all currencies
|
|
777
|
-
* @param {boolean} opts.status - Confirmed status of the depowithdrawalssits to get. Leave blank to get all confirmed and unconfirmed withdrawals
|
|
778
|
-
* @param {boolean} opts.dismissed - Dismissed status of the withdrawals to get. Leave blank to get all dismissed and undismissed withdrawals
|
|
779
|
-
* @param {boolean} opts.rejected - Rejected status of the withdrawals to get. Leave blank to get all rejected and unrejected withdrawals
|
|
780
|
-
* @param {boolean} opts.processing - Processing status of the withdrawals to get. Leave blank to get all processing and unprocessing withdrawals
|
|
781
|
-
* @param {boolean} opts.waiting - Waiting status of the withdrawals to get. Leave blank to get all waiting and unwaiting withdrawals
|
|
782
|
-
* @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
|
|
783
|
-
* @param {number} opts.page - Page of trades data. Default: 1
|
|
784
|
-
* @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
|
|
785
|
-
* @param {string} opts.order - Ascending (asc) or descending (desc). Default: asc
|
|
786
|
-
* @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
|
|
787
|
-
* @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
|
|
788
|
-
* @param {string} opts.transactionId - Withdrawals with specific transaction ID.
|
|
789
|
-
* @param {string} opts.address - Withdrawals with specific address.
|
|
790
|
-
* @return {object} Fields: Count, Data. Count is the number of withdrawals on the page. Data is an array of withdrawals
|
|
791
|
-
*/
|
|
792
|
-
getUserWithdrawals(
|
|
793
|
-
userId,
|
|
794
|
-
opts = {
|
|
795
|
-
currency: null,
|
|
796
|
-
status: null,
|
|
797
|
-
dismissed: null,
|
|
798
|
-
rejected: null,
|
|
799
|
-
processing: null,
|
|
800
|
-
waiting: null,
|
|
801
|
-
limit: 50,
|
|
802
|
-
page: 1,
|
|
803
|
-
orderBy: 'id',
|
|
804
|
-
order: 'asc',
|
|
805
|
-
startDate: null,
|
|
806
|
-
endDate: null,
|
|
807
|
-
transactionId: null,
|
|
808
|
-
address: null
|
|
809
|
-
}
|
|
810
|
-
) {
|
|
811
|
-
checkKit(this.exchange_id);
|
|
812
|
-
|
|
813
|
-
if (!userId) {
|
|
814
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
const verb = 'GET';
|
|
818
|
-
|
|
819
|
-
let path = `${this.baseUrl}/network/${
|
|
820
|
-
this.exchange_id
|
|
821
|
-
}/withdrawals?user_id=${userId}`;
|
|
822
|
-
|
|
823
|
-
if (isNumber(opts.limit)) {
|
|
824
|
-
path += `&limit=${opts.limit}`;
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
if (isNumber(opts.page)) {
|
|
828
|
-
path += `&page=${opts.page}`;
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
if (isString(opts.orderBy)) {
|
|
832
|
-
path += `&order_by=${opts.orderBy}`;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
if (isString(opts.order)) {
|
|
836
|
-
path += `&order=${opts.order}`;
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
if (isString(opts.address)) {
|
|
840
|
-
path += `&address=${opts.address}`;
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
if (isString(opts.transactionId)) {
|
|
844
|
-
path += `&transaction_id=${opts.transactionId}`;
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
if (isString(opts.startDate)) {
|
|
848
|
-
path += `&start_date=${opts.startDate}`;
|
|
849
|
-
} else if (isDate(opts.startDate)) {
|
|
850
|
-
path += `&start_date=${opts.startDate.toISOString()}`;
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
if (isString(opts.endDate)) {
|
|
854
|
-
path += `&end_date=${opts.endDate}`;
|
|
855
|
-
} else if (isDate(opts.endDate)) {
|
|
856
|
-
path += `&end_date=${opts.endDate.toISOString()}`;
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
if (opts.currency) {
|
|
860
|
-
path += `¤cy=${opts.currency}`;
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
if (isBoolean(opts.status)) {
|
|
864
|
-
path += `&status=${opts.status}`;
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
if (isBoolean(opts.dismissed)) {
|
|
868
|
-
path += `&dismissed=${opts.dismissed}`;
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
if (isBoolean(opts.rejected)) {
|
|
872
|
-
path += `&rejected=${opts.rejected}`;
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
if (isBoolean(opts.processing)) {
|
|
876
|
-
path += `&processing=${opts.processing}`;
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
if (isBoolean(opts.waiting)) {
|
|
880
|
-
path += `&waiting=${opts.waiting}`;
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
const headers = generateHeaders(
|
|
884
|
-
this.headers,
|
|
885
|
-
this.apiSecret,
|
|
886
|
-
verb,
|
|
887
|
-
path,
|
|
888
|
-
this.apiExpiresAfter
|
|
889
|
-
);
|
|
890
|
-
|
|
891
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
/**
|
|
895
|
-
* Get the balance for the exchange on the network
|
|
896
|
-
* @return {object} Available, pending, and total balance for all currencies for your exchange on the network
|
|
897
|
-
*/
|
|
898
|
-
getBalance() {
|
|
899
|
-
checkKit(this.exchange_id);
|
|
900
|
-
const verb = 'GET';
|
|
901
|
-
|
|
902
|
-
let path = `${this.baseUrl}/network/${this.exchange_id}/balance`;
|
|
903
|
-
|
|
904
|
-
const headers = generateHeaders(
|
|
905
|
-
this.headers,
|
|
906
|
-
this.apiSecret,
|
|
907
|
-
verb,
|
|
908
|
-
path,
|
|
909
|
-
this.apiExpiresAfter
|
|
910
|
-
);
|
|
911
|
-
|
|
912
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
/**
|
|
916
|
-
* Get the balance for an exchange's user on the network
|
|
917
|
-
* @param {number} userId - User id on network
|
|
918
|
-
* @return {object} Available, pending, and total balance for all currencies for your exchange on the network
|
|
919
|
-
*/
|
|
920
|
-
getUserBalance(userId) {
|
|
921
|
-
checkKit(this.exchange_id);
|
|
922
|
-
|
|
923
|
-
if (!userId) {
|
|
924
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
const verb = 'GET';
|
|
928
|
-
|
|
929
|
-
let path = `${this.baseUrl}/network/${this.exchange_id}/balance?user_id=${userId}`;
|
|
930
|
-
|
|
931
|
-
const headers = generateHeaders(
|
|
932
|
-
this.headers,
|
|
933
|
-
this.apiSecret,
|
|
934
|
-
verb,
|
|
935
|
-
path,
|
|
936
|
-
this.apiExpiresAfter
|
|
937
|
-
);
|
|
938
|
-
|
|
939
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
/**
|
|
943
|
-
* Get an order for the exchange on the network
|
|
944
|
-
* @param {number} userId - Id of order's user
|
|
945
|
-
* @param {number} orderId - Order id
|
|
946
|
-
* @return {object} Order on the network with current data e.g. side, size, filled, etc.
|
|
947
|
-
*/
|
|
948
|
-
getOrder(userId, orderId) {
|
|
949
|
-
checkKit(this.exchange_id);
|
|
950
|
-
|
|
951
|
-
if (!userId) {
|
|
952
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
953
|
-
} else if (!orderId) {
|
|
954
|
-
return reject(parameterError('orderId', 'cannot be null'));
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
const verb = 'GET';
|
|
958
|
-
const path = `${this.baseUrl}/network/${
|
|
959
|
-
this.exchange_id
|
|
960
|
-
}/order?user_id=${userId}&order_id=${orderId}`;
|
|
961
|
-
const headers = generateHeaders(
|
|
962
|
-
this.headers,
|
|
963
|
-
this.apiSecret,
|
|
964
|
-
verb,
|
|
965
|
-
path,
|
|
966
|
-
this.apiExpiresAfter
|
|
967
|
-
);
|
|
968
|
-
|
|
969
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
/**
|
|
973
|
-
* Create a new order for the exchange on the network
|
|
974
|
-
* @param {number} userId - User id on the network
|
|
975
|
-
* @param {string} symbol - The currency pair symbol e.g. 'hex-usdt'
|
|
976
|
-
* @param {string} side - The side of the order e.g. 'buy', 'sell'
|
|
977
|
-
* @param {number} size - The amount of currency to order
|
|
978
|
-
* @param {string} type - The type of order to create e.g. 'market', 'limit'
|
|
979
|
-
* @param {number} price - The price at which to order (only required if type is 'limit')
|
|
980
|
-
* @param {object} feeData - Object with fee data
|
|
981
|
-
* @param {object} feeData.fee_structure - Object with maker and taker fees
|
|
982
|
-
* @param {number} feeData.fee_structure.maker - Maker fee.
|
|
983
|
-
* @param {number} feeData.fee_structure.taker - Taker fee
|
|
984
|
-
* @param {object} opts - Optional parameters.
|
|
985
|
-
* @param {number} opts.stop - Stop price of order. This makes the order a stop loss order.
|
|
986
|
-
* @param {object} opts.meta - Meta values for order.
|
|
987
|
-
* @return {object} Newly created order values e.g. symbol, id, side, status, etc.
|
|
988
|
-
*/
|
|
989
|
-
createOrder(
|
|
990
|
-
userId,
|
|
991
|
-
symbol,
|
|
992
|
-
side,
|
|
993
|
-
size,
|
|
994
|
-
type,
|
|
995
|
-
price = 0,
|
|
996
|
-
feeData = {
|
|
997
|
-
fee_structure: null,
|
|
998
|
-
fee_coin: null
|
|
999
|
-
},
|
|
1000
|
-
opts = {
|
|
1001
|
-
stop: null,
|
|
1002
|
-
meta: null
|
|
1003
|
-
}
|
|
1004
|
-
) {
|
|
1005
|
-
checkKit(this.exchange_id);
|
|
1006
|
-
|
|
1007
|
-
if (!userId) {
|
|
1008
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
1009
|
-
} else if (!symbol) {
|
|
1010
|
-
return reject(parameterError('symbol', 'cannot be null'));
|
|
1011
|
-
} else if (side !== 'buy' && side !== 'sell') {
|
|
1012
|
-
return reject(parameterError('side', 'must be buy or sell'));
|
|
1013
|
-
} else if (!size) {
|
|
1014
|
-
return reject(parameterError('size', 'cannot be null'));
|
|
1015
|
-
} else if (type !== 'market' && type !== 'limit') {
|
|
1016
|
-
return reject(parameterError('type', 'must be limit or market'));
|
|
1017
|
-
} else if (!price && type !== 'market') {
|
|
1018
|
-
return reject(parameterError('price', 'cannot be null for limit orders'));
|
|
1019
|
-
} else if (!isPlainObject(feeData) || !isPlainObject(feeData.fee_structure)) {
|
|
1020
|
-
return reject(parameterError('feeData', 'feeData must be an object and contain fee_structure'));
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
const verb = 'POST';
|
|
1024
|
-
const path = `${this.baseUrl}/network/${
|
|
1025
|
-
this.exchange_id
|
|
1026
|
-
}/order?user_id=${userId}`;
|
|
1027
|
-
const data = { symbol, side, size, type, price };
|
|
1028
|
-
|
|
1029
|
-
if (isPlainObject(feeData.fee_structure)) {
|
|
1030
|
-
data.fee_structure = feeData.fee_structure;
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
if (feeData.fee_coin) {
|
|
1034
|
-
data.fee_coin = feeData.fee_coin;
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
if (isPlainObject(opts.meta)) {
|
|
1038
|
-
data.meta = opts.meta;
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
if (isNumber(opts.stop)) {
|
|
1042
|
-
data.stop = opts.stop;
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
const headers = generateHeaders(
|
|
1046
|
-
this.headers,
|
|
1047
|
-
this.apiSecret,
|
|
1048
|
-
verb,
|
|
1049
|
-
path,
|
|
1050
|
-
this.apiExpiresAfter,
|
|
1051
|
-
data
|
|
1052
|
-
);
|
|
1053
|
-
|
|
1054
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers, data);
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
/**
|
|
1058
|
-
* Cancel an order for the exchange on the network
|
|
1059
|
-
* @param {number} userId - Id of order's user
|
|
1060
|
-
* @param {number} orderId - Order id
|
|
1061
|
-
* @return {object} Value of canceled order on the network with values side, size, filled, etc.
|
|
1062
|
-
*/
|
|
1063
|
-
cancelOrder(userId, orderId) {
|
|
1064
|
-
checkKit(this.exchange_id);
|
|
1065
|
-
|
|
1066
|
-
if (!userId) {
|
|
1067
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
1068
|
-
} else if (!orderId) {
|
|
1069
|
-
return reject(parameterError('orderId', 'cannot be null'));
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
const verb = 'DELETE';
|
|
1073
|
-
const path = `${this.baseUrl}/network/${
|
|
1074
|
-
this.exchange_id
|
|
1075
|
-
}/order?user_id=${userId}&order_id=${orderId}`;
|
|
1076
|
-
const headers = generateHeaders(
|
|
1077
|
-
this.headers,
|
|
1078
|
-
this.apiSecret,
|
|
1079
|
-
verb,
|
|
1080
|
-
path,
|
|
1081
|
-
this.apiExpiresAfter
|
|
1082
|
-
);
|
|
1083
|
-
|
|
1084
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
/**
|
|
1088
|
-
* Get all orders for the exchange on the network
|
|
1089
|
-
* @param {object} opts - Optional parameters.
|
|
1090
|
-
* @param {string} opts.symbol - Symbol of orders. Leave blank to get orders for all symbols
|
|
1091
|
-
* @param {string} opts.side - Side of orders to query e.g. buy, sell
|
|
1092
|
-
* @param {string} opts.type - Type of orders to query e.g. active, stop
|
|
1093
|
-
* @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
|
|
1094
|
-
* @param {number} opts.page - Page of trades data. Default: 1
|
|
1095
|
-
* @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
|
|
1096
|
-
* @param {string} opts.order - Ascending (asc) or descending (desc). Default: desc
|
|
1097
|
-
* @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
|
|
1098
|
-
* @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
|
|
1099
|
-
* @return {array} Array of queried orders
|
|
1100
|
-
*/
|
|
1101
|
-
getOrders(
|
|
1102
|
-
opts = {
|
|
1103
|
-
symbol: null,
|
|
1104
|
-
side: null,
|
|
1105
|
-
status: null,
|
|
1106
|
-
open: null,
|
|
1107
|
-
limit: 50,
|
|
1108
|
-
page: 1,
|
|
1109
|
-
orderBy: 'id',
|
|
1110
|
-
order: 'desc',
|
|
1111
|
-
startDate: null,
|
|
1112
|
-
endDate: null
|
|
1113
|
-
}
|
|
1114
|
-
) {
|
|
1115
|
-
checkKit(this.exchange_id);
|
|
1116
|
-
const verb = 'GET';
|
|
1117
|
-
|
|
1118
|
-
let path = `${this.baseUrl}/network/${this.exchange_id}/orders?`;
|
|
1119
|
-
|
|
1120
|
-
if (isNumber(opts.limit)) {
|
|
1121
|
-
path += `&limit=${opts.limit}`;
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
if (isNumber(opts.page)) {
|
|
1125
|
-
path += `&page=${opts.page}`;
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
if (isString(opts.orderBy)) {
|
|
1129
|
-
path += `&order_by=${opts.orderBy}`;
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
if (isString(opts.order)) {
|
|
1133
|
-
path += `&order=${opts.order}`;
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
if (isString(opts.startDate)) {
|
|
1137
|
-
path += `&start_date=${opts.startDate}`;
|
|
1138
|
-
} else if (isDate(opts.startDate)) {
|
|
1139
|
-
path += `&start_date=${opts.startDate.toISOString()}`;
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
if (isString(opts.endDate)) {
|
|
1143
|
-
path += `&end_date=${opts.endDate}`;
|
|
1144
|
-
} else if (isDate(opts.endDate)) {
|
|
1145
|
-
path += `&end_date=${opts.endDate.toISOString()}`;
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
if (opts.symbol) {
|
|
1149
|
-
path += `&symbol=${opts.symbol}`;
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
if (opts.side) {
|
|
1153
|
-
path += `&side=${opts.side}`;
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
if (opts.status) {
|
|
1157
|
-
path += `&status=${opts.status}`;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
if (isBoolean(opts.open)) {
|
|
1161
|
-
path += `&open=${opts.open}`;
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
const headers = generateHeaders(
|
|
1165
|
-
this.headers,
|
|
1166
|
-
this.apiSecret,
|
|
1167
|
-
verb,
|
|
1168
|
-
path,
|
|
1169
|
-
this.apiExpiresAfter
|
|
1170
|
-
);
|
|
1171
|
-
|
|
1172
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
/**
|
|
1176
|
-
* Get all orders for a user on the network
|
|
1177
|
-
* @param {number} userId - User id on network. Leave blank to get all orders for the exchange
|
|
1178
|
-
* @param {object} opts - Optional parameters.
|
|
1179
|
-
* @param {string} opts.symbol - Symbol of orders. Leave blank to get orders for all symbols
|
|
1180
|
-
* @param {string} opts.side - Side of orders to query e.g. buy, sell
|
|
1181
|
-
* @param {string} opts.type - Type of orders to query e.g. active, stop
|
|
1182
|
-
* @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
|
|
1183
|
-
* @param {number} opts.page - Page of trades data. Default: 1
|
|
1184
|
-
* @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
|
|
1185
|
-
* @param {string} opts.order - Ascending (asc) or descending (desc). Default: desc
|
|
1186
|
-
* @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
|
|
1187
|
-
* @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
|
|
1188
|
-
* @return {array} Array of queried orders
|
|
1189
|
-
*/
|
|
1190
|
-
getUserOrders(
|
|
1191
|
-
userId,
|
|
1192
|
-
opts = {
|
|
1193
|
-
symbol: null,
|
|
1194
|
-
side: null,
|
|
1195
|
-
status: null,
|
|
1196
|
-
open: null,
|
|
1197
|
-
limit: 50,
|
|
1198
|
-
page: 1,
|
|
1199
|
-
orderBy: 'id',
|
|
1200
|
-
order: 'desc',
|
|
1201
|
-
startDate: null,
|
|
1202
|
-
endDate: null
|
|
1203
|
-
}
|
|
1204
|
-
) {
|
|
1205
|
-
checkKit(this.exchange_id);
|
|
1206
|
-
|
|
1207
|
-
if (!userId) {
|
|
1208
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
const verb = 'GET';
|
|
1212
|
-
|
|
1213
|
-
let path = `${this.baseUrl}/network/${this.exchange_id}/orders?user_id=${userId}`;
|
|
1214
|
-
|
|
1215
|
-
if (isNumber(opts.limit)) {
|
|
1216
|
-
path += `&limit=${opts.limit}`;
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
if (isNumber(opts.page)) {
|
|
1220
|
-
path += `&page=${opts.page}`;
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
if (isString(opts.orderBy)) {
|
|
1224
|
-
path += `&order_by=${opts.orderBy}`;
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
if (isString(opts.order)) {
|
|
1228
|
-
path += `&order=${opts.order}`;
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
if (isString(opts.startDate)) {
|
|
1232
|
-
path += `&start_date=${opts.startDate}`;
|
|
1233
|
-
} else if (isDate(opts.startDate)) {
|
|
1234
|
-
path += `&start_date=${opts.startDate.toISOString()}`;
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
if (isString(opts.endDate)) {
|
|
1238
|
-
path += `&end_date=${opts.endDate}`;
|
|
1239
|
-
} else if (isDate(opts.endDate)) {
|
|
1240
|
-
path += `&end_date=${opts.endDate.toISOString()}`;
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
if (opts.symbol) {
|
|
1244
|
-
path += `&symbol=${opts.symbol}`;
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
if (opts.side) {
|
|
1248
|
-
path += `&side=${opts.side}`;
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
if (opts.status) {
|
|
1252
|
-
path += `&status=${opts.status}`;
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
if (isBoolean(opts.open)) {
|
|
1256
|
-
path += `&open=${opts.open}`;
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
const headers = generateHeaders(
|
|
1260
|
-
this.headers,
|
|
1261
|
-
this.apiSecret,
|
|
1262
|
-
verb,
|
|
1263
|
-
path,
|
|
1264
|
-
this.apiExpiresAfter
|
|
1265
|
-
);
|
|
1266
|
-
|
|
1267
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
/**
|
|
1271
|
-
* Cancel all orders for an exchange's user on the network
|
|
1272
|
-
* @param {number} userId - User id on network
|
|
1273
|
-
* @param {object} opts - Optional parameters.
|
|
1274
|
-
* @param {string} opts.symbol - Symbol of orders to cancel. Leave blank to cancel user's orders for all symbols
|
|
1275
|
-
* @return {array} Array of canceled orders
|
|
1276
|
-
*/
|
|
1277
|
-
cancelAllOrders(userId, opts = { symbol: null }) {
|
|
1278
|
-
checkKit(this.exchange_id);
|
|
1279
|
-
|
|
1280
|
-
if (!userId) {
|
|
1281
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
const verb = 'DELETE';
|
|
1285
|
-
|
|
1286
|
-
let path = `${this.baseUrl}/network/${
|
|
1287
|
-
this.exchange_id
|
|
1288
|
-
}/order/all?user_id=${userId}`;
|
|
1289
|
-
if (opts.symbol) {
|
|
1290
|
-
path += `&symbol=${opts.symbol}`;
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
const headers = generateHeaders(
|
|
1294
|
-
this.headers,
|
|
1295
|
-
this.apiSecret,
|
|
1296
|
-
verb,
|
|
1297
|
-
path,
|
|
1298
|
-
this.apiExpiresAfter
|
|
1299
|
-
);
|
|
1300
|
-
|
|
1301
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
/**
|
|
1305
|
-
* Get sum of user trades and its stats
|
|
1306
|
-
* @param {number} userId - User id on network
|
|
1307
|
-
* @return {object} Object with field data that contains stats info
|
|
1308
|
-
*/
|
|
1309
|
-
getUserStats(userId) {
|
|
1310
|
-
checkKit(this.exchange_id);
|
|
1311
|
-
|
|
1312
|
-
if (!userId) {
|
|
1313
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
const verb = 'GET';
|
|
1317
|
-
const path = `${this.baseUrl}/network/${
|
|
1318
|
-
this.exchange_id
|
|
1319
|
-
}/user/stats?user_id=${userId}`;
|
|
1320
|
-
const headers = generateHeaders(
|
|
1321
|
-
this.headers,
|
|
1322
|
-
this.apiSecret,
|
|
1323
|
-
verb,
|
|
1324
|
-
path,
|
|
1325
|
-
this.apiExpiresAfter
|
|
1326
|
-
);
|
|
1327
|
-
|
|
1328
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
/**
|
|
1332
|
-
* Check transaction in network. Will update transaction status on Kit accordingly
|
|
1333
|
-
* @param {string} currency; - Currency of transaction
|
|
1334
|
-
* @param {string} transactionId - Transaction id
|
|
1335
|
-
* @param {string} address - Transaction receiving address
|
|
1336
|
-
* @param {object} opts - Optional parameters.
|
|
1337
|
-
* @param {boolean} opts.isTestnet - Network transaction was made on. Default: false
|
|
1338
|
-
* @return {object} Success or failed message
|
|
1339
|
-
*/
|
|
1340
|
-
checkTransaction(
|
|
1341
|
-
currency,
|
|
1342
|
-
transactionId,
|
|
1343
|
-
address,
|
|
1344
|
-
opts = { isTestnet: null }
|
|
1345
|
-
) {
|
|
1346
|
-
checkKit(this.exchange_id);
|
|
1347
|
-
|
|
1348
|
-
if (!currency) {
|
|
1349
|
-
return reject(parameterError('currency', 'cannot be null'));
|
|
1350
|
-
} else if (!transactionId) {
|
|
1351
|
-
return reject(parameterError('transactionId', 'cannot be null'));
|
|
1352
|
-
} else if (!address) {
|
|
1353
|
-
return reject(parameterError('address', 'cannot be null'));
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
const verb = 'GET';
|
|
1357
|
-
let path = `${this.baseUrl}/check-transaction?currency=${currency}&transaction_id=${transactionId}&address=${address}`;
|
|
1358
|
-
|
|
1359
|
-
if (isBoolean(opts.isTestnet)) {
|
|
1360
|
-
path += `&is_testnet=${opts.isTestnet}`;
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
const headers = generateHeaders(
|
|
1364
|
-
this.headers,
|
|
1365
|
-
this.apiSecret,
|
|
1366
|
-
verb,
|
|
1367
|
-
path,
|
|
1368
|
-
this.apiExpiresAfter
|
|
1369
|
-
);
|
|
1370
|
-
|
|
1371
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
/**
|
|
1375
|
-
* Transfer funds between two users
|
|
1376
|
-
* @param {number} senderId; - Network id of user that is sending funds
|
|
1377
|
-
* @param {number} receiverId - Network id of user that is receiving funds
|
|
1378
|
-
* @param {string} currency - Currency to transfer
|
|
1379
|
-
* @param {number} amount - Amount to transfer
|
|
1380
|
-
* @param {object} opts - Optional parameters.
|
|
1381
|
-
* @param {string} opts.description - Description of transfer. Default: Empty string
|
|
1382
|
-
* @param {boolean} opts.email - Send email to users after transfer. Default: true.
|
|
1383
|
-
* @return {object} Object with field transaction_id
|
|
1384
|
-
*/
|
|
1385
|
-
transferAsset(
|
|
1386
|
-
senderId,
|
|
1387
|
-
receiverId,
|
|
1388
|
-
currency,
|
|
1389
|
-
amount,
|
|
1390
|
-
opts = { description: null, email: true }
|
|
1391
|
-
) {
|
|
1392
|
-
checkKit(this.exchange_id);
|
|
1393
|
-
|
|
1394
|
-
if (!senderId) {
|
|
1395
|
-
return reject(parameterError('senderId', 'cannot be null'));
|
|
1396
|
-
} else if (!receiverId) {
|
|
1397
|
-
return reject(parameterError('receiverId', 'cannot be null'));
|
|
1398
|
-
} else if (!currency) {
|
|
1399
|
-
return reject(parameterError('currency', 'cannot be null'));
|
|
1400
|
-
} else if (!amount) {
|
|
1401
|
-
return reject(parameterError('amount', 'cannot be null'));
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
const verb = 'POST';
|
|
1405
|
-
const path = `${this.baseUrl}/network/${
|
|
1406
|
-
this.exchange_id
|
|
1407
|
-
}/transfer`;
|
|
1408
|
-
const data = {
|
|
1409
|
-
sender_id: senderId,
|
|
1410
|
-
receiver_id: receiverId,
|
|
1411
|
-
currency,
|
|
1412
|
-
amount
|
|
1413
|
-
};
|
|
1414
|
-
|
|
1415
|
-
if (opts.description) {
|
|
1416
|
-
data.description = opts.description;
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
if (isBoolean(opts.email)) {
|
|
1420
|
-
data.email = opts.email;
|
|
1421
|
-
} else {
|
|
1422
|
-
data.email = true;
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
const headers = generateHeaders(
|
|
1426
|
-
this.headers,
|
|
1427
|
-
this.apiSecret,
|
|
1428
|
-
verb,
|
|
1429
|
-
path,
|
|
1430
|
-
this.apiExpiresAfter,
|
|
1431
|
-
data
|
|
1432
|
-
);
|
|
1433
|
-
|
|
1434
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers, data);
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
|
-
/**
|
|
1438
|
-
* Get trade history for exchange on network
|
|
1439
|
-
* @param {object} opts - Optional parameters.
|
|
1440
|
-
* @param {string} opts.symbol - Symbol of trades.
|
|
1441
|
-
* @param {string} opts.side - Side of trades.
|
|
1442
|
-
* @param {number} opts.limit - Amount of trades per page. Maximum: 50. Default: 50
|
|
1443
|
-
* @param {number} opts.page - Page of trades data. Default: 1
|
|
1444
|
-
* @param {string} opts.orderBy - The field to order data by e.g. amount, id. Default: id
|
|
1445
|
-
* @param {string} opts.order - Ascending (asc) or descending (desc). Default: asc
|
|
1446
|
-
* @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
|
|
1447
|
-
* @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
|
|
1448
|
-
* @return {object} Count and data format.
|
|
1449
|
-
*/
|
|
1450
|
-
getTradesHistory(
|
|
1451
|
-
opts = {
|
|
1452
|
-
symbol: null,
|
|
1453
|
-
side: null,
|
|
1454
|
-
limit: 50,
|
|
1455
|
-
page: 1,
|
|
1456
|
-
orderBy: 'id',
|
|
1457
|
-
order: 'asc',
|
|
1458
|
-
startDate: null,
|
|
1459
|
-
endDate: null
|
|
1460
|
-
}
|
|
1461
|
-
) {
|
|
1462
|
-
checkKit(this.exchange_id);
|
|
1463
|
-
const verb = 'GET';
|
|
1464
|
-
|
|
1465
|
-
let path = `${this.baseUrl}/network/${
|
|
1466
|
-
this.exchange_id
|
|
1467
|
-
}/trades/history?`;
|
|
1468
|
-
|
|
1469
|
-
if (isNumber(opts.limit)) {
|
|
1470
|
-
path += `&limit=${opts.limit}`;
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
|
-
if (isNumber(opts.page)) {
|
|
1474
|
-
path += `&page=${opts.page}`;
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
if (isString(opts.orderBy)) {
|
|
1478
|
-
path += `&order_by=${opts.orderBy}`;
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
if (isString(opts.order)) {
|
|
1482
|
-
path += `&order=${opts.order}`;
|
|
1483
|
-
}
|
|
1484
|
-
|
|
1485
|
-
if (isString(opts.startDate)) {
|
|
1486
|
-
path += `&start_date=${opts.startDate}`;
|
|
1487
|
-
} else if (isDate(opts.startDate)) {
|
|
1488
|
-
path += `&start_date=${opts.startDate.toISOString()}`;
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
if (isString(opts.endDate)) {
|
|
1492
|
-
path += `&end_date=${opts.endDate}`;
|
|
1493
|
-
} else if (isDate(opts.endDate)) {
|
|
1494
|
-
path += `&end_date=${opts.endDate.toISOString()}`;
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
if (opts.symbol) {
|
|
1498
|
-
path += `&symbol=${opts.symbol}`;
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
if (opts.side) {
|
|
1502
|
-
path += `&side=${opts.side}`;
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
const headers = generateHeaders(
|
|
1506
|
-
this.headers,
|
|
1507
|
-
this.apiSecret,
|
|
1508
|
-
verb,
|
|
1509
|
-
path,
|
|
1510
|
-
this.apiExpiresAfter
|
|
1511
|
-
);
|
|
1512
|
-
|
|
1513
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
/* Network Engine Endpoints*/
|
|
1517
|
-
|
|
1518
|
-
/**
|
|
1519
|
-
* Get Public trades on network
|
|
1520
|
-
* @param {object} opts - Optional parameters.
|
|
1521
|
-
* @param {string} opts.symbol - Symbol to get trades for. Leave blank to get trades of all symbols
|
|
1522
|
-
* @return {object} Object with trades
|
|
1523
|
-
*/
|
|
1524
|
-
getPublicTrades(opts = { symbol: null }) {
|
|
1525
|
-
checkKit(this.exchange_id);
|
|
1526
|
-
const verb = 'GET';
|
|
1527
|
-
let path = `${this.baseUrl}/network/${this.exchange_id}/trades`;
|
|
1528
|
-
|
|
1529
|
-
if (opts.symbol) {
|
|
1530
|
-
path += `?symbol=${opts.symbol}`;
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
const headers = generateHeaders(
|
|
1534
|
-
this.headers,
|
|
1535
|
-
this.apiSecret,
|
|
1536
|
-
verb,
|
|
1537
|
-
path,
|
|
1538
|
-
this.apiExpiresAfter
|
|
1539
|
-
);
|
|
1540
|
-
|
|
1541
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
/**
|
|
1545
|
-
* Get top orderbook for specific symbol
|
|
1546
|
-
* @param {string} symbol - Symbol to get orderbook for. Leave blank to get orderbook of all symbols
|
|
1547
|
-
* @return {object} Object with orderbook
|
|
1548
|
-
*/
|
|
1549
|
-
getOrderbook(symbol) {
|
|
1550
|
-
checkKit(this.exchange_id);
|
|
1551
|
-
|
|
1552
|
-
if (!symbol) {
|
|
1553
|
-
return reject(parameterError('symbol', 'cannot be null'));
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
const verb = 'GET';
|
|
1557
|
-
let path = `${this.baseUrl}/network/${
|
|
1558
|
-
this.exchange_id
|
|
1559
|
-
}/orderbook`;
|
|
1560
|
-
|
|
1561
|
-
if (symbol) {
|
|
1562
|
-
path += `?symbol=${symbol}`;
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
const headers = generateHeaders(
|
|
1566
|
-
this.headers,
|
|
1567
|
-
this.apiSecret,
|
|
1568
|
-
verb,
|
|
1569
|
-
path,
|
|
1570
|
-
this.apiExpiresAfter
|
|
1571
|
-
);
|
|
1572
|
-
|
|
1573
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1574
|
-
}
|
|
1575
|
-
|
|
1576
|
-
/**
|
|
1577
|
-
* Get top orderbooks
|
|
1578
|
-
* @param {string} symbol - Symbol to get orderbook for. Leave blank to get orderbook of all symbols
|
|
1579
|
-
* @return {object} Object with orderbook
|
|
1580
|
-
*/
|
|
1581
|
-
getOrderbooks() {
|
|
1582
|
-
checkKit(this.exchange_id);
|
|
1583
|
-
const verb = 'GET';
|
|
1584
|
-
let path = `${this.baseUrl}/network/${
|
|
1585
|
-
this.exchange_id
|
|
1586
|
-
}/orderbooks`;
|
|
1587
|
-
|
|
1588
|
-
const headers = generateHeaders(
|
|
1589
|
-
this.headers,
|
|
1590
|
-
this.apiSecret,
|
|
1591
|
-
verb,
|
|
1592
|
-
path,
|
|
1593
|
-
this.apiExpiresAfter
|
|
1594
|
-
);
|
|
1595
|
-
|
|
1596
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1599
|
-
/**
|
|
1600
|
-
* Get TradingView trade history HOLCV
|
|
1601
|
-
* @param {string} from - Starting date of trade history in UNIX timestamp format
|
|
1602
|
-
* @param {string} to - Ending date of trade history in UNIX timestamp format
|
|
1603
|
-
* @param {string} symbol - Symbol to get trade history for
|
|
1604
|
-
* @param {string} resolution - Resolution of trade history. 1d, 1W, etc
|
|
1605
|
-
* @return {object} Object with trade history info
|
|
1606
|
-
*/
|
|
1607
|
-
getChart(from, to, symbol, resolution) {
|
|
1608
|
-
checkKit(this.exchange_id);
|
|
1609
|
-
|
|
1610
|
-
if (!from) {
|
|
1611
|
-
return reject(parameterError('from', 'cannot be null'));
|
|
1612
|
-
} else if (!to) {
|
|
1613
|
-
return reject(parameterError('to', 'cannot be null'));
|
|
1614
|
-
} else if (!symbol) {
|
|
1615
|
-
return reject(parameterError('symbol', 'cannot be null'));
|
|
1616
|
-
} else if (!resolution) {
|
|
1617
|
-
return reject(parameterError('resolution', 'cannot be null'));
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
const verb = 'GET';
|
|
1621
|
-
const path = `${this.baseUrl}/network/${
|
|
1622
|
-
this.exchange_id
|
|
1623
|
-
}/chart?from=${from}&to=${to}&symbol=${symbol}&resolution=${resolution}`;
|
|
1624
|
-
const headers = generateHeaders(
|
|
1625
|
-
this.headers,
|
|
1626
|
-
this.apiSecret,
|
|
1627
|
-
verb,
|
|
1628
|
-
path,
|
|
1629
|
-
this.apiExpiresAfter
|
|
1630
|
-
);
|
|
1631
|
-
|
|
1632
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
/**
|
|
1636
|
-
* Get TradingView trade history HOLCV for all pairs
|
|
1637
|
-
* @param {string} from - Starting date of trade history in UNIX timestamp format
|
|
1638
|
-
* @param {string} to - Ending date of trade history in UNIX timestamp format
|
|
1639
|
-
* @param {string} resolution - Resolution of trade history. 1d, 1W, etc
|
|
1640
|
-
* @return {array} Array of objects with trade history info
|
|
1641
|
-
*/
|
|
1642
|
-
getCharts(from, to, resolution) {
|
|
1643
|
-
checkKit(this.exchange_id);
|
|
1644
|
-
|
|
1645
|
-
if (!from) {
|
|
1646
|
-
return reject(parameterError('from', 'cannot be null'));
|
|
1647
|
-
} else if (!to) {
|
|
1648
|
-
return reject(parameterError('to', 'cannot be null'));
|
|
1649
|
-
} else if (!resolution) {
|
|
1650
|
-
return reject(parameterError('resolution', 'cannot be null'));
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
const verb = 'GET';
|
|
1654
|
-
const path = `${this.baseUrl}/network/${
|
|
1655
|
-
this.exchange_id
|
|
1656
|
-
}/charts?from=${from}&to=${to}&resolution=${resolution}`;
|
|
1657
|
-
const headers = generateHeaders(
|
|
1658
|
-
this.headers,
|
|
1659
|
-
this.apiSecret,
|
|
1660
|
-
verb,
|
|
1661
|
-
path,
|
|
1662
|
-
this.apiExpiresAfter
|
|
1663
|
-
);
|
|
1664
|
-
|
|
1665
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
/**
|
|
1669
|
-
* Get TradingView udf config
|
|
1670
|
-
* @return {object} Object with TradingView udf config
|
|
1671
|
-
*/
|
|
1672
|
-
getUdfConfig() {
|
|
1673
|
-
checkKit(this.exchange_id);
|
|
1674
|
-
const verb = 'GET';
|
|
1675
|
-
const path = `${this.baseUrl}/network/${
|
|
1676
|
-
this.exchange_id
|
|
1677
|
-
}/udf/config`;
|
|
1678
|
-
const headers = generateHeaders(
|
|
1679
|
-
this.headers,
|
|
1680
|
-
this.apiSecret,
|
|
1681
|
-
verb,
|
|
1682
|
-
path,
|
|
1683
|
-
this.apiExpiresAfter
|
|
1684
|
-
);
|
|
1685
|
-
|
|
1686
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
|
-
/**
|
|
1690
|
-
* Get TradingView udf history HOLCV
|
|
1691
|
-
* @param {string} from - Starting date in UNIX timestamp format
|
|
1692
|
-
* @param {string} to - Ending date in UNIX timestamp format
|
|
1693
|
-
* @param {string} symbol - Symbol to get
|
|
1694
|
-
* @param {string} resolution - Resolution of query. 1d, 1W, etc
|
|
1695
|
-
* @return {object} Object with TradingView udf history HOLCV
|
|
1696
|
-
*/
|
|
1697
|
-
getUdfHistory(from, to, symbol, resolution) {
|
|
1698
|
-
checkKit(this.exchange_id);
|
|
1699
|
-
|
|
1700
|
-
if (!from) {
|
|
1701
|
-
return reject(parameterError('from', 'cannot be null'));
|
|
1702
|
-
} else if (!to) {
|
|
1703
|
-
return reject(parameterError('to', 'cannot be null'));
|
|
1704
|
-
} else if (!symbol) {
|
|
1705
|
-
return reject(parameterError('symbol', 'cannot be null'));
|
|
1706
|
-
} else if (!resolution) {
|
|
1707
|
-
return reject(parameterError('resolution', 'cannot be null'));
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1710
|
-
const verb = 'GET';
|
|
1711
|
-
const path = `${this.baseUrl}/network/${
|
|
1712
|
-
this.exchange_id
|
|
1713
|
-
}/udf/history?from=${from}&to=${to}&symbol=${symbol}&resolution=${resolution}`;
|
|
1714
|
-
const headers = generateHeaders(
|
|
1715
|
-
this.headers,
|
|
1716
|
-
this.apiSecret,
|
|
1717
|
-
verb,
|
|
1718
|
-
path,
|
|
1719
|
-
this.apiExpiresAfter
|
|
1720
|
-
);
|
|
1721
|
-
|
|
1722
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
/**
|
|
1726
|
-
* Get TradingView udf symbols
|
|
1727
|
-
* @param {string} symbol - Symbol to get
|
|
1728
|
-
* @return {object} Object with TradingView udf symbols
|
|
1729
|
-
*/
|
|
1730
|
-
getUdfSymbols(symbol) {
|
|
1731
|
-
checkKit(this.exchange_id);
|
|
1732
|
-
|
|
1733
|
-
if (!symbol) {
|
|
1734
|
-
return reject(parameterError('symbol', 'cannot be null'));
|
|
1735
|
-
}
|
|
1736
|
-
|
|
1737
|
-
const verb = 'GET';
|
|
1738
|
-
const path = `${this.baseUrl}/network/${
|
|
1739
|
-
this.exchange_id
|
|
1740
|
-
}/udf/symbols?symbol=${symbol}`;
|
|
1741
|
-
const headers = generateHeaders(
|
|
1742
|
-
this.headers,
|
|
1743
|
-
this.apiSecret,
|
|
1744
|
-
verb,
|
|
1745
|
-
path,
|
|
1746
|
-
this.apiExpiresAfter
|
|
1747
|
-
);
|
|
1748
|
-
|
|
1749
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1750
|
-
}
|
|
1751
|
-
|
|
1752
|
-
/**
|
|
1753
|
-
* Get historical data, time interval is 5 minutes
|
|
1754
|
-
* @param {string} symbol - Symbol to get
|
|
1755
|
-
* @return {object} Object with historical data
|
|
1756
|
-
*/
|
|
1757
|
-
getTicker(symbol) {
|
|
1758
|
-
checkKit(this.exchange_id);
|
|
1759
|
-
|
|
1760
|
-
if (!symbol) {
|
|
1761
|
-
return reject(parameterError('symbol', 'cannot be null'));
|
|
1762
|
-
}
|
|
1763
|
-
|
|
1764
|
-
const verb = 'GET';
|
|
1765
|
-
let path = `${this.baseUrl}/network/${this.exchange_id}/ticker`;
|
|
1766
|
-
|
|
1767
|
-
if (symbol) {
|
|
1768
|
-
path += `?symbol=${symbol}`;
|
|
1769
|
-
}
|
|
1770
|
-
|
|
1771
|
-
const headers = generateHeaders(
|
|
1772
|
-
this.headers,
|
|
1773
|
-
this.apiSecret,
|
|
1774
|
-
verb,
|
|
1775
|
-
path,
|
|
1776
|
-
this.apiExpiresAfter
|
|
1777
|
-
);
|
|
1778
|
-
|
|
1779
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1780
|
-
}
|
|
1781
|
-
|
|
1782
|
-
/**
|
|
1783
|
-
* Get historical data for all symbols, time interval is 5 minutes
|
|
1784
|
-
* @return {object} Object with historical data for all symbols
|
|
1785
|
-
*/
|
|
1786
|
-
getTickers() {
|
|
1787
|
-
checkKit(this.exchange_id);
|
|
1788
|
-
const verb = 'GET';
|
|
1789
|
-
const path = `${this.baseUrl}/network/${
|
|
1790
|
-
this.exchange_id
|
|
1791
|
-
}/tickers`;
|
|
1792
|
-
const headers = generateHeaders(
|
|
1793
|
-
this.headers,
|
|
1794
|
-
this.apiSecret,
|
|
1795
|
-
verb,
|
|
1796
|
-
path,
|
|
1797
|
-
this.apiExpiresAfter
|
|
1798
|
-
);
|
|
1799
|
-
|
|
1800
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
/**
|
|
1804
|
-
* Mint an asset you own to a user
|
|
1805
|
-
* @param {number} userId; - Network id of user.
|
|
1806
|
-
* @param {string} currency - Currency to mint.
|
|
1807
|
-
* @param {number} amount - Amount to mint.
|
|
1808
|
-
* @param {object} opts - Optional parameters.
|
|
1809
|
-
* @param {string} opts.description - Description of transfer. Default: Empty string
|
|
1810
|
-
* @param {string} opts.transactionId - Custom transaction ID for mint.
|
|
1811
|
-
* @param {boolean} opts.status - Status of mint created. Default: true.
|
|
1812
|
-
* @return {object} Object with created mint's data.
|
|
1813
|
-
*/
|
|
1814
|
-
mintAsset(userId, currency, amount, opts = { description: null, transactionId: null, status: null }) {
|
|
1815
|
-
if (!userId) {
|
|
1816
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
1817
|
-
} else if (!currency) {
|
|
1818
|
-
return reject(parameterError('currency', 'cannot be null'));
|
|
1819
|
-
} else if (!amount) {
|
|
1820
|
-
return reject(parameterError('amount', 'cannot be null'));
|
|
1821
|
-
}
|
|
1822
|
-
|
|
1823
|
-
const verb = 'POST';
|
|
1824
|
-
const path = `${this.baseUrl}/network/mint`;
|
|
1825
|
-
const data = {
|
|
1826
|
-
user_id: userId,
|
|
1827
|
-
currency,
|
|
1828
|
-
amount
|
|
1829
|
-
};
|
|
1830
|
-
|
|
1831
|
-
if (opts.description) {
|
|
1832
|
-
data.description = opts.description;
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1835
|
-
if (opts.transactionId) {
|
|
1836
|
-
data.transaction_id = opts.transactionId;
|
|
1837
|
-
}
|
|
1838
|
-
|
|
1839
|
-
if (isBoolean(opts.status)) {
|
|
1840
|
-
data.status = opts.status;
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
const headers = generateHeaders(
|
|
1844
|
-
this.headers,
|
|
1845
|
-
this.apiSecret,
|
|
1846
|
-
verb,
|
|
1847
|
-
path,
|
|
1848
|
-
this.apiExpiresAfter,
|
|
1849
|
-
data
|
|
1850
|
-
);
|
|
1851
|
-
|
|
1852
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers, data);
|
|
1853
|
-
}
|
|
1854
|
-
|
|
1855
|
-
/**
|
|
1856
|
-
* Update a pending mint
|
|
1857
|
-
* @param {string} transactionId; - Transaction ID of pending mint.
|
|
1858
|
-
* @param {object} opts - Optional parameters.
|
|
1859
|
-
* @param {boolean} opts.status - Set to true to confirm pending mint.
|
|
1860
|
-
* @param {boolean} opts.dismissed - Set to true to dismiss pending mint.
|
|
1861
|
-
* @param {boolean} opts.rejected - Set to true to reject pending mint.
|
|
1862
|
-
* @param {string} opts.updatedTransactionId - Value to update transaction ID of pending mint to.
|
|
1863
|
-
* @return {object} Object with updated mint's data.
|
|
1864
|
-
*/
|
|
1865
|
-
updatePendingMint(transactionId, opts = { status: null, dismissed: null, rejected: null, updatedTransactionId: null }) {
|
|
1866
|
-
if (!transactionId) {
|
|
1867
|
-
return reject(parameterError('transactionId', 'cannot be null'));
|
|
1868
|
-
}
|
|
1869
|
-
|
|
1870
|
-
const status = isBoolean(opts.status) ? opts.status : false;
|
|
1871
|
-
const rejected = isBoolean(opts.rejected) ? opts.rejected : false;
|
|
1872
|
-
const dismissed = isBoolean(opts.dismissed) ? opts.dismissed : false;
|
|
1873
|
-
|
|
1874
|
-
if (!status && !rejected && !dismissed) {
|
|
1875
|
-
return reject(new Error('Must give one parameter to update'));
|
|
1876
|
-
} else if (
|
|
1877
|
-
status && (rejected || dismissed)
|
|
1878
|
-
|| rejected && (status || dismissed)
|
|
1879
|
-
|| dismissed && (status || rejected)
|
|
1880
|
-
) {
|
|
1881
|
-
return reject(new Error('Can only update one parmaeter'));
|
|
1882
|
-
}
|
|
1883
|
-
|
|
1884
|
-
const verb = 'PUT';
|
|
1885
|
-
const path = `${this.baseUrl}/network/mint`;
|
|
1886
|
-
const data = {
|
|
1887
|
-
transaction_id: transactionId,
|
|
1888
|
-
status,
|
|
1889
|
-
rejected,
|
|
1890
|
-
dismissed
|
|
1891
|
-
};
|
|
1892
|
-
|
|
1893
|
-
if (opts.updatedTransactionId) {
|
|
1894
|
-
data.updated_transaction_id = opts.updatedTransactionId;
|
|
1895
|
-
}
|
|
1896
|
-
|
|
1897
|
-
const headers = generateHeaders(
|
|
1898
|
-
this.headers,
|
|
1899
|
-
this.apiSecret,
|
|
1900
|
-
verb,
|
|
1901
|
-
path,
|
|
1902
|
-
this.apiExpiresAfter,
|
|
1903
|
-
data
|
|
1904
|
-
);
|
|
1905
|
-
|
|
1906
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers, data);
|
|
1907
|
-
}
|
|
1908
|
-
|
|
1909
|
-
/**
|
|
1910
|
-
* Burn an asset you own to a user
|
|
1911
|
-
* @param {number} userId; - Network id of user.
|
|
1912
|
-
* @param {string} currency - Currency to burn.
|
|
1913
|
-
* @param {number} amount - Amount to burn.
|
|
1914
|
-
* @param {object} opts - Optional parameters.
|
|
1915
|
-
* @param {string} opts.description - Description of transfer. Default: Empty string
|
|
1916
|
-
* @param {string} opts.transactionId - Custom transaction ID for burn.
|
|
1917
|
-
* @param {boolean} opts.status - Status of burn created. Default: true.
|
|
1918
|
-
* @return {object} Object with created burn's data.
|
|
1919
|
-
*/
|
|
1920
|
-
burnAsset(userId, currency, amount, opts = { description: null, transactionId: null, status: null }) {
|
|
1921
|
-
if (!userId) {
|
|
1922
|
-
return reject(parameterError('userId', 'cannot be null'));
|
|
1923
|
-
} else if (!currency) {
|
|
1924
|
-
return reject(parameterError('currency', 'cannot be null'));
|
|
1925
|
-
} else if (!amount) {
|
|
1926
|
-
return reject(parameterError('amount', 'cannot be null'));
|
|
1927
|
-
}
|
|
1928
|
-
|
|
1929
|
-
const verb = 'POST';
|
|
1930
|
-
const path = `${this.baseUrl}/network/burn`;
|
|
1931
|
-
const data = {
|
|
1932
|
-
user_id: userId,
|
|
1933
|
-
currency,
|
|
1934
|
-
amount
|
|
1935
|
-
};
|
|
1936
|
-
|
|
1937
|
-
if (opts.description) {
|
|
1938
|
-
data.description = opts.description;
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
|
-
if (opts.transactionId) {
|
|
1942
|
-
data.transaction_id = opts.transactionId;
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
|
-
if (isBoolean(opts.status)) {
|
|
1946
|
-
data.status = opts.status;
|
|
1947
|
-
}
|
|
1948
|
-
|
|
1949
|
-
const headers = generateHeaders(
|
|
1950
|
-
this.headers,
|
|
1951
|
-
this.apiSecret,
|
|
1952
|
-
verb,
|
|
1953
|
-
path,
|
|
1954
|
-
this.apiExpiresAfter,
|
|
1955
|
-
data
|
|
1956
|
-
);
|
|
1957
|
-
|
|
1958
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers, data);
|
|
1959
|
-
}
|
|
1960
|
-
|
|
1961
|
-
/**
|
|
1962
|
-
* Update a pending burn
|
|
1963
|
-
* @param {string} transactionId; - Transaction ID of pending burn.
|
|
1964
|
-
* @param {object} opts - Optional parameters.
|
|
1965
|
-
* @param {boolean} opts.status - Set to true to confirm pending burn.
|
|
1966
|
-
* @param {boolean} opts.dismissed - Set to true to dismiss pending burn.
|
|
1967
|
-
* @param {boolean} opts.rejected - Set to true to reject pending burn.
|
|
1968
|
-
* @param {string} opts.updatedTransactionId - Value to update transaction ID of pending burn to.
|
|
1969
|
-
* @return {object} Object with updated burn's data.
|
|
1970
|
-
*/
|
|
1971
|
-
updatePendingBurn(transactionId, opts = { status: null, dismissed: null, rejected: null, updatedTransactionId: null }) {
|
|
1972
|
-
if (!transactionId) {
|
|
1973
|
-
return reject(parameterError('transactionId', 'cannot be null'));
|
|
1974
|
-
}
|
|
1975
|
-
|
|
1976
|
-
const status = isBoolean(opts.status) ? opts.status : false;
|
|
1977
|
-
const rejected = isBoolean(opts.rejected) ? opts.rejected : false;
|
|
1978
|
-
const dismissed = isBoolean(opts.dismissed) ? opts.dismissed : false;
|
|
1979
|
-
|
|
1980
|
-
if (!status && !rejected && !dismissed) {
|
|
1981
|
-
return reject(new Error('Must give one parameter to update'));
|
|
1982
|
-
} else if (
|
|
1983
|
-
status && (rejected || dismissed)
|
|
1984
|
-
|| rejected && (status || dismissed)
|
|
1985
|
-
|| dismissed && (status || rejected)
|
|
1986
|
-
) {
|
|
1987
|
-
return reject(new Error('Can only update one parmaeter'));
|
|
1988
|
-
}
|
|
1989
|
-
|
|
1990
|
-
const verb = 'PUT';
|
|
1991
|
-
const path = `${this.baseUrl}/network/burn`;
|
|
1992
|
-
const data = {
|
|
1993
|
-
transaction_id: transactionId,
|
|
1994
|
-
status,
|
|
1995
|
-
rejected,
|
|
1996
|
-
dismissed
|
|
1997
|
-
};
|
|
1998
|
-
|
|
1999
|
-
if (opts.updatedTransactionId) {
|
|
2000
|
-
data.updated_transaction_id = opts.updatedTransactionId;
|
|
2001
|
-
}
|
|
2002
|
-
|
|
2003
|
-
const headers = generateHeaders(
|
|
2004
|
-
this.headers,
|
|
2005
|
-
this.apiSecret,
|
|
2006
|
-
verb,
|
|
2007
|
-
path,
|
|
2008
|
-
this.apiExpiresAfter,
|
|
2009
|
-
data
|
|
2010
|
-
);
|
|
2011
|
-
|
|
2012
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers, data);
|
|
2013
|
-
}
|
|
2014
|
-
|
|
2015
|
-
/**
|
|
2016
|
-
* Get generated fees for exchange
|
|
2017
|
-
* @param {object} opts - Optional parameters.
|
|
2018
|
-
* @param {string} opts.startDate - Start date of query in ISO8601 format. Default: 0
|
|
2019
|
-
* @param {string} opts.endDate - End date of query in ISO8601 format: Default: current time in ISO8601 format
|
|
2020
|
-
* @return {object} Object with generated fees
|
|
2021
|
-
*/
|
|
2022
|
-
getGeneratedFees(
|
|
2023
|
-
opts = {
|
|
2024
|
-
startDate: null,
|
|
2025
|
-
endDate: null
|
|
2026
|
-
}
|
|
2027
|
-
) {
|
|
2028
|
-
checkKit(this.exchange_id);
|
|
2029
|
-
const verb = 'GET';
|
|
2030
|
-
|
|
2031
|
-
let path = `${this.baseUrl}/network/${this.exchange_id}/fees?`;
|
|
2032
|
-
|
|
2033
|
-
if (isString(opts.startDate)) {
|
|
2034
|
-
path += `&start_date=${opts.startDate}`;
|
|
2035
|
-
} else if (isDate(opts.startDate)) {
|
|
2036
|
-
path += `&start_date=${opts.startDate.toISOString()}`;
|
|
2037
|
-
}
|
|
2038
|
-
|
|
2039
|
-
if (isString(opts.endDate)) {
|
|
2040
|
-
path += `&end_date=${opts.endDate}`;
|
|
2041
|
-
} else if (isDate(opts.endDate)) {
|
|
2042
|
-
path += `&end_date=${opts.endDate.toISOString()}`;
|
|
2043
|
-
}
|
|
2044
|
-
|
|
2045
|
-
const headers = generateHeaders(
|
|
2046
|
-
this.headers,
|
|
2047
|
-
this.apiSecret,
|
|
2048
|
-
verb,
|
|
2049
|
-
path,
|
|
2050
|
-
this.apiExpiresAfter
|
|
2051
|
-
);
|
|
2052
|
-
|
|
2053
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
2054
|
-
}
|
|
2055
|
-
|
|
2056
|
-
/**
|
|
2057
|
-
* Settle exchange fees
|
|
2058
|
-
* @return {object} Object with settled fees.
|
|
2059
|
-
*/
|
|
2060
|
-
settleFees() {
|
|
2061
|
-
checkKit(this.exchange_id);
|
|
2062
|
-
const verb = 'GET';
|
|
2063
|
-
|
|
2064
|
-
const path = `${this.baseUrl}/network/${this.exchange_id}/fees/settle`;
|
|
2065
|
-
|
|
2066
|
-
const headers = generateHeaders(
|
|
2067
|
-
this.headers,
|
|
2068
|
-
this.apiSecret,
|
|
2069
|
-
verb,
|
|
2070
|
-
path,
|
|
2071
|
-
this.apiExpiresAfter
|
|
2072
|
-
);
|
|
2073
|
-
|
|
2074
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
2075
|
-
}
|
|
2076
|
-
|
|
2077
|
-
/**
|
|
2078
|
-
* Convert assets to a quote asset
|
|
2079
|
-
* @param {array} assets - Array of assets to convert as strings
|
|
2080
|
-
* @param {object} opts - Optional parameters.
|
|
2081
|
-
* @param {string} opts.quote - Quote asset to convert to. Default: USDT.
|
|
2082
|
-
* @param {number} opts.amount - Amount of quote asset to convert to. Default: 1.
|
|
2083
|
-
* @return {object} Object with converted assets.
|
|
2084
|
-
*/
|
|
2085
|
-
getOraclePrices(assets = [], opts = { quote: null, amount: null }) {
|
|
2086
|
-
checkKit(this.exchange_id);
|
|
2087
|
-
|
|
2088
|
-
if (!assets || !isArray(assets) || assets.length === 0) {
|
|
2089
|
-
return reject(parameterError('assets', 'must be an array with length greater than one'));
|
|
2090
|
-
}
|
|
2091
|
-
|
|
2092
|
-
assets = assets.join(',');
|
|
2093
|
-
|
|
2094
|
-
const verb = 'GET';
|
|
2095
|
-
let path = `${this.baseUrl}/oracle/prices?exchange_id=${
|
|
2096
|
-
this.exchange_id
|
|
2097
|
-
}&assets=${assets}`;
|
|
2098
|
-
|
|
2099
|
-
if (opts.quote) {
|
|
2100
|
-
path += `"e=${opts.quote}`;
|
|
2101
|
-
}
|
|
2102
|
-
|
|
2103
|
-
if (isNumber(opts.amount)) {
|
|
2104
|
-
path += `&amount=${opts.amount}`;
|
|
2105
|
-
}
|
|
2106
|
-
|
|
2107
|
-
const headers = generateHeaders(
|
|
2108
|
-
this.headers,
|
|
2109
|
-
this.apiSecret,
|
|
2110
|
-
verb,
|
|
2111
|
-
path,
|
|
2112
|
-
this.apiExpiresAfter
|
|
2113
|
-
);
|
|
2114
|
-
|
|
2115
|
-
return createRequest(verb, `${this.apiUrl}${path}`, headers);
|
|
2116
|
-
}
|
|
2117
|
-
|
|
2118
|
-
/**
|
|
2119
|
-
* Connect to websocket
|
|
2120
|
-
* @param {array} events - Array of events to connect to
|
|
2121
|
-
*/
|
|
2122
|
-
connect(events = []) {
|
|
2123
|
-
checkKit(this.exchange_id);
|
|
2124
|
-
this.wsReconnect = true;
|
|
2125
|
-
this.wsEvents = events;
|
|
2126
|
-
const apiExpires = moment().unix() + this.apiExpiresAfter;
|
|
2127
|
-
const signature = createSignature(
|
|
2128
|
-
this.apiSecret,
|
|
2129
|
-
'CONNECT',
|
|
2130
|
-
'/stream',
|
|
2131
|
-
apiExpires
|
|
2132
|
-
);
|
|
2133
|
-
|
|
2134
|
-
this.ws = new WebSocket(this.wsUrl, {
|
|
2135
|
-
headers: {
|
|
2136
|
-
'api-key': this.apiKey,
|
|
2137
|
-
'api-signature': signature,
|
|
2138
|
-
'api-expires': apiExpires
|
|
2139
|
-
}
|
|
2140
|
-
});
|
|
2141
|
-
|
|
2142
|
-
if (this.wsEventListeners) {
|
|
2143
|
-
this.ws._events = this.wsEventListeners;
|
|
2144
|
-
} else {
|
|
2145
|
-
this.ws.on('unexpected-response', () => {
|
|
2146
|
-
if (this.ws.readyState !== WebSocket.CLOSING) {
|
|
2147
|
-
if (this.ws.readyState === WebSocket.OPEN) {
|
|
2148
|
-
this.ws.close();
|
|
2149
|
-
} else if (this.wsReconnect) {
|
|
2150
|
-
this.wsEventListeners = this.ws._events;
|
|
2151
|
-
this.ws = null;
|
|
2152
|
-
setTimeout(() => {
|
|
2153
|
-
this.connect(this.wsEvents);
|
|
2154
|
-
}, this.wsReconnectInterval);
|
|
2155
|
-
} else {
|
|
2156
|
-
this.wsEventListeners = null;
|
|
2157
|
-
this.ws = null;
|
|
2158
|
-
}
|
|
2159
|
-
}
|
|
2160
|
-
});
|
|
2161
|
-
|
|
2162
|
-
this.ws.on('error', () => {
|
|
2163
|
-
if (this.ws.readyState !== WebSocket.CLOSING) {
|
|
2164
|
-
if (this.ws.readyState === WebSocket.OPEN) {
|
|
2165
|
-
this.ws.close();
|
|
2166
|
-
} else if (this.wsReconnect) {
|
|
2167
|
-
this.wsEventListeners = this.ws._events;
|
|
2168
|
-
this.ws = null;
|
|
2169
|
-
setTimeout(() => {
|
|
2170
|
-
this.connect(this.wsEvents);
|
|
2171
|
-
}, this.wsReconnectInterval);
|
|
2172
|
-
} else {
|
|
2173
|
-
this.wsEventListeners = null;
|
|
2174
|
-
this.ws = null;
|
|
2175
|
-
}
|
|
2176
|
-
}
|
|
2177
|
-
});
|
|
2178
|
-
|
|
2179
|
-
this.ws.on('close', () => {
|
|
2180
|
-
if (this.wsReconnect) {
|
|
2181
|
-
this.wsEventListeners = this.ws._events;
|
|
2182
|
-
this.ws = null;
|
|
2183
|
-
setTimeout(() => {
|
|
2184
|
-
this.connect(this.wsEvents);
|
|
2185
|
-
}, this.wsReconnectInterval);
|
|
2186
|
-
} else {
|
|
2187
|
-
this.wsEventListeners = null;
|
|
2188
|
-
this.ws = null;
|
|
2189
|
-
}
|
|
2190
|
-
});
|
|
2191
|
-
|
|
2192
|
-
this.ws.on('open', () => {
|
|
2193
|
-
if (this.wsEvents.length > 0) {
|
|
2194
|
-
this.subscribe(this.wsEvents);
|
|
2195
|
-
}
|
|
2196
|
-
|
|
2197
|
-
setWsHeartbeat(this.ws, 'ping', {
|
|
2198
|
-
pingTimeout: 60000,
|
|
2199
|
-
pingInterval: 25000
|
|
2200
|
-
});
|
|
2201
|
-
});
|
|
2202
|
-
}
|
|
2203
|
-
}
|
|
2204
|
-
|
|
2205
|
-
/**
|
|
2206
|
-
* Disconnect from Network websocket
|
|
2207
|
-
*/
|
|
2208
|
-
disconnect() {
|
|
2209
|
-
checkKit(this.exchange_id);
|
|
2210
|
-
if (this.wsConnected()) {
|
|
2211
|
-
this.wsReconnect = false;
|
|
2212
|
-
this.ws.close();
|
|
2213
|
-
} else {
|
|
2214
|
-
throw new Error('Websocket not connected');
|
|
2215
|
-
}
|
|
2216
|
-
}
|
|
2217
|
-
|
|
2218
|
-
/**
|
|
2219
|
-
* Subscribe to Network websocket events
|
|
2220
|
-
* @param {array} events - The events to listen to
|
|
2221
|
-
*/
|
|
2222
|
-
subscribe(events = []) {
|
|
2223
|
-
checkKit(this.exchange_id);
|
|
2224
|
-
if (this.wsConnected()) {
|
|
2225
|
-
this.ws.send(
|
|
2226
|
-
JSON.stringify({
|
|
2227
|
-
op: 'subscribe',
|
|
2228
|
-
args: events
|
|
2229
|
-
})
|
|
2230
|
-
);
|
|
2231
|
-
} else {
|
|
2232
|
-
throw new Error('Websocket not connected');
|
|
2233
|
-
}
|
|
2234
|
-
}
|
|
2235
|
-
|
|
2236
|
-
/**
|
|
2237
|
-
* Unsubscribe to Network websocket events
|
|
2238
|
-
* @param {array} events - The events to unsub from
|
|
2239
|
-
*/
|
|
2240
|
-
unsubscribe(events = []) {
|
|
2241
|
-
checkKit(this.exchange_id);
|
|
2242
|
-
if (this.wsConnected()) {
|
|
2243
|
-
this.ws.send(
|
|
2244
|
-
JSON.stringify({
|
|
2245
|
-
op: 'unsubscribe',
|
|
2246
|
-
args: events
|
|
2247
|
-
})
|
|
2248
|
-
);
|
|
2249
|
-
} else {
|
|
2250
|
-
throw new Error('Websocket not connected');
|
|
2251
|
-
}
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
|
-
|
|
2255
|
-
module.exports = HollaExNetwork;
|