Browse Source

Handle division by zero (#1398)

pull/1401/head
Thomas Kaul 2 years ago
committed by GitHub
parent
commit
5c6cc4fed5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      apps/api/src/app/portfolio/portfolio-calculator.ts

6
apps/api/src/app/portfolio/portfolio-calculator.ts

@ -1036,10 +1036,12 @@ export class PortfolioCalculator {
const transactionInvestment = const transactionInvestment =
order.type === 'BUY' order.type === 'BUY'
? order.quantity.mul(order.unitPrice).mul(this.getFactor(order.type)) ? order.quantity.mul(order.unitPrice).mul(this.getFactor(order.type))
: totalInvestment : totalUnits.gt(0)
? totalInvestment
.div(totalUnits) .div(totalUnits)
.mul(order.quantity) .mul(order.quantity)
.mul(this.getFactor(order.type)); .mul(this.getFactor(order.type))
: new Big(0);
if (PortfolioCalculator.ENABLE_LOGGING) { if (PortfolioCalculator.ENABLE_LOGGING) {
console.log('totalInvestment', totalInvestment.toNumber()); console.log('totalInvestment', totalInvestment.toNumber());

Loading…
Cancel
Save