Browse Source

resolve comments

pull/4660/head
KenTandrian 4 months ago
parent
commit
c05ca5d473
  1. 30
      apps/api/src/app/portfolio/portfolio.service.ts

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

@ -24,7 +24,6 @@ import { BenchmarkService } from '@ghostfolio/api/services/benchmark/benchmark.s
import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service';
import { ImpersonationService } from '@ghostfolio/api/services/impersonation/impersonation.service'; import { ImpersonationService } from '@ghostfolio/api/services/impersonation/impersonation.service';
import { MarketDataService } from '@ghostfolio/api/services/market-data/market-data.service';
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile/symbol-profile.service'; import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile/symbol-profile.service';
import { import {
getAnnualizedPerformancePercent, getAnnualizedPerformancePercent,
@ -107,7 +106,6 @@ export class PortfolioService {
private readonly dataProviderService: DataProviderService, private readonly dataProviderService: DataProviderService,
private readonly exchangeRateDataService: ExchangeRateDataService, private readonly exchangeRateDataService: ExchangeRateDataService,
private readonly impersonationService: ImpersonationService, private readonly impersonationService: ImpersonationService,
private readonly marketDataService: MarketDataService,
private readonly orderService: OrderService, private readonly orderService: OrderService,
@Inject(REQUEST) private readonly request: RequestWithUser, @Inject(REQUEST) private readonly request: RequestWithUser,
private readonly rulesService: RulesService, private readonly rulesService: RulesService,
@ -682,11 +680,6 @@ export class PortfolioService {
}; };
} }
const allTimeHigh = await this.marketDataService.getMax({
dataSource: aDataSource,
symbol: aSymbol
});
const [SymbolProfile] = await this.symbolProfileService.getSymbolProfiles([ const [SymbolProfile] = await this.symbolProfileService.getSymbolProfiles([
{ dataSource: aDataSource, symbol: aSymbol } { dataSource: aDataSource, symbol: aSymbol }
]); ]);
@ -762,6 +755,10 @@ export class PortfolioService {
activitiesOfHolding[0].unitPriceInAssetProfileCurrency, activitiesOfHolding[0].unitPriceInAssetProfileCurrency,
marketPrice marketPrice
); );
let marketPriceMaxDate =
marketPrice > activitiesOfHolding[0].unitPriceInAssetProfileCurrency
? new Date()
: activitiesOfHolding[0].date;
let marketPriceMin = Math.min( let marketPriceMin = Math.min(
activitiesOfHolding[0].unitPriceInAssetProfileCurrency, activitiesOfHolding[0].unitPriceInAssetProfileCurrency,
marketPrice marketPrice
@ -803,7 +800,10 @@ export class PortfolioService {
quantity: currentQuantity quantity: currentQuantity
}); });
marketPriceMax = Math.max(marketPrice ?? 0, marketPriceMax); if (marketPrice > marketPriceMax) {
marketPriceMax = marketPrice;
marketPriceMaxDate = parseISO(date);
}
marketPriceMin = Math.min( marketPriceMin = Math.min(
marketPrice ?? Number.MAX_SAFE_INTEGER, marketPrice ?? Number.MAX_SAFE_INTEGER,
marketPriceMin marketPriceMin
@ -821,7 +821,7 @@ export class PortfolioService {
const performancePercent = const performancePercent =
this.benchmarkService.calculateChangeInPercentage( this.benchmarkService.calculateChangeInPercentage(
allTimeHigh?.marketPrice, marketPriceMax,
marketPrice marketPrice
); );
@ -865,7 +865,7 @@ export class PortfolioService {
performances: { performances: {
allTimeHigh: { allTimeHigh: {
performancePercent, performancePercent,
date: allTimeHigh?.date date: marketPriceMaxDate
} }
}, },
quantity: quantity.toNumber(), quantity: quantity.toNumber(),
@ -907,6 +907,7 @@ export class PortfolioService {
const historicalDataArray: HistoricalDataItem[] = []; const historicalDataArray: HistoricalDataItem[] = [];
let marketPriceMax = marketPrice; let marketPriceMax = marketPrice;
let marketPriceMaxDate = new Date();
let marketPriceMin = marketPrice; let marketPriceMin = marketPrice;
for (const [date, { marketPrice }] of Object.entries( for (const [date, { marketPrice }] of Object.entries(
@ -917,7 +918,10 @@ export class PortfolioService {
value: marketPrice value: marketPrice
}); });
marketPriceMax = Math.max(marketPrice ?? 0, marketPriceMax); if (marketPrice > marketPriceMax) {
marketPriceMax = marketPrice;
marketPriceMaxDate = parseISO(date);
}
marketPriceMin = Math.min( marketPriceMin = Math.min(
marketPrice ?? Number.MAX_SAFE_INTEGER, marketPrice ?? Number.MAX_SAFE_INTEGER,
marketPriceMin marketPriceMin
@ -926,7 +930,7 @@ export class PortfolioService {
const performancePercent = const performancePercent =
this.benchmarkService.calculateChangeInPercentage( this.benchmarkService.calculateChangeInPercentage(
allTimeHigh?.marketPrice, marketPriceMax,
marketPrice marketPrice
); );
@ -956,7 +960,7 @@ export class PortfolioService {
performances: { performances: {
allTimeHigh: { allTimeHigh: {
performancePercent, performancePercent,
date: allTimeHigh?.date date: marketPriceMaxDate
} }
}, },
quantity: 0, quantity: 0,

Loading…
Cancel
Save