Browse Source

Bugfix/exception in portfolio details endpoint for unmatched asset profile (#6861)

* Resolve exception in portfolio details endpoint when an asset profile is unmatched

* Use asset profile identifier for value uniqueness

* Update changelog
pull/6862/head
Thomas Kaul 1 week ago
committed by GitHub
parent
commit
f82fbcfc58
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      CHANGELOG.md
  2. 21
      apps/api/src/app/portfolio/current-rate.service.ts
  3. 34
      apps/api/src/app/portfolio/portfolio.service.ts
  4. 4
      apps/api/src/services/data-provider/data-provider.service.ts

6
CHANGELOG.md

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Fixed
- Resolved an exception in the portfolio details endpoint when an asset profile is unmatched
## 3.3.0 - 2026-05-14 ## 3.3.0 - 2026-05-14
### Added ### Added

21
apps/api/src/app/portfolio/current-rate.service.ts

@ -2,7 +2,10 @@ import { ActivitiesService } from '@ghostfolio/api/app/activities/activities.ser
import { LogPerformance } from '@ghostfolio/api/interceptors/performance-logging/performance-logging.interceptor'; import { LogPerformance } from '@ghostfolio/api/interceptors/performance-logging/performance-logging.interceptor';
import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service';
import { MarketDataService } from '@ghostfolio/api/services/market-data/market-data.service'; import { MarketDataService } from '@ghostfolio/api/services/market-data/market-data.service';
import { resetHours } from '@ghostfolio/common/helper'; import {
getAssetProfileIdentifier,
resetHours
} from '@ghostfolio/common/helper';
import { import {
AssetProfileIdentifier, AssetProfileIdentifier,
DataProviderInfo, DataProviderInfo,
@ -114,8 +117,8 @@ export class CurrentRateService {
errors: quoteErrors.map(({ dataSource, symbol }) => { errors: quoteErrors.map(({ dataSource, symbol }) => {
return { dataSource, symbol }; return { dataSource, symbol };
}), }),
values: uniqBy(values, ({ date, symbol }) => { values: uniqBy(values, ({ dataSource, date, symbol }) => {
return `${date}-${symbol}`; return `${date}-${getAssetProfileIdentifier({ dataSource, symbol })}`;
}) })
}; };
@ -124,7 +127,11 @@ export class CurrentRateService {
try { try {
// If missing quote, fallback to the latest available historical market price // If missing quote, fallback to the latest available historical market price
let value: GetValueObject = response.values.find((currentValue) => { let value: GetValueObject = response.values.find((currentValue) => {
return currentValue.symbol === symbol && isToday(currentValue.date); return (
currentValue.dataSource === dataSource &&
currentValue.symbol === symbol &&
isToday(currentValue.date)
);
}); });
if (!value) { if (!value) {
@ -147,7 +154,11 @@ export class CurrentRateService {
const [latestValue] = response.values const [latestValue] = response.values
.filter((currentValue) => { .filter((currentValue) => {
return currentValue.symbol === symbol && currentValue.marketPrice; return (
currentValue.dataSource === dataSource &&
currentValue.marketPrice &&
currentValue.symbol === symbol
);
}) })
.sort((a, b) => { .sort((a, b) => {
if (a.date < b.date) { if (a.date < b.date) {

34
apps/api/src/app/portfolio/portfolio.service.ts

@ -36,7 +36,12 @@ import {
TAG_ID_EXCLUDE_FROM_ANALYSIS, TAG_ID_EXCLUDE_FROM_ANALYSIS,
UNKNOWN_KEY UNKNOWN_KEY
} from '@ghostfolio/common/config'; } from '@ghostfolio/common/config';
import { DATE_FORMAT, getSum, parseDate } from '@ghostfolio/common/helper'; import {
DATE_FORMAT,
getAssetProfileIdentifier,
getSum,
parseDate
} from '@ghostfolio/common/helper';
import { import {
AccountsResponse, AccountsResponse,
Activity, Activity,
@ -64,7 +69,7 @@ import {
} from '@ghostfolio/common/types'; } from '@ghostfolio/common/types';
import { PerformanceCalculationType } from '@ghostfolio/common/types/performance-calculation-type.type'; import { PerformanceCalculationType } from '@ghostfolio/common/types/performance-calculation-type.type';
import { Inject, Injectable } from '@nestjs/common'; import { Inject, Injectable, Logger } from '@nestjs/common';
import { REQUEST } from '@nestjs/core'; import { REQUEST } from '@nestjs/core';
import { import {
Account, Account,
@ -558,9 +563,17 @@ export class PortfolioService {
const cashSymbolProfiles = this.getCashSymbolProfiles(cashDetails); const cashSymbolProfiles = this.getCashSymbolProfiles(cashDetails);
symbolProfiles.push(...cashSymbolProfiles); symbolProfiles.push(...cashSymbolProfiles);
const symbolProfileMap: { [symbol: string]: EnhancedSymbolProfile } = {}; const symbolProfileMap: {
[assetProfileIdentifier: string]: EnhancedSymbolProfile;
} = {};
for (const symbolProfile of symbolProfiles) { for (const symbolProfile of symbolProfiles) {
symbolProfileMap[symbolProfile.symbol] = symbolProfile; symbolProfileMap[
getAssetProfileIdentifier({
dataSource: symbolProfile.dataSource,
symbol: symbolProfile.symbol
})
] = symbolProfile;
} }
const portfolioItemsNow: { [symbol: string]: TimelinePosition } = {}; const portfolioItemsNow: { [symbol: string]: TimelinePosition } = {};
@ -571,6 +584,7 @@ export class PortfolioService {
for (const { for (const {
activitiesCount, activitiesCount,
currency, currency,
dataSource,
dateOfFirstActivity, dateOfFirstActivity,
dividend, dividend,
grossPerformance, grossPerformance,
@ -600,7 +614,17 @@ export class PortfolioService {
} }
} }
const assetProfile = symbolProfileMap[symbol]; const assetProfile =
symbolProfileMap[getAssetProfileIdentifier({ dataSource, symbol })];
if (!assetProfile) {
Logger.warn(
`Asset profile not found for ${symbol} (${dataSource})`,
'PortfolioService'
);
continue;
}
let markets: PortfolioPosition['markets']; let markets: PortfolioPosition['markets'];
let marketsAdvanced: PortfolioPosition['marketsAdvanced']; let marketsAdvanced: PortfolioPosition['marketsAdvanced'];

4
apps/api/src/services/data-provider/data-provider.service.ts

@ -82,6 +82,7 @@ export class DataProviderService implements OnModuleInit {
return false; return false;
} }
// TODO: Change symbol in response to assetProfileIdentifier
public async getAssetProfiles(items: AssetProfileIdentifier[]): Promise<{ public async getAssetProfiles(items: AssetProfileIdentifier[]): Promise<{
[symbol: string]: Partial<SymbolProfile>; [symbol: string]: Partial<SymbolProfile>;
}> { }> {
@ -330,6 +331,7 @@ export class DataProviderService implements OnModuleInit {
}); });
} }
// TODO: Change symbol in response to assetProfileIdentifier
public async getHistorical( public async getHistorical(
aItems: AssetProfileIdentifier[], aItems: AssetProfileIdentifier[],
aGranularity: Granularity = 'month', aGranularity: Granularity = 'month',
@ -395,6 +397,7 @@ export class DataProviderService implements OnModuleInit {
} }
} }
// TODO: Change symbol in response to assetProfileIdentifier
public async getHistoricalRaw({ public async getHistoricalRaw({
assetProfileIdentifiers, assetProfileIdentifiers,
from, from,
@ -508,6 +511,7 @@ export class DataProviderService implements OnModuleInit {
return result; return result;
} }
// TODO: Change symbol in response to assetProfileIdentifier
public async getQuotes({ public async getQuotes({
items, items,
requestTimeout, requestTimeout,

Loading…
Cancel
Save