diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e468015e..152afcab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed the activities sorting in the position detail dialog +- Fixed a division by zero error in the cash positions calculation ## 1.213.0 - 14.11.2022 diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index f7efd6651..125002b36 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -1163,16 +1163,12 @@ export class PortfolioService { for (const symbol of Object.keys(cashPositions)) { // Calculate allocations for each currency - cashPositions[symbol].allocationCurrent = new Big( - cashPositions[symbol].value - ) - .div(value) - .toNumber(); - cashPositions[symbol].allocationInvestment = new Big( - cashPositions[symbol].investment - ) - .div(investment) - .toNumber(); + cashPositions[symbol].allocationCurrent = value.gt(0) + ? new Big(cashPositions[symbol].value).div(value).toNumber() + : 0; + cashPositions[symbol].allocationInvestment = investment.gt(0) + ? new Big(cashPositions[symbol].investment).div(investment).toNumber() + : 0; } return cashPositions;