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; portfolioPosition.value / totalValue;
} }
for (const [name, { current }] of Object.entries(accounts)) { for (const [name, { valueInBaseCurrency }] of Object.entries(accounts)) {
accounts[name].current = current / totalValue; 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 = { const result = {
...account, ...account,
@ -615,8 +616,8 @@ export class PortfolioService {
accounts[UNKNOWN_KEY] = { accounts[UNKNOWN_KEY] = {
balance: 0, balance: 0,
currency: userCurrency, currency: userCurrency,
current: emergencyFundInCash, name: UNKNOWN_KEY,
name: UNKNOWN_KEY valueInBaseCurrency: emergencyFundInCash
}; };
holdings[userCurrency] = { holdings[userCurrency] = {
@ -1758,12 +1759,12 @@ export class PortfolioService {
accounts[account.id] = { accounts[account.id] = {
balance: account.balance, balance: account.balance,
currency: account.currency, currency: account.currency,
current: this.exchangeRateDataService.toCurrency( name: account.name,
valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
account.balance, account.balance,
account.currency, account.currency,
userCurrency userCurrency
), )
name: account.name
}; };
for (const order of ordersByAccount) { for (const order of ordersByAccount) {
@ -1777,15 +1778,15 @@ export class PortfolioService {
currentValueOfSymbolInBaseCurrency *= -1; currentValueOfSymbolInBaseCurrency *= -1;
} }
if (accounts[order.Account?.id || UNKNOWN_KEY]?.current) { if (accounts[order.Account?.id || UNKNOWN_KEY]?.valueInBaseCurrency) {
accounts[order.Account?.id || UNKNOWN_KEY].current += accounts[order.Account?.id || UNKNOWN_KEY].valueInBaseCurrency +=
currentValueOfSymbolInBaseCurrency; currentValueOfSymbolInBaseCurrency;
} else { } else {
accounts[order.Account?.id || UNKNOWN_KEY] = { accounts[order.Account?.id || UNKNOWN_KEY] = {
balance: 0, balance: 0,
currency: order.Account?.currency, 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)) { for (const [accountId, account] of Object.entries(this.accounts)) {
accounts[accountId] = { accounts[accountId] = {
name: account.name, 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() { public initializeAnalysisData() {
this.initialize(); this.initialize();
for (const [id, { current, name }] of Object.entries( for (const [id, { name, valueInBaseCurrency }] of Object.entries(
this.portfolioDetails.accounts this.portfolioDetails.accounts
)) { )) {
this.accounts[id] = { this.accounts[id] = {
id, id,
name, name,
value: current value: valueInBaseCurrency
}; };
} }

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

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

Loading…
Cancel
Save