Browse Source

Introduce primary data source

pull/419/head
Thomas 4 years ago
parent
commit
9dbec5c125
  1. 3
      apps/api/src/app/info/info.service.ts
  2. 6
      apps/api/src/app/portfolio/current-rate.service.ts
  3. 4
      apps/api/src/services/data-provider/data-provider.service.ts
  4. 2
      apps/api/src/services/exchange-rate-data.service.ts
  5. 9
      apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts
  6. 8
      apps/client/src/app/services/import-transactions.service.ts
  7. 2
      libs/common/src/lib/interfaces/info-item.interface.ts

3
apps/api/src/app/info/info.service.ts

@ -1,5 +1,6 @@
import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration.service';
import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.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 { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { InfoItem } from '@ghostfolio/common/interfaces'; import { InfoItem } from '@ghostfolio/common/interfaces';
@ -16,6 +17,7 @@ export class InfoService {
public constructor( public constructor(
private readonly configurationService: ConfigurationService, private readonly configurationService: ConfigurationService,
private readonly dataProviderService: DataProviderService,
private readonly exchangeRateDataService: ExchangeRateDataService, private readonly exchangeRateDataService: ExchangeRateDataService,
private readonly dataGatheringService: DataGatheringService, private readonly dataGatheringService: DataGatheringService,
private readonly jwtService: JwtService, private readonly jwtService: JwtService,
@ -60,6 +62,7 @@ export class InfoService {
currencies: this.exchangeRateDataService.getCurrencies(), currencies: this.exchangeRateDataService.getCurrencies(),
demoAuthToken: this.getDemoAuthToken(), demoAuthToken: this.getDemoAuthToken(),
lastDataGathering: await this.getLastDataGathering(), lastDataGathering: await this.getLastDataGathering(),
primaryDataSource: this.dataProviderService.getPrimaryDataSource(),
statistics: await this.getStatistics(), statistics: await this.getStatistics(),
subscriptions: await this.getSubscriptions() subscriptions: await this.getSubscriptions()
}; };

6
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 { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
import { resetHours } from '@ghostfolio/common/helper'; import { resetHours } from '@ghostfolio/common/helper';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { DataSource } from '@prisma/client';
import { isBefore, isToday } from 'date-fns'; import { isBefore, isToday } from 'date-fns';
import { flatten } from 'lodash'; import { flatten } from 'lodash';
@ -27,7 +26,10 @@ export class CurrentRateService {
}: GetValueParams): Promise<GetValueObject> { }: GetValueParams): Promise<GetValueObject> {
if (isToday(date)) { if (isToday(date)) {
const dataProviderResult = await this.dataProviderService.get([ const dataProviderResult = await this.dataProviderService.get([
{ symbol, dataSource: DataSource.YAHOO } {
symbol,
dataSource: this.dataProviderService.getPrimaryDataSource()
}
]); ]);
return { return {
symbol, symbol,

4
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) { private getDataProvider(providerName: DataSource) {
switch (providerName) { switch (providerName) {
case DataSource.ALPHA_VANTAGE: case DataSource.ALPHA_VANTAGE:

2
apps/api/src/services/exchange-rate-data.service.ts

@ -210,7 +210,7 @@ export class ExchangeRateDataService {
return { return {
currency1: baseCurrency, currency1: baseCurrency,
currency2: currency, currency2: currency,
dataSource: DataSource.YAHOO, dataSource: this.dataProviderService.getPrimaryDataSource(),
symbol: `${baseCurrency}${currency}` symbol: `${baseCurrency}${currency}`
}; };
}); });

9
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 { UserService } from '@ghostfolio/client/services/user/user.service';
import { User } from '@ghostfolio/common/interfaces'; import { User } from '@ghostfolio/common/interfaces';
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; 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 { format, parseISO } from 'date-fns';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject, Subscription } from 'rxjs'; import { Subject, Subscription } from 'rxjs';
@ -36,6 +36,7 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
public transactions: OrderModel[]; public transactions: OrderModel[];
public user: User; public user: User;
private primaryDataSource: DataSource;
private unsubscribeSubject = new Subject<void>(); private unsubscribeSubject = new Subject<void>();
/** /**
@ -53,6 +54,9 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
private snackBar: MatSnackBar, private snackBar: MatSnackBar,
private userService: UserService private userService: UserService
) { ) {
const { primaryDataSource } = this.dataService.fetchInfo();
this.primaryDataSource = primaryDataSource;
this.routeQueryParams = route.queryParams this.routeQueryParams = route.queryParams
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe((params) => { .subscribe((params) => {
@ -201,7 +205,8 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
try { try {
await this.importTransactionsService.importCsv({ await this.importTransactionsService.importCsv({
fileContent, fileContent,
defaultAccountId: this.defaultAccountId defaultAccountId: this.defaultAccountId,
primaryDataSource: this.primaryDataSource
}); });
this.handleImportSuccess(); this.handleImportSuccess();

8
apps/client/src/app/services/import-transactions.service.ts

@ -1,7 +1,7 @@
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto'; 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 { parse } from 'date-fns';
import { isNumber } from 'lodash'; import { isNumber } from 'lodash';
import { parse as csvToJson } from 'papaparse'; import { parse as csvToJson } from 'papaparse';
@ -24,10 +24,12 @@ export class ImportTransactionsService {
public async importCsv({ public async importCsv({
defaultAccountId, defaultAccountId,
fileContent fileContent,
primaryDataSource
}: { }: {
defaultAccountId: string; defaultAccountId: string;
fileContent: string; fileContent: string;
primaryDataSource: DataSource;
}) { }) {
const content = csvToJson(fileContent, { const content = csvToJson(fileContent, {
dynamicTyping: true, dynamicTyping: true,
@ -41,7 +43,7 @@ export class ImportTransactionsService {
orders.push({ orders.push({
accountId: defaultAccountId, accountId: defaultAccountId,
currency: this.parseCurrency(item), currency: this.parseCurrency(item),
dataSource: 'YAHOO', dataSource: primaryDataSource,
date: this.parseDate(item), date: this.parseDate(item),
fee: this.parseFee(item), fee: this.parseFee(item),
quantity: this.parseQuantity(item), quantity: this.parseQuantity(item),

2
libs/common/src/lib/interfaces/info-item.interface.ts

@ -1,3 +1,4 @@
import { DataSource } from '@prisma/client';
import { Statistics } from './statistics.interface'; import { Statistics } from './statistics.interface';
import { Subscription } from './subscription.interface'; import { Subscription } from './subscription.interface';
@ -11,6 +12,7 @@ export interface InfoItem {
type: string; type: string;
}; };
platforms: { id: string; name: string }[]; platforms: { id: string; name: string }[];
primaryDataSource: DataSource;
statistics: Statistics; statistics: Statistics;
stripePublicKey?: string; stripePublicKey?: string;
subscriptions: Subscription[]; subscriptions: Subscription[];

Loading…
Cancel
Save