@icgio/icg-utils 1.9.13 → 1.9.15

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 +46 -3
  2. 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
- let coeff = amount_cap / amount_total
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 * coeff
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
 
@@ -828,11 +846,36 @@ module.exports.exchange_cur_quote_cur_converter = (exchange_cur_quote_cur) => {
828
846
  pair_exchanges[pair].push(exchange)
829
847
  })
830
848
  }
849
+ // Add exchange_pairs_without_2
850
+ let exchange_pairs_without_2 = {}
851
+ for (let exchange in exchange_pairs) {
852
+ if (!exchange.endsWith('_2')) {
853
+ exchange_pairs_without_2[exchange] = exchange_pairs[exchange]
854
+ }
855
+ }
856
+ // Add exchange_curs_without_2
857
+ let exchange_curs_without_2 = {}
858
+ for (let exchange in exchange_curs) {
859
+ if (!exchange.endsWith('_2')) {
860
+ exchange_curs_without_2[exchange] = exchange_curs[exchange]
861
+ }
862
+ }
863
+ // Add pair_exchanges_without_2
864
+ let pair_exchanges_without_2 = {}
865
+ for (let pair in pair_exchanges) {
866
+ pair_exchanges_without_2[pair] = pair_exchanges[pair].filter((exchange) => !exchange.endsWith('_2'))
867
+ if (pair_exchanges_without_2[pair].length === 0) {
868
+ delete pair_exchanges_without_2[pair]
869
+ }
870
+ }
831
871
  return {
832
872
  exchange_cur_quote_cur,
833
873
  exchange_pairs,
874
+ exchange_pairs_without_2,
834
875
  exchange_curs,
876
+ exchange_curs_without_2,
835
877
  pair_exchanges,
878
+ pair_exchanges_without_2,
836
879
  }
837
880
  }
838
881
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.9.13",
3
+ "version": "1.9.15",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {