Browse Source

Refactor current to valueInBaseCurrency

pull/1914/head
Thomas 2 years ago
parent
commit
8f2a44a75d
  1. 4
      apps/api/src/app/portfolio/portfolio.controller.ts
  2. 21
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 2
      apps/api/src/models/rules/account-cluster-risk/current-investment.ts
  4. 4
      apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts
  5. 2
      libs/common/src/lib/interfaces/portfolio-details.interface.ts

4
apps/api/src/app/portfolio/portfolio.controller.ts

@ -136,8 +136,8 @@ export class PortfolioController {
portfolioPosition.value / totalValue;
}
for (const [name, { current }] of Object.entries(accounts)) {
accounts[name].current = current / totalValue;
for (const [name, { valueInBaseCurrency }] of Object.entries(accounts)) {
accounts[name].valueInBaseCurrency = valueInBaseCurrency / totalValue;
}
}

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

@ -146,7 +146,8 @@ export class PortfolioService {
}
}
const valueInBaseCurrency = details.accounts[account.id]?.current ?? 0;
const valueInBaseCurrency =
details.accounts[account.id]?.valueInBaseCurrency ?? 0;
const result = {
...account,
@ -615,8 +616,8 @@ export class PortfolioService {
accounts[UNKNOWN_KEY] = {
balance: 0,
currency: userCurrency,
current: emergencyFundInCash,
name: UNKNOWN_KEY
name: UNKNOWN_KEY,
valueInBaseCurrency: emergencyFundInCash
};
holdings[userCurrency] = {
@ -1758,12 +1759,12 @@ export class PortfolioService {
accounts[account.id] = {
balance: account.balance,
currency: account.currency,
current: this.exchangeRateDataService.toCurrency(
name: account.name,
valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
account.balance,
account.currency,
userCurrency
),
name: account.name
)
};
for (const order of ordersByAccount) {
@ -1777,15 +1778,15 @@ export class PortfolioService {
currentValueOfSymbolInBaseCurrency *= -1;
}
if (accounts[order.Account?.id || UNKNOWN_KEY]?.current) {
accounts[order.Account?.id || UNKNOWN_KEY].current +=
if (accounts[order.Account?.id || UNKNOWN_KEY]?.valueInBaseCurrency) {
accounts[order.Account?.id || UNKNOWN_KEY].valueInBaseCurrency +=
currentValueOfSymbolInBaseCurrency;
} else {
accounts[order.Account?.id || UNKNOWN_KEY] = {
balance: 0,
currency: order.Account?.currency,
current: currentValueOfSymbolInBaseCurrency,
name: account.name
name: account.name,
valueInBaseCurrency: currentValueOfSymbolInBaseCurrency
};
}
}

2
apps/api/src/models/rules/account-cluster-risk/current-investment.ts

@ -28,7 +28,7 @@ export class AccountClusterRiskCurrentInvestment extends Rule<Settings> {
for (const [accountId, account] of Object.entries(this.accounts)) {
accounts[accountId] = {
name: account.name,
investment: account.current
investment: account.valueInBaseCurrency
};
}

4
apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts

@ -249,13 +249,13 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
public initializeAnalysisData() {
this.initialize();
for (const [id, { current, name }] of Object.entries(
for (const [id, { name, valueInBaseCurrency }] of Object.entries(
this.portfolioDetails.accounts
)) {
this.accounts[id] = {
id,
name,
value: current
value: valueInBaseCurrency
};
}

2
libs/common/src/lib/interfaces/portfolio-details.interface.ts

@ -8,8 +8,8 @@ export interface PortfolioDetails {
[id: string]: {
balance: number;
currency: string;
current: number;
name: string;
valueInBaseCurrency: number;
};
};
filteredValueInBaseCurrency?: number;

Loading…
Cancel
Save