Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/eliminate name from scraper config (#277)
Thomas8ac1272a9d82
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 778fe6bfd3..e9dd4f422a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Improved the data gathering handling on server restart- Respected the cash balance on the allocations page+- Eliminated the name from the scraper configuration### Fixeddiff --git a/apps/api/src/app/symbol/symbol.service.ts b/apps/api/src/app/symbol/symbol.service.tsindex 5740ea69fd..a44f4edd10 100644--- a/apps/api/src/app/symbol/symbol.service.ts+++ b/apps/api/src/app/symbol/symbol.service.ts@@ -1,6 +1,5 @@import { DataProviderService } from '@ghostfolio/api/services/data-provider.service';-import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service';-import { convertFromYahooSymbol } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service';+import { PrismaService } from '@ghostfolio/api/services/prisma.service';import { Injectable } from '@nestjs/common';import { Currency, DataSource } from '@prisma/client';@@ -11,7 +10,7 @@ import { SymbolItem } from './interfaces/symbol-item.interface';export class SymbolService {public constructor(private readonly dataProviderService: DataProviderService,- private readonly ghostfolioScraperApiService: GhostfolioScraperApiService+ private readonly prismaService: PrismaService) {}public async get(aSymbol: string): Promise<SymbolItem> {@@ -37,16 +36,28 @@ export class SymbolService {results.items = items;// Add custom symbols- const scraperConfigurations = await this.ghostfolioScraperApiService.getScraperConfigurations();- scraperConfigurations.forEach((scraperConfiguration) => {- if (scraperConfiguration.name.toLowerCase().startsWith(aQuery)) {- results.items.push({- dataSource: DataSource.GHOSTFOLIO,- name: scraperConfiguration.name,- symbol: scraperConfiguration.symbol- });- }- });+ const ghostfolioSymbolProfiles =+ await this.prismaService.symbolProfile.findMany({+ select: {+ dataSource: true,+ name: true,+ symbol: true+ },+ where: {+ AND: [+ {+ dataSource: DataSource.GHOSTFOLIO,+ name: {+ startsWith: aQuery+ }+ }+ ]+ }+ });++ for (const ghostfolioSymbolProfile of ghostfolioSymbolProfiles) {+ results.items.push(ghostfolioSymbolProfile);+ }return results;} catch (error) {diff --git a/apps/api/src/services/data-gathering.service.ts b/apps/api/src/services/data-gathering.service.tsindex 6bc01f2214..f853e5dbce 100644--- a/apps/api/src/services/data-gathering.service.ts+++ b/apps/api/src/services/data-gathering.service.ts@@ -333,9 +333,8 @@ export class DataGatheringService {});- const customSymbolsToGather = await this.getCustomSymbolsToGather(- startDate- );+ const customSymbolsToGather =+ await this.ghostfolioScraperApi.getCustomSymbolsToGather(startDate);return [...this.getBenchmarksToGather(startDate),@@ -348,9 +347,8 @@ export class DataGatheringService {private async getSymbolsMax(): Promise<IDataGatheringItem[]> {const startDate = new Date(getUtc('2015-01-01'));- const customSymbolsToGather = await this.getCustomSymbolsToGather(- startDate- );+ const customSymbolsToGather =+ await this.ghostfolioScraperApi.getCustomSymbolsToGather(startDate);const currencyPairsToGather = currencyPairs.map(({ dataSource, symbol }) => {diff --git a/apps/api/src/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service.ts b/apps/api/src/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service.tsindex e2bda04767..e2ffe3d19f 100644--- a/apps/api/src/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service.ts+++ b/apps/api/src/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service.ts@@ -12,6 +12,7 @@ import { format } from 'date-fns';import { DataProviderInterface } from '../../interfaces/data-provider.interface';import {+ IDataGatheringItem,IDataProviderHistoricalResponse,IDataProviderResponse,MarketState@@ -55,8 +56,7 @@ export class GhostfolioScraperApiService implements DataProviderInterface {marketPrice,currency: scraperConfig?.currency,dataSource: DataSource.GHOSTFOLIO,- marketState: MarketState.delayed,- name: scraperConfig?.name+ marketState: MarketState.delayed}};} catch (error) {@@ -66,6 +66,25 @@ export class GhostfolioScraperApiService implements DataProviderInterface {return {};}+ public async getCustomSymbolsToGather(+ startDate?: Date+ ): Promise<IDataGatheringItem[]> {+ const ghostfolioSymbolProfiles =+ await this.prismaService.symbolProfile.findMany({+ where: {+ dataSource: DataSource.GHOSTFOLIO+ }+ });++ return ghostfolioSymbolProfiles.map(({ dataSource, symbol }) => {+ return {+ dataSource,+ symbol,+ date: startDate+ };+ });+ }+public async getHistorical(aSymbols: string[],aGranularity: Granularity = 'day',diff --git a/apps/api/src/services/data-provider/ghostfolio-scraper-api/interfaces/scraper-config.interface.ts b/apps/api/src/services/data-provider/ghostfolio-scraper-api/interfaces/scraper-config.interface.tsindex c6900ecf3f..449ea987dc 100644--- a/apps/api/src/services/data-provider/ghostfolio-scraper-api/interfaces/scraper-config.interface.ts+++ b/apps/api/src/services/data-provider/ghostfolio-scraper-api/interfaces/scraper-config.interface.ts@@ -2,7 +2,6 @@ import { Currency } from '@prisma/client';export interface ScraperConfig {currency: Currency;- name: string;selector: string;symbol: string;url: string;diff --git a/apps/api/src/services/interfaces/interfaces.ts b/apps/api/src/services/interfaces/interfaces.tsindex dac5b8213f..ba1f4a50d4 100644--- a/apps/api/src/services/interfaces/interfaces.ts+++ b/apps/api/src/services/interfaces/interfaces.ts@@ -42,7 +42,7 @@ export interface IDataProviderResponse {marketChangePercent?: number;marketPrice: number;marketState: MarketState;- name: string;+ name?: string;url?: string;}