@icgio/icg-exchanges-wrapper 1.9.62 → 1.9.64

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.
Files changed (2) hide show
  1. package/middleware/orders.js +401 -255
  2. package/package.json +3 -3
@@ -15,25 +15,25 @@ const STANDARD_LIMITS = {
15
15
  public_max_concurrent: 10,
16
16
  public_interval_concurrent: 1000,
17
17
  private_max_concurrent: 5,
18
- private_interval_concurrent: 1000
18
+ private_interval_concurrent: 1000,
19
19
  }
20
20
  const MEDIUM_LIMITS = {
21
21
  public_max_concurrent: 7,
22
22
  public_interval_concurrent: 1000,
23
23
  private_max_concurrent: 4,
24
- private_interval_concurrent: 1000
24
+ private_interval_concurrent: 1000,
25
25
  }
26
26
  const SMALL_LIMITS = {
27
27
  public_max_concurrent: 5,
28
28
  public_interval_concurrent: 1000,
29
29
  private_max_concurrent: 3,
30
- private_interval_concurrent: 1000
30
+ private_interval_concurrent: 1000,
31
31
  }
32
32
  const MINIMUM_LIMITS = {
33
33
  public_max_concurrent: 2,
34
34
  public_interval_concurrent: 1000,
35
35
  private_max_concurrent: 1,
36
- private_interval_concurrent: 3000
36
+ private_interval_concurrent: 3000,
37
37
  }
38
38
 
39
39
  const RATES_LENGTH_MAX = 100
@@ -42,11 +42,11 @@ const MARKET_HISTORY_DEFAULT_TIME = 10 * 60 * 1000
42
42
  const TRADES_DEFAULT_TIME = 12 * 60 * 60 * 1000
43
43
 
