Skip to content

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

Feature/start eliminating data source from order (#622)

Thomas Kaul7df53896f374
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2cceba33c9..ef67e69f15 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
+### Changed
+
+- Start eliminating `dataSource` from activity
+
### Fixed
- Fixed the support for multiple accounts with the same name
diff --git a/apps/api/src/app/portfolio/current-rate.service.spec.ts b/apps/api/src/app/portfolio/current-rate.service.spec.ts
index bb9aa78b60..ca45483e12 100644
--- a/apps/api/src/app/portfolio/current-rate.service.spec.ts
+++ b/apps/api/src/app/portfolio/current-rate.service.spec.ts
@@ -85,19 +85,6 @@ describe('CurrentRateService', () => {
);
});
- it('getValue', async () => {
- expect(
- await currentRateService.getValue({
- currency: 'USD',
- date: new Date(Date.UTC(2020, 0, 1, 0, 0, 0)),
- symbol: 'AMZN',
- userCurrency: 'CHF'
- })
- ).toMatchObject({
- marketPrice: 1847.839966
- });
- });
-
it('getValues', async () => {
expect(
await currentRateService.getValues({
diff --git a/apps/api/src/app/portfolio/current-rate.service.ts b/apps/api/src/app/portfolio/current-rate.service.ts
index 3c7a6bde5f..fac0418378 100644
--- a/apps/api/src/app/portfolio/current-rate.service.ts
+++ b/apps/api/src/app/portfolio/current-rate.service.ts
@@ -7,7 +7,6 @@ import { isBefore, isToday } from 'date-fns';
import { flatten } from 'lodash';
import { GetValueObject } from './interfaces/get-value-object.interface';
-import { GetValueParams } from './interfaces/get-value-params.interface';
import { GetValuesParams } from './interfaces/get-values-params.interface';
@Injectable()
@@ -18,46 +17,6 @@ export class CurrentRateService {
private readonly marketDataService: MarketDataService
) {}
- public async getValue({
- currency,
- date,
- symbol,
- userCurrency
- }: GetValueParams): Promise<GetValueObject> {
- if (isToday(date)) {
- const dataProviderResult = await this.dataProviderService.get([
- {
- symbol,
- dataSource: this.dataProviderService.getPrimaryDataSource()
- }
- ]);
- return {
- symbol,
- date: resetHours(date),
- marketPrice: dataProviderResult?.[symbol]?.marketPrice ?? 0
- };
- }
-
- const marketData = await this.marketDataService.get({
- date,
- symbol
- });
-
- if (marketData) {
- return {
- date: marketData.date,
- marketPrice: this.exchangeRateDataService.toCurrency(
- marketData.marketPrice,
- currency,
- userCurrency
- ),
- symbol: marketData.symbol
- };
- }
-
- throw new Error(`Value not found for ${symbol} at ${resetHours(date)}`);
- }
-
public async getValues({
currencies,
dataGatheringItems,
diff --git a/apps/api/src/app/portfolio/interfaces/get-value-params.interface.ts b/apps/api/src/app/portfolio/interfaces/get-value-params.interface.ts
deleted file mode 100644
index a9b934271d..0000000000
--- a/apps/api/src/app/portfolio/interfaces/get-value-params.interface.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-export interface GetValueParams {
- currency: string;
- date: Date;
- symbol: string;
- userCurrency: string;
-}
diff --git a/apps/api/src/app/portfolio/portfolio-calculator.spec.ts b/apps/api/src/app/portfolio/portfolio-calculator.spec.ts
index 1de2a1d158..74c45f026b 100644
--- a/apps/api/src/app/portfolio/portfolio-calculator.spec.ts
+++ b/apps/api/src/app/portfolio/portfolio-calculator.spec.ts
@@ -1,17 +1,9 @@
import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper';
import { DataSource } from '@prisma/client';
import Big from 'big.js';
-import {
- addDays,
- differenceInCalendarDays,
- endOfDay,
- format,
- isBefore,
- isSameDay
-} from 'date-fns';
+import { addDays, endOfDay, format, isBefore, isSameDay } from 'date-fns';
import { CurrentRateService } from './current-rate.service';
-import { GetValueParams } from './interfaces/get-value-params.interface';
import { GetValuesParams } from './interfaces/get-values-params.interface';
import { PortfolioOrder } from './interfaces/portfolio-order.interface';
import { TimelinePeriod } from './interfaces/timeline-period.interface';
@@ -275,9 +267,6 @@ jest.mock('./current-rate.service', () => {
// eslint-disable-next-line @typescript-eslint/naming-convention
CurrentRateService: jest.fn().mockImplementation(() => {
return {
- getValue: ({ date, symbol }: GetValueParams) => {
- return Promise.resolve(mockGetValue(symbol, date));
- },
getValues: ({ dataGatheringItems, dateQuery }: GetValuesParams) => {
const result = [];
if (dateQuery.lt) {
diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts
index 9ed19810f3..15170dcef2 100644
--- a/apps/api/src/app/portfolio/portfolio.service.ts
+++ b/apps/api/src/app/portfolio/portfolio.service.ts
@@ -428,7 +428,7 @@ export class PortfolioService {
})
.map((order) => ({
currency: order.currency,
- dataSource: order.dataSource,
+ dataSource: order.SymbolProfile?.dataSource ?? order.dataSource,
date: format(order.date, DATE_FORMAT),
fee: new Big(order.fee),
name: order.SymbolProfile?.name,
@@ -1038,7 +1038,7 @@ export class PortfolioService {
const userCurrency = this.request.user?.Settings?.currency ?? baseCurrency;
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({
currency: order.currency,
- dataSource: order.dataSource,
+ dataSource: order.SymbolProfile?.dataSource ?? order.dataSource,
date: format(order.date, DATE_FORMAT),
fee: new Big(
this.exchangeRateDataService.toCurrency(