Feature/reuse advanced markets calculation in portfolio details endpoint (#3884)

pull/3886/head
Thomas Kaul 2 weeks ago committed by GitHub
parent f0f67cdacb
commit bce18f7261
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -98,15 +98,22 @@ export class PortfolioController {
filterByTags filterByTags
}); });
const { accounts, hasErrors, holdings, markets, platforms, summary } = const {
await this.portfolioService.getDetails({ accounts,
dateRange, hasErrors,
filters, holdings,
impersonationId, markets,
withMarkets, marketsAdvanced,
userId: this.request.user.id, platforms,
withSummary: true summary
}); } = await this.portfolioService.getDetails({
dateRange,
filters,
impersonationId,
withMarkets,
userId: this.request.user.id,
withSummary: true
});
if (hasErrors || hasNotDefinedValuesInObject(holdings)) { if (hasErrors || hasNotDefinedValuesInObject(holdings)) {
hasError = true; hasError = true;
@ -168,6 +175,9 @@ export class PortfolioController {
Object.values(markets).forEach((market) => { Object.values(markets).forEach((market) => {
delete market.valueInBaseCurrency; delete market.valueInBaseCurrency;
}); });
Object.values(marketsAdvanced).forEach((market) => {
delete market.valueInBaseCurrency;
});
portfolioSummary = nullifyValuesInObject(summary, [ portfolioSummary = nullifyValuesInObject(summary, [
'cash', 'cash',
@ -241,6 +251,38 @@ export class PortfolioController {
valueInPercentage: 0 valueInPercentage: 0
} }
}, },
marketsAdvanced: hasDetails
? marketsAdvanced
: {
[UNKNOWN_KEY]: {
id: UNKNOWN_KEY,
valueInPercentage: 0
},
asiaPacific: {
id: 'asiaPacific',
valueInPercentage: 0
},
emergingMarkets: {
id: 'emergingMarkets',
valueInPercentage: 0
},
europe: {
id: 'europe',
valueInPercentage: 0
},
japan: {
id: 'japan',
valueInPercentage: 0
},
northAmerica: {
id: 'northAmerica',
valueInPercentage: 0
},
otherMarkets: {
id: 'otherMarkets',
valueInPercentage: 0
}
},
summary: portfolioSummary summary: portfolioSummary
}; };
} }

@ -302,6 +302,14 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
this.markets = this.portfolioDetails.markets; this.markets = this.portfolioDetails.markets;
Object.values(this.portfolioDetails.marketsAdvanced).forEach(
({ id, valueInBaseCurrency, valueInPercentage }) => {
this.marketsAdvanced[id].value = isNumber(valueInBaseCurrency)
? valueInBaseCurrency
: valueInPercentage;
}
);
for (const [symbol, position] of Object.entries( for (const [symbol, position] of Object.entries(
this.portfolioDetails.holdings this.portfolioDetails.holdings
)) { )) {
@ -332,32 +340,6 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
// Prepare analysis data by continents, countries, holdings and sectors except for liquidity // Prepare analysis data by continents, countries, holdings and sectors except for liquidity
if (position.countries.length > 0) { if (position.countries.length > 0) {
this.marketsAdvanced.asiaPacific.value +=
position.marketsAdvanced.asiaPacific *
(isNumber(position.valueInBaseCurrency)
? position.valueInBaseCurrency
: position.valueInPercentage);
this.marketsAdvanced.emergingMarkets.value +=
position.marketsAdvanced.emergingMarkets *
(isNumber(position.valueInBaseCurrency)
? position.valueInBaseCurrency
: position.valueInPercentage);
this.marketsAdvanced.europe.value +=
position.marketsAdvanced.europe *
(isNumber(position.valueInBaseCurrency)
? position.valueInBaseCurrency
: position.valueInPercentage);
this.marketsAdvanced.japan.value +=
position.marketsAdvanced.japan *
(isNumber(position.valueInBaseCurrency)
? position.valueInBaseCurrency
: position.valueInPercentage);
this.marketsAdvanced.northAmerica.value +=
position.marketsAdvanced.northAmerica *
(isNumber(position.valueInBaseCurrency)
? position.valueInBaseCurrency
: position.valueInPercentage);
for (const country of position.countries) { for (const country of position.countries) {
const { code, continent, name, weight } = country; const { code, continent, name, weight } = country;
@ -407,12 +389,6 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
) )
? this.portfolioDetails.holdings[symbol].valueInBaseCurrency ? this.portfolioDetails.holdings[symbol].valueInBaseCurrency
: this.portfolioDetails.holdings[symbol].valueInPercentage; : this.portfolioDetails.holdings[symbol].valueInPercentage;
this.marketsAdvanced[UNKNOWN_KEY].value += isNumber(
position.valueInBaseCurrency
)
? this.portfolioDetails.holdings[symbol].valueInBaseCurrency
: this.portfolioDetails.holdings[symbol].valueInPercentage;
} }
if (position.holdings.length > 0) { if (position.holdings.length > 0) {

@ -25,7 +25,7 @@ export interface PortfolioDetails {
marketsAdvanced?: { marketsAdvanced?: {
[key in MarketAdvanced]: { [key in MarketAdvanced]: {
id: MarketAdvanced; id: MarketAdvanced;
valueInBaseCurrency: number; valueInBaseCurrency?: number;
valueInPercentage: number; valueInPercentage: number;
}; };
}; };

Loading…
Cancel
Save