@icgio/icg-utils 1.6.21 → 1.6.22

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 +11 -2
  2. package/package.json +1 -1
package/lib/utils.js CHANGED
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.6.21",
3
+ "version": "1.6.22",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {