Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/add default market price to scraper configuration (#762)
Thomas Kaul32fb3551dccf
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 803f39c442..6c53c15039 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Added+- Added the attribute `defaultMarketPrice` to the scraper configuration to improve the support for bonds- Added a hover effect to the table style### Fixeddiff --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 fb4df11e8f..58ac5de3c9 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@@ -13,7 +13,7 @@ import { Injectable, Logger } from '@nestjs/common';import { DataSource, SymbolProfile } from '@prisma/client';import * as bent from 'bent';import * as cheerio from 'cheerio';-import { format } from 'date-fns';+import { addDays, format, isBefore } from 'date-fns';@Injectable()export class GhostfolioScraperApiService implements DataProviderInterface {@@ -50,9 +50,27 @@ export class GhostfolioScraperApiService implements DataProviderInterface {const [symbolProfile] = await this.symbolProfileService.getSymbolProfiles([symbol]);- const { selector, url } = symbolProfile.scraperConfiguration;+ const { defaultMarketPrice, selector, url } =+ symbolProfile.scraperConfiguration;++ if (defaultMarketPrice) {+ const historical: {+ [symbol: string]: { [date: string]: IDataProviderHistoricalResponse };+ } = {+ [symbol]: {}+ };+ let date = from;++ while (isBefore(date, to)) {+ historical[symbol][format(date, DATE_FORMAT)] = {+ marketPrice: defaultMarketPrice+ };++ date = addDays(date, 1);+ }- if (selector === undefined || url === undefined) {+ return historical;+ } else if (selector === undefined || url === undefined) {return {};}diff --git a/apps/api/src/services/data-provider/ghostfolio-scraper-api/interfaces/scraper-configuration.interface.ts b/apps/api/src/services/data-provider/ghostfolio-scraper-api/interfaces/scraper-configuration.interface.tsindex 21380253e0..9bae194183 100644--- a/apps/api/src/services/data-provider/ghostfolio-scraper-api/interfaces/scraper-configuration.interface.ts+++ b/apps/api/src/services/data-provider/ghostfolio-scraper-api/interfaces/scraper-configuration.interface.ts@@ -1,4 +1,5 @@export interface ScraperConfiguration {+ defaultMarketPrice?: number;selector: string;url: string;}diff --git a/apps/api/src/services/symbol-profile.service.ts b/apps/api/src/services/symbol-profile.service.tsindex b3c6a4c21d..b45c44af94 100644--- a/apps/api/src/services/symbol-profile.service.ts+++ b/apps/api/src/services/symbol-profile.service.ts@@ -79,6 +79,7 @@ export class SymbolProfileService {if (scraperConfiguration) {return {+ defaultMarketPrice: scraperConfiguration.defaultMarketPrice as number,selector: scraperConfiguration.selector as string,url: scraperConfiguration.url as string};