@icgio/icg-utils 1.7.23 → 1.7.25

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/lib/utils.js +64 -22
  2. package/package.json +1 -1
package/lib/utils.js CHANGED
@@ -380,11 +380,19 @@ module.exports.combine_orderbooks = (orderbooks_dict, length = undefined) => {
380
380
  count[exchange] = 0
381
381
  }
382
382
  let result = []
383
+ // * -1 check if all exchanges are done
383
384
  while (_.sum(_.values(count)) !== _.keys(orderbooks_dict).length * -1) {
384
385
  let picked
385
386
  for (let exchange in orderbooks_dict) {
386
- if (count[exchange] === -1) continue
387
- if (_.get(orderbooks_dict, [exchange, type, count[exchange], 'length']) === 2) orderbooks_dict[exchange][type][count[exchange]].push(exchange)
387
+ if (_.get(orderbooks_dict, [exchange, type], []).length === 0) {
388
+ count[exchange] = -1 // -1 means finished
389
+ }
390
+ if (count[exchange] === -1) {
391
+ continue
392
+ }
393
+ if (_.get(orderbooks_dict, [exchange, type, count[exchange], 'length']) === 2) {
394
+ orderbooks_dict[exchange][type][count[exchange]].push(exchange)
395
+ }
388
396
  if (!picked) {
389
397
  picked = orderbooks_dict[exchange][type][count[exchange]]
390
398
  } else if (type === 'asks' && picked[0] > orderbooks_dict[exchange][type][count[exchange]][0]) {
@@ -393,13 +401,18 @@ module.exports.combine_orderbooks = (orderbooks_dict, length = undefined) => {
393
401
  picked = orderbooks_dict[exchange][type][count[exchange]]
394
402
  }
395
403
  }
396
- result.push(picked)
397
- if (count[picked[2]] < orderbooks_dict[picked[2]][type].length - 1) {
398
- count[picked[2]] += 1
399
- } else {
400
- count[picked[2]] = -1
404
+ if (picked) {
405
+ result.push(picked)
406
+ let picked_exchange = picked[2]
407
+ if (count[picked_exchange] < orderbooks_dict[picked_exchange][type].length - 1) {
408
+ count[picked_exchange] += 1
409
+ } else {
410
+ count[picked_exchange] = -1 // -1 means finished
411
+ }
412
+ }
413
+ if (result.length === length) {
414
+ break
401
415
  }
402
- if (result.length === length) break
403
416
  }
404
417
  return result
405
418
  }
@@ -408,20 +421,49 @@ module.exports.combine_orderbooks = (orderbooks_dict, length = undefined) => {
408
421
  return { asks, bids }
409
422
  }
410
423
 
411
- // console.log(module.exports.combine_orderbooks({
412
- // 'binance': {
413
- // asks: [[1, 1], [2, 2], [3, 3]],
414
- // bids: [[0.9, 0.9], [0.5, 0.5], [0.3, 0.2]]
415
- // },
416
- // 'bittrex': {
417
- // asks: [[4, 4], [5, 5], [8, 8]],
418
- // bids: [[0.6, 0.9], [0.5, 0.2], [0.2, 0.2]]
419
- // },
420
- // 'poloniex': {
421
- // asks: [[1, 1], [6, 6], [7, 7]],
422
- // bids: [[0.95, 0.9], [0.7, 0.5], [0.4, 0.2]]
423
- // }
424
- // }, 3))
424
+ console.log(
425
+ module.exports.combine_orderbooks(
426
+ {
427
+ // binance: {
428
+ // // asks: [
429
+ // // [1, 1],
430
+ // // [2, 2],
431
+ // // [3, 3],
432
+ // // ],
433
+ // // bids: [
434
+ // // [0.9, 0.9],
435
+ // // [0.5, 0.5],
436
+ // // [0.3, 0.2],
437
+ // // ],
438
+ // },
439
+ bittrex: {
440
+ // asks: [
441
+ // // [4, 4],
442
+ // // [5, 5],
443
+ // // [8, 8],
444
+ // ],
445
+ bids: [
446
+ [0.6, 0.9],
447
+ [0.5, 0.2],
448
+ [0.2, 0.2],
449
+ ],
450
+ },
451
+ poloniex: {
452
+ // asks: [
453
+ // // [1, 1],
454
+ // // [6, 6],
455
+ // // [7, 7],
456
+ // ],
457
+ bids: [
458
+ [0.95, 0.9],
459
+ [0.7, 0.5],
460
+ [0.4, 0.2],
461
+ ],
462
+ },
463
+ },
464
+ 100
465
+ )
466
+ )
425
467
  // console.log(module.exports.combine_orderbooks({}, 100))
426
468
 
427
469
  module.exports.arb_opportunities_from_combined_orderbook = (orderbook_combined, profit_percentage = 0, amount_cap = 0) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.7.23",
3
+ "version": "1.7.25",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {