Feature/reuse advanced markets calculation in portfolio details endpoint (#3884)
This commit is contained in:
parent
f0f67cdacb
commit
bce18f7261
@ -98,15 +98,22 @@ export class PortfolioController {
|
||||
filterByTags
|
||||
});
|
||||
|
||||
const { accounts, hasErrors, holdings, markets, platforms, summary } =
|
||||
await this.portfolioService.getDetails({
|
||||
dateRange,
|
||||
filters,
|
||||
impersonationId,
|
||||
withMarkets,
|
||||
userId: this.request.user.id,
|
||||
withSummary: true
|
||||
});
|
||||
const {
|
||||
accounts,
|
||||
hasErrors,
|
||||
holdings,
|
||||
markets,
|
||||
marketsAdvanced,
|
||||
platforms,
|
||||
summary
|
||||
} = await this.portfolioService.getDetails({
|
||||
dateRange,
|
||||
filters,
|
||||
impersonationId,
|
||||
withMarkets,
|
||||
userId: this.request.user.id,
|
||||
withSummary: true
|
||||
});
|
||||
|
||||
if (hasErrors || hasNotDefinedValuesInObject(holdings)) {
|
||||
hasError = true;
|
||||
@ -168,6 +175,9 @@ export class PortfolioController {
|
||||
Object.values(markets).forEach((market) => {
|
||||
delete market.valueInBaseCurrency;
|
||||
});
|
||||
Object.values(marketsAdvanced).forEach((market) => {
|
||||
delete market.valueInBaseCurrency;
|
||||
});
|
||||
|
||||
portfolioSummary = nullifyValuesInObject(summary, [
|
||||
'cash',
|
||||
@ -241,6 +251,38 @@ export class PortfolioController {
|
||||
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
|
||||
};
|
||||
}
|
||||
|
@ -302,6 +302,14 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
|
||||
|
||||
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(
|
||||
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
|
||||
|
||||
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) {
|
||||
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].valueInPercentage;
|
||||
|
||||
this.marketsAdvanced[UNKNOWN_KEY].value += isNumber(
|
||||
position.valueInBaseCurrency
|
||||
)
|
||||
? this.portfolioDetails.holdings[symbol].valueInBaseCurrency
|
||||
: this.portfolioDetails.holdings[symbol].valueInPercentage;
|
||||
}
|
||||
|
||||
if (position.holdings.length > 0) {
|
||||
|
@ -25,7 +25,7 @@ export interface PortfolioDetails {
|
||||
marketsAdvanced?: {
|
||||
[key in MarketAdvanced]: {
|
||||
id: MarketAdvanced;
|
||||
valueInBaseCurrency: number;
|
||||
valueInBaseCurrency?: number;
|
||||
valueInPercentage: number;
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user