44
44
  module.exports = class Orders {
45
- constructor (exchange_basecur_curs, cd, settings) {
45
+ constructor(exchange_basecur_curs, cd, settings) {
46
46
  this.exchange_basecur_curs = exchange_basecur_curs
47
47
  let { exchange_pairs, exchange_curs, pair_exchanges } = utils.exchange_basecur_curs_converter(exchange_basecur_curs)
48
48
  this.exchange_pairs = exchange_pairs
49
- this.pair_exchanges = pair_exchanges
49
+ this.pair_exchanges = pair_exchanges
50
50
  this.Exchanges = {}
51
51
  this.settings = settings || {}
52
52
  this.ws_enabled = settings.ws_enabled || false
@@ -63,7 +63,7 @@ module.exports = class Orders {
63
63
  this.no_cancel_range_exchanges = settings.no_cancel_range_exchanges || []
64
64
  this.no_trades_function_exchanges = settings.no_trades_function_exchanges || []
65
65
  this.no_trades_function_f_filled_timeout = settings.no_trades_function_f_filled_timeout || 30 * 1000
66
- this.bad_trades_function_exchanges = settings.bad_trades_function_exchanges || []
66
+ this.bad_trades_no_arb_function_exchanges = settings.bad_trades_no_arb_function_exchanges || []
67
67
  this.buy_sell_limits_threshold = settings.buy_sell_limits_threshold || 0.95
68
68
  this.p_filled_threshold = settings.p_filled_threshold || 0
69
69
  this.f_filled_threshold = settings.f_filled_threshold || 0.99
@@ -92,12 +92,12 @@ module.exports = class Orders {
92
92
  }
93
93
  if (!this.interval_dict || !this.interval_dict[exchange]) {
94
94
  this.interval_dict[exchange] = {
95
- 'balances': 10 * 1000,
96
- 'positions': 10 * 1000,
97
- 'open_orders': 10 * 1000,
98
- 'trades': 10 * 1000,
99
- 'rates': 1 * 1000,
100
- 'market_history': 2 * 1000,
95
+ balances: 10 * 1000,
96
+ positions: 10 * 1000,
97
+ open_orders: 10 * 1000,
98
+ trades: 10 * 1000,
99
+ rates: 1 * 1000,
100
+ market_history: 2 * 1000,
101
101
  }
102
102
  } else {
103
103
  this.interval_dict[exchange].balances = this.interval_dict[exchange].balances || 10 * 1000
@@ -108,30 +108,28 @@ module.exports = class Orders {
108
108
  this.interval_dict[exchange].market_history = this.interval_dict[exchange].market_history || 2 * 1000
109
109
  }
110
110
  }
111
- this.balances = {}, this.open_orders = {}, this.trades = {}, this.rates = {}, this.market_history = {}, this.volumes = {}, this.cmc_rates = {}
112
- this.rates_combined_all = {}, this.rates_combined_all_with_buy_sell_limits = {}, this.rates_combined_major = {}, this.rates_combined_good_with_buy_sell_limits = {}
111
+ ;(this.balances = {}), (this.open_orders = {}), (this.trades = {}), (this.rates = {}), (this.market_history = {}), (this.volumes = {}), (this.cmc_rates = {})
112
+ ;(this.rates_combined_all = {}), (this.rates_combined_all_with_buy_sell_limits = {}), (this.rates_combined_major = {}), (this.rates_combined_good_with_buy_sell_limits = {})
113
113
  this.buy_sell_limits = {}
114
114
  this.order_info = {}
115
115
  this.order_info_status = {}
116
116
  this.enabled = settings.enabled || {
117
- 'info_log': true,
118
- 'error_log': true,
119
- 'balances_check': true,
120
- 'positions_check': false,
121
- 'open_orders_check': true,
122
- 'trades_check': true,
123
- 'rates_check': true,
124
- 'market_history_check': true,
125
- 'volumes_check': false,
126
- 'cmc_rates_check': true
117
+ info_log: true,
118
+ error_log: true,
119
+ balances_check: true,
120
+ positions_check: false,
121
+ open_orders_check: true,
122
+ trades_check: true,
123
+ rates_check: true,
124
+ market_history_check: true,
125
+ volumes_check: false,
126
+ cmc_rates_check: true,
127
127
  }
128
128
  this.info_log = (...args) => {
129
- if (this.enabled.info_log)
130
- console.log(...args)
129
+ if (this.enabled.info_log) console.log(...args)
131
130
  }
132
131
  this.error_log = (...args) => {
133
- if (this.enabled.info_log)
134
- console.error(...args)
132
+ if (this.enabled.info_log) console.error(...args)
135
133
  }
136
134
  if (this.enabled.balances_check) {
137
135
  this.check_balances()
@@ -165,36 +163,50 @@ module.exports = class Orders {
165
163
  }
166
164
  this.ws_market_first_time = {}
167
165
  }
168
- init_account (initial_balances) {
166
+ init_account(initial_balances) {
169
167
  this.account = new Account(initial_balances)
170
168
  }
171
- set_exchange_assets_from_balances (balances) {
169
+ set_exchange_assets_from_balances(balances) {
172
170
  this.account.set_exchange_assets_from_balances(balances)
173
171
  }
174
- limit_trade (exchange, pair, method, price, amount, id=uuid(), order_type='', limiter_on=true) {
172
+ limit_trade(exchange, pair, method, price, amount, id = uuid(), order_type = '', limiter_on = true) {
175
173
  price = round_price(_.upperFirst(exchange), pair, price)
176
174
  amount = round_amount(_.upperFirst(exchange), pair, amount)
177
175
  this.info_log('%s %s %s %s %s %s at %s', limiter_on, order_type, exchange, pair, method, amount, price)
178
- this.update_order_info(exchange, pair, method, id, {
179
- order_type,
180
- status: 'INIT',
181
- id,
182
- order_id: id,
183
- type: method,
184
- price,
185
- amount,
186
- f_amount: 0,
187
- f_percentage: 0,
188
- t_amount: amount,
189
- open_time: new Date(),
190
- close_time: null
191
- }, order_type + ' init')
176
+ this.update_order_info(
177
+ exchange,
178
+ pair,
179
+ method,
180
+ id,
181
+ {
182
+ order_type,
183
+ status: 'INIT',
184
+ id,
185
+ order_id: id,
186
+ type: method,
187
+ price,
188
+ amount,
189
+ f_amount: 0,
190
+ f_percentage: 0,
191
+ t_amount: amount,
192
+ open_time: new Date(),
193
+ close_time: null,
194
+ },
195
+ order_type + ' init'
196
+ )
192
197
  let no_callback_timeout = setTimeout(() => {
193
198
  if (_.get(this.order_info, [exchange, pair, method, id, 'status']) === 'INIT') {
194
199
  console.log('no callback: %s %s %s %s %s', exchange, pair, method, id, order_type)
195
- this.update_order_info(exchange, pair, method, id, {
196
- status: 'N-OPENED-TIMEOUT'
197
- }, order_type + ' n-opened-timeout-init')
200
+ this.update_order_info(
201
+ exchange,
202
+ pair,
203
+ method,
204
+ id,
205
+ {
206
+ status: 'N-OPENED-TIMEOUT',
207
+ },
208
+ order_type + ' n-opened-timeout-init'
209
+ )
198
210
  }
199
211
  }, 60 * 1000)
200
212
  let limit_trade = (cb) => {
@@ -208,26 +220,33 @@ module.exports = class Orders {
208
220
  if (res.success) {
209
221
  let order_id = res.body
210
222
  this.delete_order_info(exchange, pair, method, id, 'limit-trade-success')
211
- this.update_order_info(exchange, pair, method, order_id, {
212
- order_type,
213
- status: 'N-FILLED',
214
- id,
223
+ this.update_order_info(
224
+ exchange,
225
+ pair,
226
+ method,
215
227
  order_id,
216
- type: method,
217
- price,
218
- amount,
219
- f_amount: 0,
220
- f_percentage: 0,
221
- t_amount: amount,
222
- open_time: new Date(),
223
- close_time: null
224
- }, order_type + ' n-filled')
228
+ {
229
+ order_type,
230
+ status: 'N-FILLED',
231
+ id,
232
+ order_id,
233
+ type: method,
234
+ price,
235
+ amount,
236
+ f_amount: 0,
237
+ f_percentage: 0,
238
+ t_amount: amount,
239
+ open_time: new Date(),
240
+ close_time: null,
241
+ },
242
+ order_type + ' n-filled'
243
+ )
225
244
  } else if (res.error === 'amount-too-small' || res.error === 'insufficient-funds') {
226
245
  this.delete_order_info(exchange, pair, method, id, 'limit-trade-' + res.error)
227
246
  } else {
228
247
  if (order_type.startsWith('self') || order_type.startsWith('maker_2')) {
229
248
  this.delete_order_info(exchange, pair, method, id, 'limit-trade-timeout-' + order_type)
230
- }
249
+ }
231
250
  // else if (_.get(this.order_info, [exchange, pair, method, id, 'status']) === 'INIT') { // make sure no_callback_timeout is NOT running zero
232
251
  // this.update_order_info(exchange, pair, method, id, {
233
252
  // status: 'N-OPENED-TIMEOUT'
@@ -238,7 +257,7 @@ module.exports = class Orders {
238
257
  clearTimeout(no_callback_timeout)
239
258
  })
240
259
  }
241
- limit_trade_all (pair, method, price, total) {
260
+ limit_trade_all(pair, method, price, total) {
242
261
  if (!this.volumes[pair]) {
243
262
  this.error_log('%s volumes do not exist')
244
263
  return
@@ -246,20 +265,20 @@ module.exports = class Orders {
246
265
  let id = uuid()
247
266
  let sum = _.sum(_.values(this.volumes[pair]))
248
267
  for (let exchange of this.pair_exchanges[pair]) {
249
- let amount = this.volumes[pair][exchange] / sum * total
268
+ let amount = (this.volumes[pair][exchange] / sum) * total
250
269
  this.limit_trade(exchange, pair, method, price, amount, id)
251
270
  }
252
271
  }
253
- market_trade (exchange, pair, method, amount, id=uuid()) {
272
+ market_trade(exchange, pair, method, amount, id = uuid()) {
254
273
  if (!this.rates[exchange][pair]) {
255
274
  this.info_log('%s %s rates do not exist', exchange, pair)
256
275
  return
257
276
  }
258
- let input_array = (method === 'sell') ? this.rates[exchange][pair].bids : this.rates[exchange][pair].asks
277
+ let input_array = method === 'sell' ? this.rates[exchange][pair].bids : this.rates[exchange][pair].asks
259
278
  let { price } = utils.vol_position(input_array, amount)
260
279
  this.limit_trade(exchange, pair, method, price, amount, id)
261
280
  }
262
- market_trade_all (pair, method, total) {
281
+ market_trade_all(pair, method, total) {
263
282
  if (!this.rates_combined_all[pair]) {
264
283
  this.error_log('%s rates combined do not exist', pair)
265
284
  return
@@ -268,34 +287,54 @@ module.exports = class Orders {
268
287
  let { price_exchange, vol_exchange } = utils.vol_position_combined(this.rates_combined_all[pair][type], total)
269
288
  let id = uuid()
270
289
  for (let exchange of this.pair_exchanges[pair]) {
271
- if (price_exchange[exchange] && vol_exchange[exchange])
272
- this.limit_trade(exchange, pair, method, price_exchange[exchange], vol_exchange[exchange], id)
290
+ if (price_exchange[exchange] && vol_exchange[exchange]) this.limit_trade(exchange, pair, method, price_exchange[exchange], vol_exchange[exchange], id)
273
291
  }
274
292
  }
275
- cancel_order (exchange, pair, order) {
293
+ cancel_order(exchange, pair, order) {
276
294
  let original_status = order.status
277
- this.update_order_info(exchange, pair, order.type, order.order_id, {
278
- status: 'CANCELING'
279
- }, order.order_type + ' canceling')
280
- order.exchange = exchange, order.pair = pair
295
+ this.update_order_info(
296
+ exchange,
297
+ pair,
298
+ order.type,
299
+ order.order_id,
300
+ {
301
+ status: 'CANCELING',
302
+ },
303
+ order.order_type + ' canceling'
304
+ )
305
+ ;(order.exchange = exchange), (order.pair = pair)
281
306
  this.Exchanges[exchange].cancel_order_by_order(order, (res) => {
282
307
  if (res.success || (!res.success && res.error === 'order-not-open' && original_status === 'CANCELING')) {
283
- this.update_order_info(exchange, pair, order.type, order.order_id, {
284
- status: 'CANCELED',
285
- close_time: new Date()
286
- }, order.order_type + ' canceled')
308
+ this.update_order_info(
309
+ exchange,
310
+ pair,
311
+ order.type,
312
+ order.order_id,
313
+ {
314
+ status: 'CANCELED',
315
+ close_time: new Date(),
316
+ },
317
+ order.order_type + ' canceled'
318
+ )
287
319
  setTimeout(() => {
288
320
  this.delete_order_info(exchange, pair, order.type, order.order_id, 'cancel-order-success')
289
321
  }, this.delete_finished_orders_timeout)
290
322
  } else if (!res.success && res.error === 'order-not-open' && original_status !== 'CANCELED') {
291
323
  // this.info_log('%s ORDER CANNOT BE CANCELED: %j', original_status, order)
292
- this.update_order_info(exchange, pair, order.type, order.order_id, {
293
- status: 'F-FILLED',
294
- amount: 0,
295
- f_amount: order.amount,
296
- f_percentage: 1,
297
- close_time: new Date()
298
- }, order.order_type + ' cannot-be-canceled')
324
+ this.update_order_info(
325
+ exchange,
326
+ pair,
327
+ order.type,
328
+ order.order_id,
329
+ {
330
+ status: 'F-FILLED',
331
+ amount: 0,
332
+ f_amount: order.amount,
333
+ f_percentage: 1,
334
+ close_time: new Date(),
335
+ },
336
+ order.order_type + ' cannot-be-canceled'
337
+ )
299
338
  setTimeout(() => {
300
339
  this.delete_order_info(exchange, pair, order.type, order.order_id, 'cannot-be-canceled')
301
340
  }, this.delete_finished_orders_timeout)
@@ -304,11 +343,12 @@ module.exports = class Orders {
304
343
  }
305
344
  })
306
345
  }
307
- get_order_info_all () {
346
+ get_order_info_all() {
308
347
  return this.order_info
309
348
  }
310
- get_order_info_all_stats () {
311
- let info_all = this.get_order_info_all(), info_all_stats = {}
349
+ get_order_info_all_stats() {
350
+ let info_all = this.get_order_info_all(),
351
+ info_all_stats = {}
312
352
  for (let exchange in info_all) {
313
353
  for (let pair in info_all[exchange]) {
314
354
  for (let type in info_all[exchange][pair]) {
@@ -318,7 +358,7 @@ module.exports = class Orders {
318
358
  }
319
359
  return info_all_stats
320
360
  }
321
- get_order_info_by_order_type (order_type) {
361
+ get_order_info_by_order_type(order_type) {
322
362
  let order_info_temp = {}
323
363
  for (let exchange in this.order_info) {
324
364
  for (let pair in this.order_info[exchange]) {
@@ -333,73 +373,109 @@ module.exports = class Orders {
333
373
  }
334
374
  return order_info_temp
335
375
  }
336
- get_order_info_status_all (exchange, pair, type, status) {
376
+ get_order_info_status_all(exchange, pair, type, status) {
337
377
  if (type === 'both') {
338
378
  return this.get_order_info_status_all(exchange, pair, 'sell', status).concat(this.get_order_info_status_all(exchange, pair, 'buy', status))
339
379
  }
340
380
  _.set(this.order_info_status, [exchange, pair, type, status], [])
341
381
  for (let order_id in _.get(this.order_info, [exchange, pair, type], {})) {
342
382
  let order_status = _.get(this.order_info, [exchange, pair, type, order_id, 'status'])
343
- if (order_status === status || status.indexOf(order_status) > -1) {
383
+ if (order_status === status || _.includes(status, order_status)) {
344
384
  this.order_info_status[exchange][pair][type][status].push(this.order_info[exchange][pair][type][order_id])
345
385
  }
346
386
  }
347
387
  return this.order_info_status[exchange][pair][type][status]
348
388
  }
349
- get_order_info_status_by_order_type (exchange, pair, type, status, order_type) {
350
- return this.get_order_info_status_all(exchange, pair, type, status).filter(o => o.order_type === order_type)
389
+ get_order_info_status_by_order_type(exchange, pair, type, status, order_type) {
390
+ return this.get_order_info_status_all(exchange, pair, type, status).filter((o) => o.order_type === order_type)
351
391
  }
352
- process_bot (balances, open_orders, trades) {
392
+ process_bot(balances, open_orders, trades) {
353
393
  for (let exchange in trades) {
354
394
  for (let pair in trades[exchange]) {
355
- trades[exchange][pair].trades.map(trade => {
395
+ trades[exchange][pair].trades.map((trade) => {
356
396
  if (_.get(this.order_info, [exchange, pair, trade.type, trade.order_id])) {
357
397
  let order_info = this.order_info[exchange][pair][trade.type][trade.order_id]
358
398
  if (order_info.status === 'CANCELED' || order_info.status === 'CANCELING') {
359
- let type = trade.type, order_id = trade.order_id
399
+ let type = trade.type,
400
+ order_id = trade.order_id
360
401
  // this.info_log('TRADES: %s ORDER FILLED', order_info.status, trade, order_info)
361
- this.update_order_info(exchange, pair, type, order_id, {
362
- status: 'F-FILLED',
363
- price: trade.price,
364
- amount: 0,
365
- f_amount: trade.amount,
366
- t_amount: trade.amount,
367
- f_percentage: 1,
368
- close_time: trade.close_time || new Date()
369
- }, order_info.order_type + ' canceled-order-filled')
402
+ this.update_order_info(
403
+ exchange,
404
+ pair,
405
+ type,
406
+ order_id,
407
+ {
408
+ status: 'F-FILLED',
409
+ price: trade.price,
410
+ amount: 0,
411
+ f_amount: trade.amount,
412
+ t_amount: trade.amount,
413
+ f_percentage: 1,
414
+ close_time: trade.close_time || new Date(),
415
+ },
416
+ order_info.order_type + ' canceled-order-filled'
417
+ )
370
418
  setTimeout(() => {
371
419
  this.delete_order_info(exchange, pair, type, order_id, 'canceled-order-filled')
372
420
  }, this.delete_finished_orders_timeout)
373
421
  } else if (order_info.status === 'F-FILLED' && trade.amount > order_info.f_amount) {
374
422
  // this.info_log('TRADES: FILLED ORDER FILLED MORE', trade, order_info)
375
- this.update_order_info(exchange, pair, order_info.type, order_info.order_id, {
376
- f_amount: trade.amount,
377
- t_amount: trade.amount,
378
- f_percentage: 1
379
- }, order_info.order_type + ' filled-order-filled-more')
380
- } else if (_.includes(['N-FILLED', 'P-FILLED'], order_info.status) && trade.amount > order_info.f_amount && trade.amount / order_info.t_amount > this.f_filled_threshold) {
423
+ this.update_order_info(
424
+ exchange,
425
+ pair,
426
+ order_info.type,
427
+ order_info.order_id,
428
+ {
429
+ f_amount: trade.amount,
430
+ t_amount: trade.amount,
431
+ f_percentage: 1,
432
+ },
433
+ order_info.order_type + ' filled-order-filled-more'
434
+ )
435
+ } else if (
436
+ _.includes(['N-FILLED', 'P-FILLED'], order_info.status) &&
437
+ trade.amount > order_info.f_amount &&
438
+ trade.amount / order_info.t_amount > this.f_filled_threshold
439
+ ) {
381
440
  // this.info_log('TRADES: %s %s ORDER F-FILLED', exchange, pair, trade)
382
- this.update_order_info(exchange, pair, order_info.type, order_info.order_id, {
383
- status: 'F-FILLED',
384
- price: trade.price,
385
- amount: order_info.t_amount - trade.amount,
386
- f_amount: trade.amount,
387
- f_percentage: trade.amount / order_info.t_amount,
388
- close_time: trade.close_time || new Date()
389
- }, order_info.order_type + ' order-f-filled-1')
441
+ this.update_order_info(
442
+ exchange,
443
+ pair,
444
+ order_info.type,
445
+ order_info.order_id,
446
+ {
447
+ status: 'F-FILLED',
448
+ price: trade.price,
449
+ amount: order_info.t_amount - trade.amount,
450
+ f_amount: trade.amount,
451
+ f_percentage: trade.amount / order_info.t_amount,
452
+ close_time: trade.close_time || new Date(),
453
+ },
454
+ order_info.order_type + ' order-f-filled-1'
455
+ )
390
456
  setTimeout(() => {
391
457
  this.delete_order_info(exchange, pair, order_info.type, order_info.order_id, 'f-filled-trades')
392
458
  }, this.delete_finished_orders_timeout)
393
- } else if (_.includes(['N-FILLED', 'P-FILLED'], order_info.status) && trade.amount > order_info.f_amount && trade.amount / order_info.t_amount > this.p_filled_threshold) {
459
+ } else if (
460
+ _.includes(['N-FILLED', 'P-FILLED'], order_info.status) &&
461
+ trade.amount > order_info.f_amount &&
462
+ trade.amount / order_info.t_amount > this.p_filled_threshold
463
+ ) {
394
464
  // this.info_log('TRADES: %s %s ORDER P-FILLED', exchange, pair, trade)
395
- this.update_order_info(exchange, pair, order_info.type, order_info.order_id, {
396
- status: 'P-FILLED',
397
- amount: order_info.t_amount - trade.amount,
398
- f_amount: trade.amount,
399
- f_percentage: trade.amount / order_info.t_amount
400
- }, order_info.order_type + ' order-p-filled-1')
465
+ this.update_order_info(
466
+ exchange,
467
+ pair,
468
+ order_info.type,
469
+ order_info.order_id,
470
+ {
471
+ status: 'P-FILLED',
472
+ amount: order_info.t_amount - trade.amount,
473
+ f_amount: trade.amount,
474
+ f_percentage: trade.amount / order_info.t_amount,
475
+ },
476
+ order_info.order_type + ' order-p-filled-1'
477
+ )
401
478
  } else if (_.includes(['F-FILLED', 'P-FILLED'], order_info.status)) {
402
-
403
479
  } else {
404
480
  this.info_log('TRADES: UNKNOWN %j', trade, this.order_info[exchange][pair])
405
481
  }
@@ -412,22 +488,32 @@ module.exports = class Orders {
412
488
  for (let type in _.get(this.order_info, [exchange, pair], {})) {
413
489
  for (let order_id in _.get(this.order_info, [exchange, pair, type], {})) {
414
490
  let order_info_order = this.order_info[exchange][pair][type][order_id]
415
- if ((order_info_order.status === 'N-FILLED' || order_info_order.status === 'P-FILLED') && order_info_order.open_time < new Date().getTime() - this.no_trades_function_f_filled_timeout) {
491
+ if (
492
+ (order_info_order.status === 'N-FILLED' || order_info_order.status === 'P-FILLED') &&
493
+ order_info_order.open_time < new Date().getTime() - this.no_trades_function_f_filled_timeout
494
+ ) {
416
495
  let exist = false
417
- open_orders[exchange][pair].open_orders.map(o => {
496
+ open_orders[exchange][pair].open_orders.map((o) => {
418
497
  if (o.order_id === order_info_order.order_id) {
419
498
  exist = true
420
499
  }
421
500
  })
422
501
  if (!exist) {
423
502
  // this.info_log('ORDERS: %s %s ORDER F-FILLED NO TRADES FUNCTION EXCHANGES', exchange, pair)
424
- this.update_order_info(exchange, pair, order_info_order.type, order_info_order.order_id, {
425
- status: 'F-FILLED',
426
- amount: 0,
427
- f_amount: order_info_order.t_amount,
428
- f_percentage: 1,
429
- close_time: new Date()
430
- }, order_info_order.order_type + ' order-f-filled-2')
503
+ this.update_order_info(
504
+ exchange,
505
+ pair,
506
+ order_info_order.type,
507
+ order_info_order.order_id,
508
+ {
509
+ status: 'F-FILLED',
510
+ amount: 0,
511
+ f_amount: order_info_order.t_amount,
512
+ f_percentage: 1,
513
+ close_time: new Date(),
514
+ },
515
+ order_info_order.order_type + ' order-f-filled-2'
516
+ )
431
517
  setTimeout(() => {
432
518
  this.delete_order_info(exchange, pair, order_info_order.type, order_info_order.order_id, 'f-filled-no-trades-function')
433
519
  }, this.delete_finished_orders_timeout)
@@ -439,50 +525,80 @@ module.exports = class Orders {
439
525
  }
440
526
  for (let exchange in open_orders) {
441
527
  for (let pair in open_orders[exchange]) {
442
- open_orders[exchange][pair].open_orders.map(order => {
528
+ open_orders[exchange][pair].open_orders.map((order) => {
443
529
  if (_.get(this.order_info, [exchange, pair, order.type, order.order_id])) {
444
530
  let order_info = this.order_info[exchange][pair][order.type][order.order_id]
445
531
  if (_.includes(['N-FILLED', 'P-FILLED'], order_info.status) && order.f_amount > order_info.f_amount && order.f_amount / order_info.t_amount > this.f_filled_threshold) {
446
532
  // this.info_log('ORDERS: %s %s ORDER F-FILLED', exchange, pair)
447
- this.update_order_info(exchange, pair, order_info.type, order_info.order_id, {
448
- status: 'F-FILLED',
449
- amount: order.amount,
450
- f_amount: order.f_amount,
451
- f_percentage: order.f_amount / order_info.t_amount,
452
- close_time: order.close_time || new Date()
453
- }, order_info.order_type + ' order-f-filled-3')
533
+ this.update_order_info(
534
+ exchange,
535
+ pair,
536
+ order_info.type,
537
+ order_info.order_id,
538
+ {
539
+ status: 'F-FILLED',
540
+ amount: order.amount,
541
+ f_amount: order.f_amount,
542
+ f_percentage: order.f_amount / order_info.t_amount,
543
+ close_time: order.close_time || new Date(),
544
+ },
545
+ order_info.order_type + ' order-f-filled-3'
546
+ )
454
547
  setTimeout(() => {
455
548
  this.delete_order_info(exchange, pair, order_info.type, order_info.order_id, 'f-filled-open-orders')
456
549
  }, this.delete_finished_orders_timeout)
457
- } else if (_.includes(['N-FILLED', 'P-FILLED'], order_info.status) && order.f_amount > order_info.f_amount && order.f_amount / order_info.t_amount > this.p_filled_threshold) {
550
+ } else if (
551
+ _.includes(['N-FILLED', 'P-FILLED'], order_info.status) &&
552
+ order.f_amount > order_info.f_amount &&
553
+ order.f_amount / order_info.t_amount > this.p_filled_threshold
554
+ ) {
458
555
  // this.info_log('ORDERS: %s %s ORDER P-FILLED', exchange, pair)
459
- this.update_order_info(exchange, pair, order_info.type, order_info.order_id, {
460
- status: 'P-FILLED',
461
- amount: order.amount,
462
- f_amount: order.f_amount,
463
- f_percentage: order.f_amount / order_info.t_amount
464
- }, order_info.order_type + ' order-p-filled-2')
556
+ this.update_order_info(
557
+ exchange,
558
+ pair,
559
+ order_info.type,
560
+ order_info.order_id,
561
+ {
562
+ status: 'P-FILLED',
563
+ amount: order.amount,
564
+ f_amount: order.f_amount,
565
+ f_percentage: order.f_amount / order_info.t_amount,
566
+ },
567
+ order_info.order_type + ' order-p-filled-2'
568
+ )
465
569
  }
466
570
  } else if (this.get_order_info_status_all(exchange, pair, 'both', 'INIT') && this.check_init_order_opened) {
467
- this.get_order_info_status_all(exchange, pair, 'both', 'INIT').map(init_order => {
571
+ this.get_order_info_status_all(exchange, pair, 'both', 'INIT').map((init_order) => {
468
572
  let init_order_price = round_price(exchange, pair, init_order.price)
469
573
  let order_price = round_price(exchange, pair, order.price)
470
574
  let init_order_time = init_order.open_time.getTime()
471
575
  let order_time = order.open_time.getTime()
472
- if (init_order.type === order.type && init_order_price === order_price && order_time - init_order_time > 0 && order_time - init_order_time < this.check_init_order_opened_timeout) {
576
+ if (
577
+ init_order.type === order.type &&
578
+ init_order_price === order_price &&
579
+ order_time - init_order_time > 0 &&
580
+ order_time - init_order_time < this.check_init_order_opened_timeout
581
+ ) {
473
582
  // this.info_log('ORDERS: %s %s %s %s INIT ORDER OPENED', init_order.order_id, order.order_id, exchange, pair)
474
583
  this.delete_order_info(exchange, pair, init_order.type, init_order.order_id, 'init-order-opened')
475
- this.update_order_info(exchange, pair, order.type, order.order_id, {
476
- status: 'N-FILLED',
477
- order_id: order.order_id,
478
- type: order.type,
479
- price: order.price,
480
- amount: order.amount,
481
- f_amount: 0,
482
- t_amount: order.amount,
483
- open_time: order.open_time || new Date(),
484
- close_time: null
485
- }, init_order.order_type + ' init-order-opened')
584
+ this.update_order_info(
585
+ exchange,
586
+ pair,
587
+ order.type,
588
+ order.order_id,
589
+ {
590
+ status: 'N-FILLED',
591
+ order_id: order.order_id,
592
+ type: order.type,
593
+ price: order.price,
594
+ amount: order.amount,
595
+ f_amount: 0,
596
+ t_amount: order.amount,
597
+ open_time: order.open_time || new Date(),
598
+ close_time: null,
599
+ },
600
+ init_order.order_type + ' init-order-opened'
601
+ )
486
602
  }
487
603
  })
488
604
  }
@@ -490,7 +606,7 @@ module.exports = class Orders {
490
606
  }
491
607
  }
492
608
  }
493
- update_order_info (exchange, pair, type, order_id, dict, note) {
609
+ update_order_info(exchange, pair, type, order_id, dict, note) {
494
610
  if (!order_id) {
495
611
  this.error_log('UPDATE %s: order_id invalid %s %s %s %s %j', note, exchange, pair, type, order_id, dict)
496
612
  return
@@ -503,23 +619,23 @@ module.exports = class Orders {
503
619
  }
504
620
  this.info_log('UPDATE %s: %s %s %s %s %j', note, exchange, pair, type, order_id, dict)
505
621
  }
506
- delete_order_info (exchange, pair, type, order_id, note) {
622
+ delete_order_info(exchange, pair, type, order_id, note) {
507
623
  this.order_info[exchange][pair][type] = _.omit(this.order_info[exchange][pair][type], [order_id])
508
624
  this.info_log('DELETE %s: %s %s %s %s', note, exchange, pair, type, order_id)
509
625
  }
510
- check_balances () {
626
+ check_balances() {
511
627
  let balances_handler = (exchange, res) => {
512
628
  if (res.success) {
513
629
  _.set(this.balances, [exchange], Object.assign(res.body, { update_time: new Date() }))
514
630
  for (let exchange in this.exchange_basecur_curs) {
515
631
  for (let base_cur in this.exchange_basecur_curs[exchange]) {
516
- this.exchange_basecur_curs[exchange][base_cur].map(cur => {
632
+ this.exchange_basecur_curs[exchange][base_cur].map((cur) => {
517
633
  let cur_balance = _.get(this.balances, [exchange, 'available', cur], 0)
518
634
  let base_cur_balance = _.get(this.balances, [exchange, 'available', base_cur], 0)
519
635
  let pair = cur + base_cur
520
636
  _.set(this.buy_sell_limits, [exchange, pair], {
521
637
  sell: cur_balance * this.buy_sell_limits_threshold,
522
- buy: base_cur_balance * this.buy_sell_limits_threshold
638
+ buy: base_cur_balance * this.buy_sell_limits_threshold,
523
639
  })
524
640
  })
525
641
  }
@@ -534,35 +650,36 @@ module.exports = class Orders {
534
650
  this.buy_sell_limits = _.omit(this.buy_sell_limits, [exchange])
535
651
  }
536
652
  }
537
- function get_balances (Exchanges, interval_dict) {
653
+ function get_balances(Exchanges, interval_dict) {
538
654
  for (let exchange in Exchanges) {
539
655
  if (Exchanges[exchange].balance_ws) {
540
656
  setInterval(() => {
541
- if (Exchanges[exchange].ws_status().trading === 'n-opened')
542
- Exchanges[exchange].ws_account()
543
- Exchanges[exchange].balance_ws((res) => { balances_handler (exchange, res) })
657
+ if (Exchanges[exchange].ws_status().trading === 'n-opened') Exchanges[exchange].ws_account()
658
+ Exchanges[exchange].balance_ws((res) => {
659
+ balances_handler(exchange, res)
660
+ })
544
661
  }, interval_dict[exchange].balances)
545
662
  } else {
546
663
  setInterval(() => {
547
- Exchanges[exchange].balance((res) => { balances_handler (exchange, res) })
664
+ Exchanges[exchange].balance((res) => {
665
+ balances_handler(exchange, res)
666
+ })
548
667
  }, interval_dict[exchange].balances)
549
668
  }
550
669
  }
551
670
  }
552
671
  get_balances(this.Exchanges, this.interval_dict)
553
672
  }
554
- check_positions () {
555
- let position_handler = (exchange, pair, res) => {
556
-
557
- }
673
+ check_positions() {
674
+ let position_handler = (exchange, pair, res) => {}
558
675
  let position_all_handler = (exchange, res) => {
559
676
  if (res.success) {
560
677
  _.set(this.positions, [exchange], Object.assign(res.body, { update_time: new Date() }))
561
678
  for (let exchange in this.exchange_pairs) {
562
- this.exchange_pairs[exchange].map(pair => {
679
+ this.exchange_pairs[exchange].map((pair) => {
563
680
  _.set(this.buy_sell_limits, [exchange, pair], {
564
681
  sell: 1000 + _.get(res.body, ['total', pair], 0),
565
- buy: 1000 - _.get(res.body, ['total', pair], 0)
682
+ buy: 1000 - _.get(res.body, ['total', pair], 0),
566
683
  })
567
684
  })
568
685
  }
@@ -572,30 +689,36 @@ module.exports = class Orders {
572
689
  this.buy_sell_limits = _.omit(this.buy_sell_limits, [exchange])
573
690
  }
574
691
  }
575
- function get_positions (Exchanges, interval_dict) {
692
+ function get_positions(Exchanges, interval_dict) {
576
693
  for (let exchange in Exchanges) {
577
694
  if (Exchanges[exchange].position_all_ws) {
578
- if (Exchanges[exchange].ws_status().trading === 'n-opened')
579
- Exchanges[exchange].ws_account()
695
+ if (Exchanges[exchange].ws_status().trading === 'n-opened') Exchanges[exchange].ws_account()
580
696
  setInterval(() => {
581
- Exchanges[exchange].position_all_ws((res) => { position_all_handler (exchange, res) })
697
+ Exchanges[exchange].position_all_ws((res) => {
698
+ position_all_handler(exchange, res)
699
+ })
582
700
  }, interval_dict[exchange].positions)
583
701
  } else if (Exchanges[exchange].position_ws) {
584
- if (Exchanges[exchange].ws_status().trading === 'n-opened')
585
- Exchanges[exchange].ws_account()
702
+ if (Exchanges[exchange].ws_status().trading === 'n-opened') Exchanges[exchange].ws_account()
586
703
  setInterval(() => {
587
704
  for (let pair of this.exchange_pairs[exchange]) {
588
- Exchanges[exchange].position_ws(pair, (res) => { position_handler (exchange, pair, res) })
705
+ Exchanges[exchange].position_ws(pair, (res) => {
706
+ position_handler(exchange, pair, res)
707
+ })
589
708
  }
590
709
  }, interval_dict[exchange].positions)
591
710
  } else if (Exchanges[exchange].position_all) {
592
711
  setInterval(() => {
593
- Exchanges[exchange].position_all((res) => { position_all_handler (exchange, res) })
712
+ Exchanges[exchange].position_all((res) => {
713
+ position_all_handler(exchange, res)
714
+ })
594
715
  }, interval_dict[exchange].positions)
595
716
  } else if (Exchanges[exchange].position) {
596
717
  setInterval(() => {
597
718
  for (let pair of this.exchange_pairs[exchange]) {
598
- Exchanges[exchange].position_ws(pair, (res) => { position_handler (exchange, pair, res) })
719
+ Exchanges[exchange].position_ws(pair, (res) => {
720
+ position_handler(exchange, pair, res)
721
+ })
599
722
  }
600
723
  }, interval_dict[exchange].positions)
601
724
  }
@@ -603,11 +726,11 @@ module.exports = class Orders {
603
726
  }
604
727
  get_positions(this.Exchanges, this.interval_dict)
605
728
  }
606
- check_open_orders () {
729
+ check_open_orders() {
607
730
  const open_orders_timeframe = 12 * 60 * 60 * 1000
608
731
  let previous_orders_processer = (exchange, pair, orders) => {
609
- if (this.cancel_previous_orders && !this.previous_orders_canceled && this.no_cancel_previous_exchanges.indexOf(exchange) === -1) {
610
- orders.map(order => {
732
+ if (this.cancel_previous_orders && !this.previous_orders_canceled && !_.includes(this.no_cancel_previous_exchanges, exchange)) {
733
+ orders.map((order) => {
611
734
  this.info_log('cancel original order: %s %s %j', exchange, pair, order)
612
735
  this.Exchanges[exchange].cancel_order_by_order(order, (res) => {})
613
736
  })
@@ -617,21 +740,20 @@ module.exports = class Orders {
617
740
  if (!this.previous_orders_canceled) {
618
741
  let previous_orders_canceled = true
619
742
  for (let exchange in this.exchange_pairs) {
620
- this.exchange_pairs[exchange].map(pair => {
743
+ this.exchange_pairs[exchange].map((pair) => {
621
744
  if (!_.get(this.previous_orders_canceled_exchange_pair, [exchange, pair])) {
622
745
  previous_orders_canceled = false
623
746
  }
624
747
  })
625
748
  }
626
- if (previous_orders_canceled)
627
- this.info_log('original order canceled')
749
+ if (previous_orders_canceled) this.info_log('original order canceled')
628
750
  this.previous_orders_canceled = previous_orders_canceled
629
751
  }
630
752
  }
631
753
  let rate_major = _.get(this.rates_combined_major, [pair])
632
- if (this.cancel_range_orders && this.major_exchanges[pair].indexOf(exchange) === -1 && this.no_cancel_range_exchanges.indexOf(exchange) === -1 && rate_major) {
633
- // console.log(exchange, pair, rate_major, orders)
634
- orders.map(order => {
754
+ if (this.cancel_range_orders && !_.includes(this.major_exchanges[pair], exchange) && !_.includes(this.no_cancel_range_exchanges, exchange) && rate_major) {
755
+ // console.log(exchange, pair, rate_major, orders)
756
+ orders.map((order) => {
635
757
  if (order.type === 'sell' && order.price < rate_major.asks[0][0] && order.order_status !== 'F-FILLED' && order.order_type !== 'arb') {
636
758
  this.info_log('cancel range order: %s %s %j', exchange, pair, order)
637
759
  order.order_type = 'range-order'
@@ -659,7 +781,7 @@ module.exports = class Orders {
659
781
  let all_open_orders_handler = (exchange, res) => {
660
782
  if (res.success) {
661
783
  for (let pair of this.exchange_pairs[exchange]) {
662
- let open_orders = res.body.filter(o => o.pair === pair)
784
+ let open_orders = res.body.filter((o) => o.pair === pair)
663
785
  _.set(this.open_orders, [exchange, pair], { open_orders: open_orders, update_time: new Date() })
664
786
  previous_orders_processer(exchange, pair, open_orders)
665
787
  }
@@ -680,9 +802,8 @@ module.exports = class Orders {
680
802
  }
681
803
  }
682
804
  let get_open_orders_all = (Exchanges, exchange_pairs, interval_dict) => {
683
- function get_all_open_orders_ws (exchange) {
684
- if (Exchanges[exchange].ws_status().trading === 'n-opened')
685
- Exchanges[exchange].ws_account()
805
+ function get_all_open_orders_ws(exchange) {
806
+ if (Exchanges[exchange].ws_status().trading === 'n-opened') Exchanges[exchange].ws_account()
686
807
  Exchanges[exchange].get_all_open_orders_ws((res) => {
687
808
  all_open_orders_handler(exchange, res)
688
809
  setTimeout(() => {
@@ -690,7 +811,7 @@ module.exports = class Orders {
690
811
  }, interval_dict[exchange].open_orders)
691
812
  })
692
813
  }
693
- function get_open_orders_ws (exchange, pair) {
814
+ function get_open_orders_ws(exchange, pair) {
694
815
  Exchanges[exchange].get_open_orders_ws(pair, (res) => {
695
816
  open_orders_handler(exchange, pair, res)
696
817
  setTimeout(() => {
@@ -698,7 +819,7 @@ module.exports = class Orders {
698
819
  }, interval_dict[exchange].open_orders)
699
820
  })
700
821
  }
701
- function get_all_open_orders (exchange) {
822
+ function get_all_open_orders(exchange) {
702
823
  Exchanges[exchange].get_all_open_orders((res) => {
703
824
  all_open_orders_handler(exchange, res)
704
825
  setTimeout(() => {
@@ -706,7 +827,7 @@ module.exports = class Orders {
706
827
  }, interval_dict[exchange].open_orders)
707
828
  })
708
829
  }
709
- function get_open_orders (exchange, pair) {
830
+ function get_open_orders(exchange, pair) {
710
831
  Exchanges[exchange].get_open_orders(pair, (res) => {
711
832
  open_orders_handler(exchange, pair, res)
712
833
  setTimeout(() => {
@@ -716,12 +837,10 @@ module.exports = class Orders {
716
837
  }
717
838
  for (let exchange in Exchanges) {
718
839
  if (Exchanges[exchange].get_all_open_orders_ws) {
719
- if (Exchanges[exchange].ws_status().trading === 'n-opened')
720
- Exchanges[exchange].ws_account()
840
+ if (Exchanges[exchange].ws_status().trading === 'n-opened') Exchanges[exchange].ws_account()
721
841
  get_all_open_orders_ws(exchange)
722
842
  } else if (Exchanges[exchange].get_open_orders_ws) {
723
- if (Exchanges[exchange].ws_status().trading === 'n-opened')
724
- Exchanges[exchange].ws_account()
843
+ if (Exchanges[exchange].ws_status().trading === 'n-opened') Exchanges[exchange].ws_account()
725
844
  for (let pair of exchange_pairs[exchange]) {
726
845
  get_open_orders_ws(exchange, pair)
727
846
  }
@@ -736,11 +855,18 @@ module.exports = class Orders {
736
855
  }
737
856
  get_open_orders_all(this.Exchanges, this.exchange_pairs, this.interval_dict)
738
857
  }
739
- check_trades () {
858
+ check_trades() {
740
859
  let trades_handler = (exchange, pair, res) => {
741
860
  if (res.success) {
742
861
  _.set(this.trades, [exchange, pair], { trades: res.body, update_time: new Date() })
743
- _.set(this.trades_amount_past_hour, [exchange, pair], _.sumBy(res.body.filter(t => t.close_time > new Date().getTime() - 60 * 60 * 1000 || t.open_time > new Date().getTime() - 60 * 60 * 1000), t => t.amount) || 0)
862
+ _.set(
863
+ this.trades_amount_past_hour,
864
+ [exchange, pair],
865
+ _.sumBy(
866
+ res.body.filter((t) => t.close_time > new Date().getTime() - 60 * 60 * 1000 || t.open_time > new Date().getTime() - 60 * 60 * 1000),
867
+ (t) => t.amount
868
+ ) || 0
869
+ )
744
870
  } else if (_.get(this.trades, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].trades) {
745
871
  this.info_log('%s %s trades expired: %j', exchange, pair, res)
746
872
  this.trades[exchange] = _.omit(this.trades[exchange], [pair])
@@ -751,9 +877,16 @@ module.exports = class Orders {
751
877
  let all_trades_handler = (exchange, res) => {
752
878
  if (res.success) {
753
879
  for (let pair of this.exchange_pairs[exchange]) {
754
- let trades = res.body.filter(o => o.pair === pair)
880
+ let trades = res.body.filter((o) => o.pair === pair)
755
881
  _.set(this.trades, [exchange, pair], { trades: trades, update_time: new Date() })
756
- _.set(this.trades_amount_past_hour, [exchange, pair], _.sumBy(trades.filter(t => t.close_time > new Date().getTime() - 60 * 60 * 1000 || t.open_time > new Date().getTime() - 60 * 60 * 1000), t => t.amount) || 0)
882
+ _.set(
883
+ this.trades_amount_past_hour,
884
+ [exchange, pair],
885
+ _.sumBy(
886
+ trades.filter((t) => t.close_time > new Date().getTime() - 60 * 60 * 1000 || t.open_time > new Date().getTime() - 60 * 60 * 1000),
887
+ (t) => t.amount
888
+ ) || 0
889
+ )
757
890
  }
758
891
  } else if (res.error !== 'opening') {
759
892
  let error_logged = false
@@ -773,8 +906,7 @@ module.exports = class Orders {
773
906
  }
774
907
  let get_trades_all = (Exchanges, exchange_pairs, interval_dict) => {
775
908
  let get_all_trades_ws = (exchange) => {
776
- if (Exchanges[exchange].ws_status().trading === 'n-opened')
777
- Exchanges[exchange].ws_account()
909
+ if (Exchanges[exchange].ws_status().trading === 'n-opened') Exchanges[exchange].ws_account()
778
910
  Exchanges[exchange].get_all_trades_ws(TRADES_DEFAULT_TIME, (res) => {
779
911
  all_trades_handler(exchange, res)
780
912
  setTimeout(() => {
@@ -811,7 +943,9 @@ module.exports = class Orders {
811
943
  let timeout = setTimeout(() => {
812
944
  get_trades_id(exchange, pair)
813
945
  }, interval_dict[exchange].trades)
814
- let order_number = _.keys(order_info['sell']).length + _.keys(order_info['buy']).length, count = 0, result = []
946
+ let order_number = _.keys(order_info['sell']).length + _.keys(order_info['buy']).length,
947
+ count = 0,
948
+ result = []
815
949
  for (let type in order_info) {
816
950
  for (let order_id in order_info[type]) {
817
951
  Exchanges[exchange].get_trades_id(pair, order_id, TRADES_DEFAULT_TIME, (res) => {
@@ -831,15 +965,12 @@ module.exports = class Orders {
831
965
  }
832
966
  }
833
967
  for (let exchange in Exchanges) {
834
- if (this.no_trades_function_exchanges.indexOf(exchange) > -1) {
835
-
968
+ if (_.includes(this.no_trades_function_exchanges, exchange)) {
836
969
  } else if (Exchanges[exchange].get_all_trades_ws) {
837
- if (Exchanges[exchange].ws_status().trading === 'n-opened')
838
- Exchanges[exchange].ws_account()
970
+ if (Exchanges[exchange].ws_status().trading === 'n-opened') Exchanges[exchange].ws_account()
839
971
  get_all_trades_ws(exchange)
840
972
  } else if (Exchanges[exchange].get_trades_ws) {
841
- if (Exchanges[exchange].ws_status().trading === 'n-opened')
842
- Exchanges[exchange].ws_account()
973
+ if (Exchanges[exchange].ws_status().trading === 'n-opened') Exchanges[exchange].ws_account()
843
974
  for (let pair of exchange_pairs[exchange]) {
844
975
  get_trades_ws(exchange, pair)
845
976
  }
@@ -856,46 +987,49 @@ module.exports = class Orders {
856
987
  }
857
988
  }
858
989
  }
859
- get_trades_all (this.Exchanges, this.exchange_pairs, this.interval_dict)
990
+ get_trades_all(this.Exchanges, this.exchange_pairs, this.interval_dict)
860
991
  }
861
- check_rates () {
992
+ check_rates() {
862
993
  let rates_handler = (exchange, pair, res) => {
863
994
  if (res.success) {
864
995
  res.body.asks = res.body.asks.slice(0, RATES_LENGTH_MAX)
865
996
  res.body.bids = res.body.bids.slice(0, RATES_LENGTH_MAX)
866
997
  _.set(this.rates, [exchange, pair], Object.assign(res.body, { update_time: new Date() }))
867
998
  for (let pair in this.pair_exchanges) {
868
- let orderbook_all = {}, orderbook_all_with_buy_sell_limits = {},
869
- orderbook_major = {}, orderbook_major_temp = {},
870
- orderbook_good_with_buy_sell_limits = {}, orderbook_good_temp = {}
999
+ let orderbook_all = {},
1000
+ orderbook_all_with_buy_sell_limits = {},
1001
+ orderbook_major = {},
1002
+ orderbook_major_temp = {},
1003
+ orderbook_good_with_buy_sell_limits = {},
1004
+ orderbook_good_temp = {}
871
1005
  for (let exchange of this.pair_exchanges[pair]) {
872
-
873
1006
  if (_.get(this.rates, [exchange, pair, 'asks'], []).length > 0 && _.get(this.rates, [exchange, pair, 'bids'], []).length > 0) {
874
1007
  orderbook_all[exchange] = this.rates[exchange][pair]
875
1008
  } else {
876
1009
  orderbook_all = _.omit(orderbook_all, [exchange])
877
1010
  }
878
1011
 
879
- if (_.get(this.rates, [exchange, pair, 'asks'], []).length > 0
880
- && _.get(this.rates, [exchange, pair, 'bids'], []).length > 0
881
- && _.get(this.buy_sell_limits, [exchange, pair, 'buy'])
882
- && _.get(this.buy_sell_limits, [exchange, pair, 'sell'])
1012
+ if (
1013
+ _.get(this.rates, [exchange, pair, 'asks'], []).length > 0 &&
1014
+ _.get(this.rates, [exchange, pair, 'bids'], []).length > 0 &&
1015
+ _.get(this.buy_sell_limits, [exchange, pair, 'buy']) &&
1016
+ _.get(this.buy_sell_limits, [exchange, pair, 'sell'])
883
1017
  ) {
884
1018
  let rates = JSON.parse(JSON.stringify(this.rates[exchange][pair]))
885
1019
  let rates_with_buy_sell_limits = {
886
1020
  asks: utils.sum_position_orderbook(rates.asks, this.buy_sell_limits[exchange][pair].buy),
887
- bids: utils.vol_position_orderbook(rates.bids, this.buy_sell_limits[exchange][pair].sell)
1021
+ bids: utils.vol_position_orderbook(rates.bids, this.buy_sell_limits[exchange][pair].sell),
888
1022
  }
889
1023
  orderbook_all_with_buy_sell_limits[exchange] = rates_with_buy_sell_limits
890
- if (this.major_exchanges[pair] && this.major_exchanges[pair].indexOf(exchange) > -1) {
1024
+ if (this.major_exchanges[pair] && _.includes(this.major_exchanges[pair], exchange)) {
891
1025
  orderbook_major_temp[exchange] = rates
892
1026
  if (_.keys(orderbook_major_temp).length === this.major_exchanges[pair].length) {
893
1027
  orderbook_major = orderbook_major_temp
894
1028
  }
895
1029
  }
896
- if (this.bad_trades_function_exchanges && this.bad_trades_function_exchanges.indexOf(exchange) === -1) {
1030
+ if (this.bad_trades_no_arb_function_exchanges && !_.includes(this.bad_trades_no_arb_function_exchanges, exchange)) {
897
1031
  orderbook_good_temp[exchange] = rates_with_buy_sell_limits
898
- if (_.keys(orderbook_good_temp).length === this.pair_exchanges[pair].length - this.bad_trades_function_exchanges.length) {
1032
+ if (_.keys(orderbook_good_temp).length === this.pair_exchanges[pair].length - this.bad_trades_no_arb_function_exchanges.length) {
899
1033
  orderbook_good_with_buy_sell_limits = orderbook_good_temp
900
1034
  }
901
1035
  }
@@ -954,22 +1088,26 @@ module.exports = class Orders {
954
1088
  this.ws_market_first_time[exchange] = true
955
1089
  } else {
956
1090
  for (let pair of exchange_pairs[exchange]) {
957
- Exchanges[exchange].rate_ws(pair, (res) => { rates_handler(exchange, pair, res) })
1091
+ Exchanges[exchange].rate_ws(pair, (res) => {
1092
+ rates_handler(exchange, pair, res)
1093
+ })
958
1094
  }
959
1095
  }
960
1096
  }, interval_dict[exchange].rates)
961
1097
  } else {
962
1098
  for (let pair of exchange_pairs[exchange]) {
963
1099
  setInterval(() => {
964
- Exchanges[exchange].rate(pair, RATES_LENGTH_DEFAULT, (res) => { rates_handler(exchange, pair, res) })
1100
+ Exchanges[exchange].rate(pair, RATES_LENGTH_DEFAULT, (res) => {
1101
+ rates_handler(exchange, pair, res)
1102
+ })
965
1103
  }, interval_dict[exchange].rates)
966
1104
  }
967
1105
  }
968
1106
  }
969
1107
  }
970
- get_rates (this.Exchanges, this.exchange_pairs, this.interval_dict)
1108
+ get_rates(this.Exchanges, this.exchange_pairs, this.interval_dict)
971
1109
  }
972
- check_market_history () {
1110
+ check_market_history() {
973
1111
  let market_history_handler = (exchange, pair, res) => {
974
1112
  if (res.success) {
975
1113
  _.set(this.market_history, [exchange, pair], Object.assign(res.body, { update_time: new Date() }))
@@ -980,7 +1118,7 @@ module.exports = class Orders {
980
1118
  }
981
1119
  let get_market_history = (Exchanges, exchange_pairs, interval_dict) => {
982
1120
  for (let exchange in Exchanges) {
983
- const market_history_timeframe = (exchange === 'coinbene') ? 30 * 24 * 60 * 60 * 1000 : MARKET_HISTORY_DEFAULT_TIME
1121
+ const market_history_timeframe = exchange === 'coinbene' ? 30 * 24 * 60 * 60 * 1000 : MARKET_HISTORY_DEFAULT_TIME
984
1122
  if (Exchanges[exchange].ws_market) {
985
1123
  setInterval(() => {
986
1124
  if (!this.ws_market_first_time[exchange]) {
@@ -988,29 +1126,33 @@ module.exports = class Orders {
988
1126
  this.ws_market_first_time[exchange] = true
989
1127
  } else {
990
1128
  for (let pair of exchange_pairs[exchange]) {
991
- Exchanges[exchange].market_history_ws(pair, market_history_timeframe, (res) => { market_history_handler(exchange, pair, res) })
1129
+ Exchanges[exchange].market_history_ws(pair, market_history_timeframe, (res) => {
1130
+ market_history_handler(exchange, pair, res)
1131
+ })
992
1132
  }
993
1133
  }
994
1134
  }, interval_dict[exchange].market_history)
995
1135
  } else {
996
1136
  for (let pair of exchange_pairs[exchange]) {
997
1137
  setInterval(() => {
998
- Exchanges[exchange].market_history(pair, market_history_timeframe, (res) => { market_history_handler(exchange, pair, res) })
1138
+ Exchanges[exchange].market_history(pair, market_history_timeframe, (res) => {
1139
+ market_history_handler(exchange, pair, res)
1140
+ })
999
1141
  }, interval_dict[exchange].market_history)
1000
1142
  }
1001
1143
  }
1002
1144
  }
1003
1145
  }
1004
- get_market_history (this.Exchanges, this.exchange_pairs, this.interval_dict)
1146
+ get_market_history(this.Exchanges, this.exchange_pairs, this.interval_dict)
1005
1147
  }
1006
- check_volumes () {
1148
+ check_volumes() {
1007
1149
  const influx_client = new Influx.InfluxDB(this.influx_url_check_volume)
1008
1150
  let check_volumes_base = () => {
1009
1151
  for (let pair in this.pair_exchanges) {
1010
1152
  for (let exchange of this.pair_exchanges[pair]) {
1011
- let query_string = `SELECT sum("vol") FROM "${pair}" WHERE ("exchange" = '${_.upperFirst(exchange)}') AND time > now() - 12h`
1012
- influx_client.query(query_string).then(res => {
1013
- res.map(e => {
1153
+ let query_string = `SELECT sum("vol") FROM "${pair}" WHERE ("exchange" = '${_.upperFirst(exchange)}') AND time > now() - 12h`
1154
+ influx_client.query(query_string).then((res) => {
1155
+ res.map((e) => {
1014
1156
  if (e.time && e.sum) {
1015
1157
  _.set(this.volumes, [pair, exchange], e.sum)
1016
1158
  }
@@ -1022,17 +1164,21 @@ module.exports = class Orders {
1022
1164
  check_volumes_base()
1023
1165
  setInterval(() => {
1024
1166
  check_volumes_base()
1025
- }, 15 * 60 * 1000)
1167
+ }, 15 * 60 * 1000)
1026
1168
  }
1027
- check_cmc_rates (data, type) {
1169
+ check_cmc_rates(data, type) {
1028
1170
  let check_cmc_rates_base = (data) => {
1029
- get_coinmarketcap_rates(rates => {
1030
- this.cmc_rates = rates
1031
- }, data, type)
1171
+ get_coinmarketcap_rates(
1172
+ (rates) => {
1173
+ this.cmc_rates = rates
1174
+ },
1175
+ data,
1176
+ type
1177
+ )
1032
1178
  }
1033
1179
  check_cmc_rates_base(data, type)
1034
1180
  setInterval(() => {
1035
1181
  check_cmc_rates_base(data, type)
1036
- }, 15 * 60 * 1000)
1182
+ }, 15 * 60 * 1000)
1037
1183
  }
1038
1184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-exchanges-wrapper",
3
- "version": "1.9.62",
3
+ "version": "1.9.64",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,8 +17,8 @@
17
17
  },
18
18
  "homepage": "https://github.com/icgio/icg-exchanges-wrapper#readme",
19
19
  "dependencies": {
20
- "@icgio/icg-exchanges": "^1.27.50",
21
- "@icgio/icg-exchanges-data": "^1.6.26",
20
+ "@icgio/icg-exchanges": "^1.27.52",
21
+ "@icgio/icg-exchanges-data": "^1.6.27",
22
22
  "@icgio/icg-utils": "^1.7.12",
23
23
  "influx": "^5.7.0",
24
24
  "lodash": "^4.17.20",