From a7e5a316be75e03878d1b9023b880c936611ce0d Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Wed, 11 Jan 2023 19:59:13 +0100 Subject: [PATCH] Bugfix/fix big.js exception in report endpoint (#1586) * Fix exception with missing marketPrice * Update changelog --- CHANGELOG.md | 4 +++ .../src/app/portfolio/portfolio.service.ts | 25 +++++++++++++------ .../base-currency-current-investment.ts | 7 +++--- .../base-currency-initial-investment.ts | 7 +++--- .../current-investment.ts | 9 +++---- .../initial-investment.ts | 7 +++--- 6 files changed, 34 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce50bb067..5eb0f323c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the form of the import dividends dialog (disable while loading) - Removed the deprecated `~` in _Sass_ imports +### Fixed + +- Fixed an exception in the _X-ray_ section + ## 1.225.0 - 2023-01-07 ### Added diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 37fae84d7..f752010b3 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -910,12 +910,14 @@ export class PortfolioService { const positions = currentPositions.positions.filter( (item) => !item.quantity.eq(0) ); + const dataGatheringItem = positions.map((position) => { return { dataSource: position.dataSource, symbol: position.symbol }; }); + const symbols = positions.map((position) => position.symbol); const [dataProviderResponses, symbolProfiles] = await Promise.all([ @@ -1103,16 +1105,23 @@ export class PortfolioService { portfolioStart ); + const positions = currentPositions.positions.filter( + (item) => !item.quantity.eq(0) + ); + const portfolioItemsNow: { [symbol: string]: TimelinePosition } = {}; - for (const position of currentPositions.positions) { + + for (const position of positions) { portfolioItemsNow[position.symbol] = position; } + const accounts = await this.getValueOfAccounts({ orders, portfolioItemsNow, - userId, - userCurrency + userCurrency, + userId }); + return { rules: { accountClusterRisk: await this.rulesService.evaluate( @@ -1136,19 +1145,19 @@ export class PortfolioService { [ new CurrencyClusterRiskBaseCurrencyInitialInvestment( this.exchangeRateDataService, - currentPositions + positions ), new CurrencyClusterRiskBaseCurrencyCurrentInvestment( this.exchangeRateDataService, - currentPositions + positions ), new CurrencyClusterRiskInitialInvestment( this.exchangeRateDataService, - currentPositions + positions ), new CurrencyClusterRiskCurrentInvestment( this.exchangeRateDataService, - currentPositions + positions ) ], this.request.user.Settings.settings @@ -1682,7 +1691,7 @@ export class PortfolioService { for (const order of ordersByAccount) { let currentValueOfSymbolInBaseCurrency = order.quantity * - portfolioItemsNow[order.SymbolProfile.symbol].marketPrice; + portfolioItemsNow[order.SymbolProfile.symbol]?.marketPrice ?? 0; let originalValueOfSymbolInBaseCurrency = this.exchangeRateDataService.toCurrency( order.quantity * order.unitPrice, diff --git a/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts index 5f1f4cf93..1d584b04f 100644 --- a/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts +++ b/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts @@ -1,14 +1,13 @@ -import { CurrentPositions } from '@ghostfolio/api/app/portfolio/interfaces/current-positions.interface'; import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; -import { UserSettings } from '@ghostfolio/common/interfaces'; +import { TimelinePosition, UserSettings } from '@ghostfolio/common/interfaces'; import { Rule } from '../../rule'; export class CurrencyClusterRiskBaseCurrencyCurrentInvestment extends Rule { public constructor( protected exchangeRateDataService: ExchangeRateDataService, - private currentPositions: CurrentPositions + private positions: TimelinePosition[] ) { super(exchangeRateDataService, { name: 'Current Investment: Base Currency' @@ -17,7 +16,7 @@ export class CurrencyClusterRiskBaseCurrencyCurrentInvestment extends Rule { public constructor( protected exchangeRateDataService: ExchangeRateDataService, - private currentPositions: CurrentPositions + private positions: TimelinePosition[] ) { super(exchangeRateDataService, { name: 'Initial Investment: Base Currency' @@ -17,7 +16,7 @@ export class CurrencyClusterRiskBaseCurrencyInitialInvestment extends Rule { public constructor( - public exchangeRateDataService: ExchangeRateDataService, - private currentPositions: CurrentPositions + protected exchangeRateDataService: ExchangeRateDataService, + private positions: TimelinePosition[] ) { super(exchangeRateDataService, { name: 'Current Investment' @@ -17,7 +16,7 @@ export class CurrencyClusterRiskCurrentInvestment extends Rule { public evaluate(ruleSettings: Settings) { const positionsGroupedByCurrency = this.groupCurrentPositionsByAttribute( - this.currentPositions.positions, + this.positions, 'currency', ruleSettings.baseCurrency ); diff --git a/apps/api/src/models/rules/currency-cluster-risk/initial-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/initial-investment.ts index 331074f16..18477f6f7 100644 --- a/apps/api/src/models/rules/currency-cluster-risk/initial-investment.ts +++ b/apps/api/src/models/rules/currency-cluster-risk/initial-investment.ts @@ -1,14 +1,13 @@ -import { CurrentPositions } from '@ghostfolio/api/app/portfolio/interfaces/current-positions.interface'; import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; -import { UserSettings } from '@ghostfolio/common/interfaces'; +import { TimelinePosition, UserSettings } from '@ghostfolio/common/interfaces'; import { Rule } from '../../rule'; export class CurrencyClusterRiskInitialInvestment extends Rule { public constructor( protected exchangeRateDataService: ExchangeRateDataService, - private currentPositions: CurrentPositions + private positions: TimelinePosition[] ) { super(exchangeRateDataService, { name: 'Initial Investment' @@ -17,7 +16,7 @@ export class CurrencyClusterRiskInitialInvestment extends Rule { public evaluate(ruleSettings: Settings) { const positionsGroupedByCurrency = this.groupCurrentPositionsByAttribute( - this.currentPositions.positions, + this.positions, 'currency', ruleSettings.baseCurrency );