Bugfix/fix cash position in user currency (#1433)

* Initialize cash positions with user currency

* Update changelog
pull/1434/head
Thomas Kaul 2 years ago committed by GitHub
parent 693ff9d3ea
commit 33fd1282e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Merged the _FIRE_ calculator and the _X-ray_ section to a single page
- Tightened the validation rule of the base currency environment variable (`BASE_CURRENCY`)
### Fixed
- Fixed an issue in the cash positions calculation
## 1.209.0 - 05.11.2022
### Added

@ -31,6 +31,7 @@ import {
HistoricalDataItem,
PortfolioDetails,
PortfolioPerformanceResponse,
PortfolioPosition,
PortfolioReport,
PortfolioSummary,
Position,
@ -1109,7 +1110,12 @@ export class PortfolioService {
value: Big;
userCurrency: string;
}) {
const cashPositions: PortfolioDetails['holdings'] = {};
const cashPositions: PortfolioDetails['holdings'] = {
[userCurrency]: this.getInitialCashPosition({
balance: 0,
currency: userCurrency
})
};
for (const account of cashDetails.accounts) {
const convertedBalance = this.exchangeRateDataService.toCurrency(
@ -1126,28 +1132,10 @@ export class PortfolioService {
cashPositions[account.currency].investment += convertedBalance;
cashPositions[account.currency].value += convertedBalance;
} else {
cashPositions[account.currency] = {
allocationCurrent: 0,
allocationInvestment: 0,
assetClass: AssetClass.CASH,
assetSubClass: AssetClass.CASH,
countries: [],
currency: account.currency,
dataSource: undefined,
grossPerformance: 0,
grossPerformancePercent: 0,
investment: convertedBalance,
marketPrice: 0,
marketState: 'open',
name: account.currency,
netPerformance: 0,
netPerformancePercent: 0,
quantity: 0,
sectors: [],
symbol: account.currency,
transactionCount: 0,
value: convertedBalance
};
cashPositions[account.currency] = this.getInitialCashPosition({
balance: convertedBalance,
currency: account.currency
});
}
}
@ -1247,6 +1235,37 @@ export class PortfolioService {
);
}
private getInitialCashPosition({
balance,
currency
}: {
balance: number;
currency: string;
}): PortfolioPosition {
return {
currency,
allocationCurrent: 0,
allocationInvestment: 0,
assetClass: AssetClass.CASH,
assetSubClass: AssetClass.CASH,
countries: [],
dataSource: undefined,
grossPerformance: 0,
grossPerformancePercent: 0,
investment: balance,
marketPrice: 0,
marketState: 'open',
name: currency,
netPerformance: 0,
netPerformancePercent: 0,
quantity: 0,
sectors: [],
symbol: currency,
transactionCount: 0,
value: balance
};
}
private getItems(orders: OrderWithAccount[], date = new Date(0)) {
return orders
.filter((order) => {

Loading…
Cancel
Save