Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/extend market data in admin panel (#716)
Thomas Kaulfed771525e8f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f99a25f358..db10283d76 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Changed- Displayed features in features overview page based on permissions+- Extended the data points of historical data in the admin control panel## 1.117.0 - 19.02.2022diff --git a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.tsindex 2b4fe8f92f..556cf71a15 100644--- a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts+++ b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts@@ -25,7 +25,7 @@ import {@Injectable()export class YahooFinanceService implements DataProviderInterface {- private yahooFinanceHostname = 'https://query1.finance.yahoo.com';+ private readonly yahooFinanceHostname = 'https://query1.finance.yahoo.com';public constructor(private readonly cryptocurrencyService: CryptocurrencyService@@ -274,7 +274,9 @@ export class YahooFinanceService implements DataProviderInterface {name: value.name});}- } catch {}+ } catch (error) {+ Logger.error(error);+ }return { items };}diff --git a/apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.html b/apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.htmlindex 00b42388b2..7264be84d6 100644--- a/apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.html+++ b/apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.html@@ -18,8 +18,7 @@available:marketDataByMonth[itemByMonth.key][i + 1 < 10 ? '0' + (i + 1) : i + 1- ]?.day ===- i + 1,+ ]?.marketPrice,today: isToday(itemByMonth.key + '-' + (i + 1 < 10 ? '0' + (i + 1) : i + 1))diff --git a/apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.ts b/apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.tsindex 210f48805d..9f935cb91e 100644--- a/apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.ts+++ b/apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.ts@@ -12,7 +12,15 @@ import { DEFAULT_DATE_FORMAT } from '@ghostfolio/common/config';import { DATE_FORMAT } from '@ghostfolio/common/helper';import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface';import { DataSource, MarketData } from '@prisma/client';-import { format, isBefore, isSameDay, isValid, parse } from 'date-fns';+import {+ addDays,+ format,+ isBefore,+ isSameDay,+ isValid,+ parse,+ parseISO+} from 'date-fns';import { DeviceDetectorService } from 'ngx-device-detector';import { Subject, takeUntil } from 'rxjs';@@ -26,6 +34,7 @@ import { MarketDataDetailDialog } from './market-data-detail-dialog/market-data-})export class AdminMarketDataDetailComponent implements OnChanges, OnInit {@Input() dataSource: DataSource;+ @Input() dateOfFirstActivity: string;@Input() marketData: MarketData[];@Input() symbol: string;@@ -36,7 +45,9 @@ export class AdminMarketDataDetailComponent implements OnChanges, OnInit {public deviceType: string;public historicalDataItems: LineChartItem[];public marketDataByMonth: {- [yearMonth: string]: { [day: string]: MarketData & { day: number } };+ [yearMonth: string]: {+ [day: string]: Pick<MarketData, 'date' | 'marketPrice'> & { day: number };+ };} = {};private unsubscribeSubject = new Subject<void>();@@ -57,9 +68,30 @@ export class AdminMarketDataDetailComponent implements OnChanges, OnInit {value: marketDataItem.marketPrice};});++ let date = parseISO(this.dateOfFirstActivity);++ const missingMarketData: Partial<MarketData>[] = [];++ if (this.historicalDataItems?.[0]?.date) {+ while (+ isBefore(+ date,+ parse(this.historicalDataItems[0].date, DATE_FORMAT, new Date())+ )+ ) {+ missingMarketData.push({+ date,+ marketPrice: undefined+ });++ date = addDays(date, 1);+ }+ }+this.marketDataByMonth = {};- for (const marketDataItem of this.marketData) {+ for (const marketDataItem of [...missingMarketData, ...this.marketData]) {const currentDay = parseInt(format(marketDataItem.date, 'd'), 10);const key = format(marketDataItem.date, 'yyyy-MM');@@ -70,8 +102,9 @@ export class AdminMarketDataDetailComponent implements OnChanges, OnInit {this.marketDataByMonth[key][currentDay < 10 ? `0${currentDay}` : currentDay] = {- ...marketDataItem,- day: currentDay+ date: marketDataItem.date,+ day: currentDay,+ marketPrice: marketDataItem.marketPrice};}}diff --git a/apps/client/src/app/components/admin-market-data/admin-market-data.html b/apps/client/src/app/components/admin-market-data/admin-market-data.htmlindex 3ff7435b40..7638d61103 100644--- a/apps/client/src/app/components/admin-market-data/admin-market-data.html+++ b/apps/client/src/app/components/admin-market-data/admin-market-data.html@@ -64,6 +64,7 @@<td class="p-1" colspan="6"><gf-admin-market-data-detail[dataSource]="item.dataSource"+ [dateOfFirstActivity]="item.date"[marketData]="marketDataDetails"[symbol]="item.symbol"(marketDataChanged)="onMarketDataChanged($event)"