Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Bugfix/fix big.js exception in report endpoint (#1586)

Thomas Kaula7e5a316be75
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ce50bb0679..5eb0f323ce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved the form of the import dividends dialog (disable while loading)
- Removed the deprecated `~` in _Sass_ imports
+### Fixed
+
+- Fixed an exception in the _X-ray_ section
+
## 1.225.0 - 2023-01-07
### Added
diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts
index 37fae84d72..f752010b35 100644
--- a/apps/api/src/app/portfolio/portfolio.service.ts
+++ b/apps/api/src/app/portfolio/portfolio.service.ts
@@ -910,12 +910,14 @@ export class PortfolioService {
const positions = currentPositions.positions.filter(
(item) => !item.quantity.eq(0)
);
+
const dataGatheringItem = positions.map((position) => {
return {
dataSource: position.dataSource,
symbol: position.symbol
};
});
+
const symbols = positions.map((position) => position.symbol);
const [dataProviderResponses, symbolProfiles] = await Promise.all([
@@ -1103,16 +1105,23 @@ export class PortfolioService {
portfolioStart
);
+ const positions = currentPositions.positions.filter(
+ (item) => !item.quantity.eq(0)
+ );
+
const portfolioItemsNow: { [symbol: string]: TimelinePosition } = {};
- for (const position of currentPositions.positions) {
+
+ for (const position of positions) {
portfolioItemsNow[position.symbol] = position;
}
+
const accounts = await this.getValueOfAccounts({
orders,
portfolioItemsNow,
- userId,
- userCurrency
+ userCurrency,
+ userId
});
+
return {
rules: {
accountClusterRisk: await this.rulesService.evaluate(
@@ -1136,19 +1145,19 @@ export class PortfolioService {
[
new CurrencyClusterRiskBaseCurrencyInitialInvestment(
this.exchangeRateDataService,
- currentPositions
+ positions
),
new CurrencyClusterRiskBaseCurrencyCurrentInvestment(
this.exchangeRateDataService,
- currentPositions
+ positions
),
new CurrencyClusterRiskInitialInvestment(
this.exchangeRateDataService,
- currentPositions
+ positions
),
new CurrencyClusterRiskCurrentInvestment(
this.exchangeRateDataService,
- currentPositions
+ positions
)
],
<UserSettings>this.request.user.Settings.settings
@@ -1682,7 +1691,7 @@ export class PortfolioService {
for (const order of ordersByAccount) {
let currentValueOfSymbolInBaseCurrency =
order.quantity *
- portfolioItemsNow[order.SymbolProfile.symbol].marketPrice;
+ portfolioItemsNow[order.SymbolProfile.symbol]?.marketPrice ?? 0;
let originalValueOfSymbolInBaseCurrency =
this.exchangeRateDataService.toCurrency(
order.quantity * order.unitPrice,
diff --git a/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts
index 5f1f4cf93d..1d584b04f4 100644
--- a/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts
+++ b/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts
@@ -1,14 +1,13 @@
-import { CurrentPositions } from '@ghostfolio/api/app/portfolio/interfaces/current-positions.interface';
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
-import { UserSettings } from '@ghostfolio/common/interfaces';
+import { TimelinePosition, UserSettings } from '@ghostfolio/common/interfaces';
import { Rule } from '../../rule';
export class CurrencyClusterRiskBaseCurrencyCurrentInvestment extends Rule<Settings> {
public constructor(
protected exchangeRateDataService: ExchangeRateDataService,
- private currentPositions: CurrentPositions
+ private positions: TimelinePosition[]
) {
super(exchangeRateDataService, {
name: 'Current Investment: Base Currency'
@@ -17,7 +16,7 @@ export class CurrencyClusterRiskBaseCurrencyCurrentInvestment extends Rule<Setti
public evaluate(ruleSettings: Settings) {
const positionsGroupedByCurrency = this.groupCurrentPositionsByAttribute(
- this.currentPositions.positions,
+ this.positions,
'currency',
ruleSettings.baseCurrency
);
diff --git a/apps/api/src/models/rules/currency-cluster-risk/base-currency-initial-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/base-currency-initial-investment.ts
index 1d43f56197..c8a3c8b262 100644
--- a/apps/api/src/models/rules/currency-cluster-risk/base-currency-initial-investment.ts
+++ b/apps/api/src/models/rules/currency-cluster-risk/base-currency-initial-investment.ts
@@ -1,14 +1,13 @@
-import { CurrentPositions } from '@ghostfolio/api/app/portfolio/interfaces/current-positions.interface';
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
-import { UserSettings } from '@ghostfolio/common/interfaces';
+import { TimelinePosition, UserSettings } from '@ghostfolio/common/interfaces';
import { Rule } from '../../rule';
export class CurrencyClusterRiskBaseCurrencyInitialInvestment extends Rule<Settings> {
public constructor(
protected exchangeRateDataService: ExchangeRateDataService,
- private currentPositions: CurrentPositions
+ private positions: TimelinePosition[]
) {
super(exchangeRateDataService, {
name: 'Initial Investment: Base Currency'
@@ -17,7 +16,7 @@ export class CurrencyClusterRiskBaseCurrencyInitialInvestment extends Rule<Setti
public evaluate(ruleSettings: Settings) {
const positionsGroupedByCurrency = this.groupCurrentPositionsByAttribute(
- this.currentPositions.positions,
+ this.positions,
'currency',
ruleSettings.baseCurrency
);
diff --git a/apps/api/src/models/rules/currency-cluster-risk/current-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/current-investment.ts
index c233ffc9cf..402eddf3f4 100644
--- a/apps/api/src/models/rules/currency-cluster-risk/current-investment.ts
+++ b/apps/api/src/models/rules/currency-cluster-risk/current-investment.ts
@@ -1,14 +1,13 @@
-import { CurrentPositions } from '@ghostfolio/api/app/portfolio/interfaces/current-positions.interface';
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
-import { UserSettings } from '@ghostfolio/common/interfaces';
+import { TimelinePosition, UserSettings } from '@ghostfolio/common/interfaces';
import { Rule } from '../../rule';
export class CurrencyClusterRiskCurrentInvestment extends Rule<Settings> {
public constructor(
- public exchangeRateDataService: ExchangeRateDataService,
- private currentPositions: CurrentPositions
+ protected exchangeRateDataService: ExchangeRateDataService,
+ private positions: TimelinePosition[]
) {
super(exchangeRateDataService, {
name: 'Current Investment'
@@ -17,7 +16,7 @@ export class CurrencyClusterRiskCurrentInvestment extends Rule<Settings> {
public evaluate(ruleSettings: Settings) {
const positionsGroupedByCurrency = this.groupCurrentPositionsByAttribute(
- this.currentPositions.positions,
+ this.positions,
'currency',
ruleSettings.baseCurrency
);
diff --git a/apps/api/src/models/rules/currency-cluster-risk/initial-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/initial-investment.ts
index 331074f16e..18477f6f70 100644
--- a/apps/api/src/models/rules/currency-cluster-risk/initial-investment.ts
+++ b/apps/api/src/models/rules/currency-cluster-risk/initial-investment.ts
@@ -1,14 +1,13 @@
-import { CurrentPositions } from '@ghostfolio/api/app/portfolio/interfaces/current-positions.interface';
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
-import { UserSettings } from '@ghostfolio/common/interfaces';
+import { TimelinePosition, UserSettings } from '@ghostfolio/common/interfaces';
import { Rule } from '../../rule';
export class CurrencyClusterRiskInitialInvestment extends Rule<Settings> {
public constructor(
protected exchangeRateDataService: ExchangeRateDataService,
- private currentPositions: CurrentPositions
+ private positions: TimelinePosition[]
) {
super(exchangeRateDataService, {
name: 'Initial Investment'
@@ -17,7 +16,7 @@ export class CurrencyClusterRiskInitialInvestment extends Rule<Settings> {
public evaluate(ruleSettings: Settings) {
const positionsGroupedByCurrency = this.groupCurrentPositionsByAttribute(
- this.currentPositions.positions,
+ this.positions,
'currency',
ruleSettings.baseCurrency
);