Browse Source

Refactoring

pull/2834/head
Thomas Kaul 2 years ago
parent
commit
28064becf4
  1. 11
      apps/api/src/app/benchmark/benchmark.service.ts
  2. 18
      apps/api/src/app/portfolio/portfolio-calculator.ts

11
apps/api/src/app/benchmark/benchmark.service.ts

@ -247,17 +247,6 @@ export class BenchmarkService {
format(startDate, DATE_FORMAT)
];
if (!exchangeRateAtStartDate) {
Logger.error(
`No exchange rate has been found for ${
currentSymbolItem.currency
}${userCurrency} at ${format(startDate, DATE_FORMAT)}`,
'BenchmarkService'
);
return { marketData };
}
const marketPriceAtStartDate = marketDataItems?.find(({ date }) => {
return isSameDay(date, startDate);
})?.marketPrice;

18
apps/api/src/app/portfolio/portfolio-calculator.ts

@ -504,10 +504,13 @@ export class PortfolioCalculator {
dates.map((date) => {
return date.getTime();
})
).map((timestamp) => {
return new Date(timestamp);
});
dates.sort((a, b) => a.getTime() - b.getTime());
)
.map((timestamp) => {
return new Date(timestamp);
})
.sort((a, b) => {
return a.getTime() - b.getTime();
});
let exchangeRatesByCurrency =
await this.exchangeRateDataService.getExchangeRatesByCurrency({
@ -1328,13 +1331,6 @@ export class PortfolioCalculator {
const exchangeRateAtOrderDate = exchangeRates[order.date];
if (!exchangeRateAtOrderDate) {
Logger.error(
`No exchange rate has been found for ${DEFAULT_CURRENCY}${order.currency} at ${order.date}`,
'PortfolioCalculator'
);
}
if (order.itemType === 'start') {
// Take the unit price of the order as the market price if there are no
// orders of this symbol before the start date

Loading…
Cancel
Save