@icgio/icg-utils 1.9.13 → 1.9.14
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 +21 -3
- package/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -544,7 +544,7 @@ module.exports.combine_orderbooks = (orderbooks_dict, length = undefined) => {
|
|
|
544
544
|
// )
|
|
545
545
|
// console.log(module.exports.combine_orderbooks({}, 100))
|
|
546
546
|
|
|
547
|
-
module.exports.arb_opportunities_from_combined_orderbook = (orderbook_combined, profit_percentage = 0, amount_cap = 0) => {
|
|
547
|
+
module.exports.arb_opportunities_from_combined_orderbook = (orderbook_combined, profit_percentage = 0, amount_cap = 0, quote_amount_cap = 0) => {
|
|
548
548
|
let i = 0,
|
|
549
549
|
j = 0,
|
|
550
550
|
ask_amount = 0,
|
|
@@ -614,15 +614,33 @@ module.exports.arb_opportunities_from_combined_orderbook = (orderbook_combined,
|
|
|
614
614
|
opportunities[bid[2]].amount += bid[1]
|
|
615
615
|
opportunities[bid[2]].total = opportunities[bid[2]].avg_price * opportunities[bid[2]].amount
|
|
616
616
|
})
|
|
617
|
+
|
|
618
|
+
// Apply amount caps if needed
|
|
617
619
|
let amount_total = _.sumBy(_.values(opportunities), 'amount')
|
|
620
|
+
let quote_amount_total = _.sumBy(_.values(opportunities), 'total')
|
|
621
|
+
let amount_coeff = 1
|
|
622
|
+
let quote_amount_coeff = 1
|
|
623
|
+
|
|
618
624
|
if (amount_total > amount_cap && amount_cap !== 0) {
|
|
619
|
-
|
|
625
|
+
amount_coeff = amount_cap / amount_total
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
if (quote_amount_total > quote_amount_cap && quote_amount_cap !== 0) {
|
|
629
|
+
quote_amount_coeff = quote_amount_cap / quote_amount_total
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// Use the more restrictive coefficient
|
|
633
|
+
let final_coeff = Math.min(amount_coeff, quote_amount_coeff)
|
|
634
|
+
|
|
635
|
+
if (final_coeff < 1) {
|
|
620
636
|
for (let exchange in opportunities) {
|
|
621
637
|
let opportunity = opportunities[exchange]
|
|
622
|
-
opportunity.reduced_amount = opportunity.amount *
|
|
638
|
+
opportunity.reduced_amount = opportunity.amount * final_coeff
|
|
639
|
+
opportunity.reduced_total = opportunity.total * final_coeff
|
|
623
640
|
opportunities[exchange] = opportunity
|
|
624
641
|
}
|
|
625
642
|
}
|
|
643
|
+
|
|
626
644
|
return opportunities
|
|
627
645
|
}
|
|
628
646
|
|