Browse Source

Improve error handling

pull/1215/head
Thomas 3 years ago
parent
commit
c221a1d358
  1. 10
      apps/api/src/app/portfolio/portfolio-calculator.ts
  2. 10
      apps/api/src/app/portfolio/portfolio.service.ts

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

@ -432,10 +432,15 @@ export class PortfolioCalculator {
}
}
let minNetPerformance = new Big(0);
let maxNetPerformance = new Big(0);
const timelineInfoInterfaces: TimelineInfoInterface[] = await Promise.all(
timelinePeriodPromises
);
const minNetPerformance = timelineInfoInterfaces
try {
minNetPerformance = timelineInfoInterfaces
.map((timelineInfo) => timelineInfo.minNetPerformance)
.filter((performance) => performance !== null)
.reduce((minPerformance, current) => {
@ -446,7 +451,7 @@ export class PortfolioCalculator {
}
});
const maxNetPerformance = timelineInfoInterfaces
maxNetPerformance = timelineInfoInterfaces
.map((timelineInfo) => timelineInfo.maxNetPerformance)
.filter((performance) => performance !== null)
.reduce((maxPerformance, current) => {
@ -456,6 +461,7 @@ export class PortfolioCalculator {
return current;
}
});
} catch {}
const timelinePeriods = timelineInfoInterfaces.map(
(timelineInfo) => timelineInfo.timelinePeriods

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

@ -327,10 +327,10 @@ export class PortfolioService {
}
let isAllTimeHigh = timelineInfo.maxNetPerformance?.eq(
lastItem?.netPerformance
lastItem?.netPerformance ?? 0
);
let isAllTimeLow = timelineInfo.minNetPerformance?.eq(
lastItem?.netPerformance
lastItem?.netPerformance ?? 0
);
if (isAllTimeHigh && isAllTimeLow) {
isAllTimeHigh = false;
@ -466,7 +466,9 @@ export class PortfolioService {
holdings[item.symbol] = {
markets,
allocationCurrent: value.div(totalValue).toNumber(),
allocationCurrent: totalValue.eq(0)
? 0
: value.div(totalValue).toNumber(),
allocationInvestment: item.investment.div(totalInvestment).toNumber(),
assetClass: symbolProfile.assetClass,
assetSubClass: symbolProfile.assetSubClass,
@ -478,7 +480,7 @@ export class PortfolioService {
item.grossPerformancePercentage?.toNumber() ?? 0,
investment: item.investment.toNumber(),
marketPrice: item.marketPrice,
marketState: dataProviderResponse.marketState,
marketState: dataProviderResponse?.marketState ?? 'delayed',
name: symbolProfile.name,
netPerformance: item.netPerformance?.toNumber() ?? 0,
netPerformancePercent: item.netPerformancePercentage?.toNumber() ?? 0,

Loading…
Cancel
Save