@icgio/icg-utils 1.6.21 → 1.6.23
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 +13 -4
- package/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const _ = require('lodash')
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
let toFixed_old = Number.prototype.toFixed
|
|
4
4
|
|
|
5
5
|
Number.prototype.toFixed = function(s) {
|
|
6
6
|
if (s >= 0 && s <= 20) {
|
|
7
|
-
return
|
|
7
|
+
return toFixed_old(s)
|
|
8
8
|
}
|
|
9
9
|
let changenum = (parseInt(this * Math.pow(10, s) + 0.5) / Math.pow(10, s)).toString()
|
|
10
10
|
index = changenum.indexOf('.')
|
|
@@ -379,7 +379,7 @@ module.exports.combine_orderbooks = (orderbooks_dict, length=undefined) => {
|
|
|
379
379
|
// }
|
|
380
380
|
// }, 3))
|
|
381
381
|
|
|
382
|
-
module.exports.arb_opportunities_from_combined_orderbook = (orderbook_combined, profit_percentage=0) => {
|
|
382
|
+
module.exports.arb_opportunities_from_combined_orderbook = (orderbook_combined, profit_percentage=0, amount_cap=0) => {
|
|
383
383
|
let i = 0, j = 0, ask_amount = 0, bid_amount = 0
|
|
384
384
|
let asks = orderbook_combined.asks, bids = orderbook_combined.bids
|
|
385
385
|
if (asks[0][0] * (1 + profit_percentage) >= bids[0][0])
|
|
@@ -445,6 +445,15 @@ module.exports.arb_opportunities_from_combined_orderbook = (orderbook_combined,
|
|
|
445
445
|
opportunities[bid[2]].amount += bid[1]
|
|
446
446
|
opportunities[bid[2]].total = opportunities[bid[2]].avg_price * opportunities[bid[2]].amount
|
|
447
447
|
})
|
|
448
|
+
let amount_total = _.sumBy(_.values(opportunities), 'amount')
|
|
449
|
+
if (amount_total > amount_cap && amount_cap !== 0) {
|
|
450
|
+
let coeff = amount_cap / amount_total
|
|
451
|
+
for (let exchange in opportunities) {
|
|
452
|
+
let opportunity = opportunities[exchange]
|
|
453
|
+
opportunity.reduced_amount = opportunity.amount * coeff
|
|
454
|
+
opportunities[exchange] = opportunity
|
|
455
|
+
}
|
|
456
|
+
}
|
|
448
457
|
return opportunities
|
|
449
458
|
}
|
|
450
459
|
|
|
@@ -459,7 +468,7 @@ module.exports.arb_opportunities_from_combined_orderbook = (orderbook_combined,
|
|
|
459
468
|
// [ 0.3049, 5956.5837, 'huobi' ],
|
|
460
469
|
// [ 0.3038, 4373.4668, 'huobi' ],
|
|
461
470
|
// [ 0.3027, 867.8638, 'huobi' ] ]
|
|
462
|
-
// }, 0.0004))
|
|
471
|
+
// }, 0.0004, amount_cap=1))
|
|
463
472
|
|
|
464
473
|
module.exports.vol_position_combined = function (input_array, vol_target) {
|
|
465
474
|
if (input_array.length === 1) {
|