Bugfix/fix cash position in user currency (#1433)
* Initialize cash positions with user currency * Update changelog
This commit is contained in:
parent
693ff9d3ea
commit
33fd1282e5
@ -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
|
- 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`)
|
- 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
|
## 1.209.0 - 05.11.2022
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -31,6 +31,7 @@ import {
|
|||||||
HistoricalDataItem,
|
HistoricalDataItem,
|
||||||
PortfolioDetails,
|
PortfolioDetails,
|
||||||
PortfolioPerformanceResponse,
|
PortfolioPerformanceResponse,
|
||||||
|
PortfolioPosition,
|
||||||
PortfolioReport,
|
PortfolioReport,
|
||||||
PortfolioSummary,
|
PortfolioSummary,
|
||||||
Position,
|
Position,
|
||||||
@ -1109,7 +1110,12 @@ export class PortfolioService {
|
|||||||
value: Big;
|
value: Big;
|
||||||
userCurrency: string;
|
userCurrency: string;
|
||||||
}) {
|
}) {
|
||||||
const cashPositions: PortfolioDetails['holdings'] = {};
|
const cashPositions: PortfolioDetails['holdings'] = {
|
||||||
|
[userCurrency]: this.getInitialCashPosition({
|
||||||
|
balance: 0,
|
||||||
|
currency: userCurrency
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
for (const account of cashDetails.accounts) {
|
for (const account of cashDetails.accounts) {
|
||||||
const convertedBalance = this.exchangeRateDataService.toCurrency(
|
const convertedBalance = this.exchangeRateDataService.toCurrency(
|
||||||
@ -1126,28 +1132,10 @@ export class PortfolioService {
|
|||||||
cashPositions[account.currency].investment += convertedBalance;
|
cashPositions[account.currency].investment += convertedBalance;
|
||||||
cashPositions[account.currency].value += convertedBalance;
|
cashPositions[account.currency].value += convertedBalance;
|
||||||
} else {
|
} else {
|
||||||
cashPositions[account.currency] = {
|
cashPositions[account.currency] = this.getInitialCashPosition({
|
||||||
allocationCurrent: 0,
|
balance: convertedBalance,
|
||||||
allocationInvestment: 0,
|
currency: account.currency
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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)) {
|
private getItems(orders: OrderWithAccount[], date = new Date(0)) {
|
||||||
return orders
|
return orders
|
||||||
.filter((order) => {
|
.filter((order) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user