diff --git a/apps/api/src/app/info/info.service.ts b/apps/api/src/app/info/info.service.ts index 9486f1527..c84daab1a 100644 --- a/apps/api/src/app/info/info.service.ts +++ b/apps/api/src/app/info/info.service.ts @@ -1,5 +1,6 @@ import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; +import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { InfoItem } from '@ghostfolio/common/interfaces'; @@ -16,6 +17,7 @@ export class InfoService { public constructor( private readonly configurationService: ConfigurationService, + private readonly dataProviderService: DataProviderService, private readonly exchangeRateDataService: ExchangeRateDataService, private readonly dataGatheringService: DataGatheringService, private readonly jwtService: JwtService, @@ -60,6 +62,7 @@ export class InfoService { currencies: this.exchangeRateDataService.getCurrencies(), demoAuthToken: this.getDemoAuthToken(), lastDataGathering: await this.getLastDataGathering(), + primaryDataSource: this.dataProviderService.getPrimaryDataSource(), statistics: await this.getStatistics(), subscriptions: await this.getSubscriptions() }; diff --git a/apps/api/src/app/portfolio/current-rate.service.ts b/apps/api/src/app/portfolio/current-rate.service.ts index 7f2813c6e..c5dff75f9 100644 --- a/apps/api/src/app/portfolio/current-rate.service.ts +++ b/apps/api/src/app/portfolio/current-rate.service.ts @@ -2,7 +2,6 @@ import { DataProviderService } from '@ghostfolio/api/services/data-provider/data import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { resetHours } from '@ghostfolio/common/helper'; import { Injectable } from '@nestjs/common'; -import { DataSource } from '@prisma/client'; import { isBefore, isToday } from 'date-fns'; import { flatten } from 'lodash'; @@ -27,7 +26,10 @@ export class CurrentRateService { }: GetValueParams): Promise { if (isToday(date)) { const dataProviderResult = await this.dataProviderService.get([ - { symbol, dataSource: DataSource.YAHOO } + { + symbol, + dataSource: this.dataProviderService.getPrimaryDataSource() + } ]); return { symbol, diff --git a/apps/api/src/services/data-provider/data-provider.service.ts b/apps/api/src/services/data-provider/data-provider.service.ts index 11109ed43..efb2a4ec0 100644 --- a/apps/api/src/services/data-provider/data-provider.service.ts +++ b/apps/api/src/services/data-provider/data-provider.service.ts @@ -199,6 +199,10 @@ export class DataProviderService { }; } + public getPrimaryDataSource(): DataSource { + return DataSource[this.configurationService.get('DATA_SOURCES')[0]]; + } + private getDataProvider(providerName: DataSource) { switch (providerName) { case DataSource.ALPHA_VANTAGE: diff --git a/apps/api/src/services/exchange-rate-data.service.ts b/apps/api/src/services/exchange-rate-data.service.ts index 729d803b3..f58c71190 100644 --- a/apps/api/src/services/exchange-rate-data.service.ts +++ b/apps/api/src/services/exchange-rate-data.service.ts @@ -210,7 +210,7 @@ export class ExchangeRateDataService { return { currency1: baseCurrency, currency2: currency, - dataSource: DataSource.YAHOO, + dataSource: this.dataProviderService.getPrimaryDataSource(), symbol: `${baseCurrency}${currency}` }; }); diff --git a/apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts b/apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts index 6ffed1568..81186cc2d 100644 --- a/apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts +++ b/apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts @@ -10,7 +10,7 @@ import { ImportTransactionsService } from '@ghostfolio/client/services/import-tr import { UserService } from '@ghostfolio/client/services/user/user.service'; import { User } from '@ghostfolio/common/interfaces'; import { hasPermission, permissions } from '@ghostfolio/common/permissions'; -import { Order as OrderModel } from '@prisma/client'; +import { DataSource, Order as OrderModel } from '@prisma/client'; import { format, parseISO } from 'date-fns'; import { DeviceDetectorService } from 'ngx-device-detector'; import { Subject, Subscription } from 'rxjs'; @@ -36,6 +36,7 @@ export class TransactionsPageComponent implements OnDestroy, OnInit { public transactions: OrderModel[]; public user: User; + private primaryDataSource: DataSource; private unsubscribeSubject = new Subject(); /** @@ -53,6 +54,9 @@ export class TransactionsPageComponent implements OnDestroy, OnInit { private snackBar: MatSnackBar, private userService: UserService ) { + const { primaryDataSource } = this.dataService.fetchInfo(); + this.primaryDataSource = primaryDataSource; + this.routeQueryParams = route.queryParams .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((params) => { @@ -201,7 +205,8 @@ export class TransactionsPageComponent implements OnDestroy, OnInit { try { await this.importTransactionsService.importCsv({ fileContent, - defaultAccountId: this.defaultAccountId + defaultAccountId: this.defaultAccountId, + primaryDataSource: this.primaryDataSource }); this.handleImportSuccess(); diff --git a/apps/client/src/app/services/import-transactions.service.ts b/apps/client/src/app/services/import-transactions.service.ts index 60ade8907..dad503350 100644 --- a/apps/client/src/app/services/import-transactions.service.ts +++ b/apps/client/src/app/services/import-transactions.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto'; -import { Type } from '@prisma/client'; +import { DataSource, Type } from '@prisma/client'; import { parse } from 'date-fns'; import { isNumber } from 'lodash'; import { parse as csvToJson } from 'papaparse'; @@ -24,10 +24,12 @@ export class ImportTransactionsService { public async importCsv({ defaultAccountId, - fileContent + fileContent, + primaryDataSource }: { defaultAccountId: string; fileContent: string; + primaryDataSource: DataSource; }) { const content = csvToJson(fileContent, { dynamicTyping: true, @@ -41,7 +43,7 @@ export class ImportTransactionsService { orders.push({ accountId: defaultAccountId, currency: this.parseCurrency(item), - dataSource: 'YAHOO', + dataSource: primaryDataSource, date: this.parseDate(item), fee: this.parseFee(item), quantity: this.parseQuantity(item), diff --git a/libs/common/src/lib/interfaces/info-item.interface.ts b/libs/common/src/lib/interfaces/info-item.interface.ts index 9fad3d393..35061cc75 100644 --- a/libs/common/src/lib/interfaces/info-item.interface.ts +++ b/libs/common/src/lib/interfaces/info-item.interface.ts @@ -1,3 +1,4 @@ +import { DataSource } from '@prisma/client'; import { Statistics } from './statistics.interface'; import { Subscription } from './subscription.interface'; @@ -11,6 +12,7 @@ export interface InfoItem { type: string; }; platforms: { id: string; name: string }[]; + primaryDataSource: DataSource; statistics: Statistics; stripePublicKey?: string; subscriptions: Subscription[];