@icgio/icg-utils 1.7.23 → 1.7.24
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/lib/utils.js +60 -20
- 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 (
|
|
387
|
-
|
|
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]) {
|
|
@@ -394,12 +402,15 @@ module.exports.combine_orderbooks = (orderbooks_dict, length = undefined) => {
|
|
|
394
402
|
}
|
|
395
403
|
}
|
|
396
404
|
result.push(picked)
|
|
397
|
-
|
|
398
|
-
|
|
405
|
+
let picked_exchange = picked[2]
|
|
406
|
+
if (count[picked_exchange] < orderbooks_dict[picked_exchange][type].length - 1) {
|
|
407
|
+
count[picked_exchange] += 1
|
|
399
408
|
} else {
|
|
400
|
-
count[
|
|
409
|
+
count[picked_exchange] = -1 // -1 means finished
|
|
410
|
+
}
|
|
411
|
+
if (result.length === length) {
|
|
412
|
+
break
|
|
401
413
|
}
|
|
402
|
-
if (result.length === length) break
|
|
403
414
|
}
|
|
404
415
|
return result
|
|
405
416
|
}
|
|
@@ -408,20 +419,49 @@ module.exports.combine_orderbooks = (orderbooks_dict, length = undefined) => {
|
|
|
408
419
|
return { asks, bids }
|
|
409
420
|
}
|
|
410
421
|
|
|
411
|
-
// console.log(
|
|
412
|
-
//
|
|
413
|
-
//
|
|
414
|
-
//
|
|
415
|
-
//
|
|
416
|
-
//
|
|
417
|
-
//
|
|
418
|
-
//
|
|
419
|
-
//
|
|
420
|
-
//
|
|
421
|
-
//
|
|
422
|
-
//
|
|
423
|
-
//
|
|
424
|
-
//
|
|
422
|
+
// console.log(
|
|
423
|
+
// module.exports.combine_orderbooks(
|
|
424
|
+
// {
|
|
425
|
+
// // binance: {
|
|
426
|
+
// // // asks: [
|
|
427
|
+
// // // [1, 1],
|
|
428
|
+
// // // [2, 2],
|
|
429
|
+
// // // [3, 3],
|
|
430
|
+
// // // ],
|
|
431
|
+
// // // bids: [
|
|
432
|
+
// // // [0.9, 0.9],
|
|
433
|
+
// // // [0.5, 0.5],
|
|
434
|
+
// // // [0.3, 0.2],
|
|
435
|
+
// // // ],
|
|
436
|
+
// // },
|
|
437
|
+
// bittrex: {
|
|
438
|
+
// asks: [
|
|
439
|
+
// [4, 4],
|
|
440
|
+
// [5, 5],
|
|
441
|
+
// [8, 8],
|
|
442
|
+
// ],
|
|
443
|
+
// bids: [
|
|
444
|
+
// // [0.6, 0.9],
|
|
445
|
+
// // [0.5, 0.2],
|
|
446
|
+
// // [0.2, 0.2],
|
|
447
|
+
// ],
|
|
448
|
+
// },
|
|
449
|
+
// poloniex: {
|
|
450
|
+
// asks: [
|
|
451
|
+
// [1, 1],
|
|
452
|
+
// [6, 6],
|
|
453
|
+
// [7, 7],
|
|
454
|
+
// ],
|
|
455
|
+
// bids: [
|
|
456
|
+
// [0.95, 0.9],
|
|
457
|
+
// [0.7, 0.5],
|
|
458
|
+
// [0.4, 0.2],
|
|
459
|
+
// ],
|
|
460
|
+
// },
|
|
461
|
+
// },
|
|
462
|
+
// 100
|
|
463
|
+
// )
|
|
464
|
+
// )
|
|
425
465
|
// console.log(module.exports.combine_orderbooks({}, 100))
|
|
426
466
|
|
|
427
467
|
module.exports.arb_opportunities_from_combined_orderbook = (orderbook_combined, profit_percentage = 0, amount_cap = 0) => {
|