Browse Source

Fix exception with missing marketPrice

pull/1586/head
Thomas 3 years ago
parent
commit
83e9a6a6c7
  1. 54
      apps/api/src/app/portfolio/portfolio-calculator.ts
  2. 2
      apps/api/src/app/portfolio/portfolio.service.ts

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

@ -422,33 +422,35 @@ export class PortfolioCalculator {
symbol: item.symbol symbol: item.symbol
}); });
hasAnySymbolMetricsErrors = hasAnySymbolMetricsErrors || hasErrors; if (item.quantity.gt(0)) {
initialValues[item.symbol] = initialValue; hasAnySymbolMetricsErrors = hasAnySymbolMetricsErrors || hasErrors;
initialValues[item.symbol] = initialValue;
positions.push({
averagePrice: item.quantity.eq(0) positions.push({
? new Big(0) averagePrice: item.quantity.eq(0)
: item.investment.div(item.quantity), ? new Big(0)
currency: item.currency, : item.investment.div(item.quantity),
dataSource: item.dataSource, currency: item.currency,
firstBuyDate: item.firstBuyDate, dataSource: item.dataSource,
grossPerformance: !hasErrors ? grossPerformance ?? null : null, firstBuyDate: item.firstBuyDate,
grossPerformancePercentage: !hasErrors grossPerformance: !hasErrors ? grossPerformance ?? null : null,
? grossPerformancePercentage ?? null grossPerformancePercentage: !hasErrors
: null, ? grossPerformancePercentage ?? null
investment: item.investment, : null,
marketPrice: marketValue?.toNumber() ?? null, investment: item.investment,
netPerformance: !hasErrors ? netPerformance ?? null : null, marketPrice: marketValue?.toNumber() ?? null,
netPerformancePercentage: !hasErrors netPerformance: !hasErrors ? netPerformance ?? null : null,
? netPerformancePercentage ?? null netPerformancePercentage: !hasErrors
: null, ? netPerformancePercentage ?? null
quantity: item.quantity, : null,
symbol: item.symbol, quantity: item.quantity,
transactionCount: item.transactionCount symbol: item.symbol,
}); transactionCount: item.transactionCount
});
if (hasErrors) { if (hasErrors) {
errors.push({ dataSource: item.dataSource, symbol: item.symbol }); errors.push({ dataSource: item.dataSource, symbol: item.symbol });
}
} }
} }

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

@ -1682,7 +1682,7 @@ export class PortfolioService {
for (const order of ordersByAccount) { for (const order of ordersByAccount) {
let currentValueOfSymbolInBaseCurrency = let currentValueOfSymbolInBaseCurrency =
order.quantity * order.quantity *
portfolioItemsNow[order.SymbolProfile.symbol].marketPrice; portfolioItemsNow[order.SymbolProfile.symbol]?.marketPrice ?? 0;
let originalValueOfSymbolInBaseCurrency = let originalValueOfSymbolInBaseCurrency =
this.exchangeRateDataService.toCurrency( this.exchangeRateDataService.toCurrency(
order.quantity * order.unitPrice, order.quantity * order.unitPrice,

Loading…
Cancel
Save