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 { 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()
};

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 { 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<GetValueObject> {
if (isToday(date)) {
const dataProviderResult = await this.dataProviderService.get([
{ symbol, dataSource: DataSource.YAHOO }
{
symbol,
dataSource: this.dataProviderService.getPrimaryDataSource()
}
]);
return {
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) {
switch (providerName) {
case DataSource.ALPHA_VANTAGE:

2
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}`
};
});

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 { 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<void>();
/**
@ -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();

8
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),

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 { 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[];

Loading…
Cancel
Save