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/6574/merge
Thomas Kaul 21 hours ago committed by GitHub
parent 5fd9eff8a7
commit f82fbcfc58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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/),
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
### Added

@ -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 { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.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 {
AssetProfileIdentifier,
DataProviderInfo,
@ -114,8 +117,8 @@ export class CurrentRateService {
errors: quoteErrors.map(({ dataSource, symbol }) => {
return { dataSource, symbol };
}),
values: uniqBy(values, ({ date, symbol }) => {
return `${date}-${symbol}`;
values: uniqBy(values, ({ dataSource, date, symbol }) => {
return `${date}-${getAssetProfileIdentifier({ dataSource, symbol })}`;
})
};
@ -124,7 +127,11 @@ export class CurrentRateService {
try {
// If missing quote, fallback to the latest available historical market price
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) {
@ -147,7 +154,11 @@ export class CurrentRateService {
const [latestValue] = response.values
.filter((currentValue) => {
return currentValue.symbol === symbol && currentValue.marketPrice;
return (
currentValue.dataSource === dataSource &&
currentValue.marketPrice &&
currentValue.symbol === symbol
);
})
.sort((a, b) => {
if (a.date < b.date) {

@ -36,7 +36,12 @@ import {
TAG_ID_EXCLUDE_FROM_ANALYSIS,
UNKNOWN_KEY
} from '@ghostfolio/common/config';
import { DATE_FORMAT, getSum, parseDate } from '@ghostfolio/common/helper';
import {
DATE_FORMAT,
getAssetProfileIdentifier,
getSum,
parseDate
} from '@ghostfolio/common/helper';
import {
AccountsResponse,
Activity,
@ -64,7 +69,7 @@ import {
} from '@ghostfolio/common/types';
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 {
Account,
@ -558,9 +563,17 @@ export class PortfolioService {
const cashSymbolProfiles = this.getCashSymbolProfiles(cashDetails);
symbolProfiles.push(...cashSymbolProfiles);
const symbolProfileMap: { [symbol: string]: EnhancedSymbolProfile } = {};
const symbolProfileMap: {
[assetProfileIdentifier: string]: EnhancedSymbolProfile;
} = {};
for (const symbolProfile of symbolProfiles) {
symbolProfileMap[symbolProfile.symbol] = symbolProfile;
symbolProfileMap[
getAssetProfileIdentifier({
dataSource: symbolProfile.dataSource,
symbol: symbolProfile.symbol
})
] = symbolProfile;
}
const portfolioItemsNow: { [symbol: string]: TimelinePosition } = {};
@ -571,6 +584,7 @@ export class PortfolioService {
for (const {
activitiesCount,
currency,
dataSource,
dateOfFirstActivity,
dividend,
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 marketsAdvanced: PortfolioPosition['marketsAdvanced'];

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

Loading…
Cancel
Save