From 65e151151b639de6a149d8fce70385b92abbb16c Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Thu, 27 Jan 2022 21:01:38 +0100 Subject: [PATCH] Feature/increase fear and greed index to 90 days (#652) * Increase fear and greed index to 90 days * Update changelog --- CHANGELOG.md | 1 + apps/api/src/app/symbol/symbol.controller.ts | 13 ++----------- apps/api/src/app/symbol/symbol.service.ts | 14 ++++++-------- .../home-market/home-market.component.ts | 3 ++- .../app/components/home-market/home-market.html | 12 ++---------- apps/client/src/app/services/data.service.ts | 14 ++++++++++---- 6 files changed, 23 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 329f43a3c..76e404802 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 - Improved the annualized performance in the new calculation engine +- Increased the historical data chart of the _Fear & Greed Index_ (market mood) to 90 days ## 1.107.0 - 24.01.2022 diff --git a/apps/api/src/app/symbol/symbol.controller.ts b/apps/api/src/app/symbol/symbol.controller.ts index bbe582cea..d81ba5ca8 100644 --- a/apps/api/src/app/symbol/symbol.controller.ts +++ b/apps/api/src/app/symbol/symbol.controller.ts @@ -1,17 +1,12 @@ import { IDataProviderHistoricalResponse } from '@ghostfolio/api/services/interfaces/interfaces'; -import type { RequestWithUser } from '@ghostfolio/common/types'; import { Controller, - DefaultValuePipe, Get, HttpException, - Inject, Param, - ParseBoolPipe, Query, UseGuards } from '@nestjs/common'; -import { REQUEST } from '@nestjs/core'; import { AuthGuard } from '@nestjs/passport'; import { DataSource } from '@prisma/client'; import { StatusCodes, getReasonPhrase } from 'http-status-codes'; @@ -23,10 +18,7 @@ import { SymbolService } from './symbol.service'; @Controller('symbol') export class SymbolController { - public constructor( - private readonly symbolService: SymbolService, - @Inject(REQUEST) private readonly request: RequestWithUser - ) {} + public constructor(private readonly symbolService: SymbolService) {} /** * Must be before /:symbol @@ -54,8 +46,7 @@ export class SymbolController { public async getSymbolData( @Param('dataSource') dataSource: DataSource, @Param('symbol') symbol: string, - @Query('includeHistoricalData', new DefaultValuePipe(false), ParseBoolPipe) - includeHistoricalData: boolean + @Query('includeHistoricalData') includeHistoricalData?: number ): Promise { if (!DataSource[dataSource]) { throw new HttpException( diff --git a/apps/api/src/app/symbol/symbol.service.ts b/apps/api/src/app/symbol/symbol.service.ts index 8c95ce947..37b1c5864 100644 --- a/apps/api/src/app/symbol/symbol.service.ts +++ b/apps/api/src/app/symbol/symbol.service.ts @@ -5,7 +5,6 @@ import { IDataProviderHistoricalResponse } from '@ghostfolio/api/services/interfaces/interfaces'; import { MarketDataService } from '@ghostfolio/api/services/market-data.service'; -import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { DATE_FORMAT } from '@ghostfolio/common/helper'; import { Injectable, Logger } from '@nestjs/common'; import { DataSource } from '@prisma/client'; @@ -18,25 +17,24 @@ import { SymbolItem } from './interfaces/symbol-item.interface'; export class SymbolService { public constructor( private readonly dataProviderService: DataProviderService, - private readonly marketDataService: MarketDataService, - private readonly prismaService: PrismaService + private readonly marketDataService: MarketDataService ) {} public async get({ dataGatheringItem, - includeHistoricalData = false + includeHistoricalData }: { dataGatheringItem: IDataGatheringItem; - includeHistoricalData?: boolean; + includeHistoricalData?: number; }): Promise { const response = await this.dataProviderService.get([dataGatheringItem]); const { currency, marketPrice } = response[dataGatheringItem.symbol] ?? {}; if (dataGatheringItem.dataSource && marketPrice) { - let historicalData: HistoricalDataItem[]; + let historicalData: HistoricalDataItem[] = []; - if (includeHistoricalData) { - const days = 30; + if (includeHistoricalData > 0) { + const days = includeHistoricalData; const marketData = await this.marketDataService.getRange({ dateQuery: { gte: subDays(new Date(), days) }, diff --git a/apps/client/src/app/components/home-market/home-market.component.ts b/apps/client/src/app/components/home-market/home-market.component.ts index 87a86814d..37b31676f 100644 --- a/apps/client/src/app/components/home-market/home-market.component.ts +++ b/apps/client/src/app/components/home-market/home-market.component.ts @@ -20,6 +20,7 @@ export class HomeMarketComponent implements OnDestroy, OnInit { public hasPermissionToAccessFearAndGreedIndex: boolean; public historicalData: HistoricalDataItem[]; public isLoading = true; + public readonly numberOfDays = 90; public user: User; private unsubscribeSubject = new Subject(); @@ -49,7 +50,7 @@ export class HomeMarketComponent implements OnDestroy, OnInit { this.dataService .fetchSymbolItem({ dataSource: DataSource.RAKUTEN, - includeHistoricalData: true, + includeHistoricalData: this.numberOfDays, symbol: ghostfolioFearAndGreedIndexSymbol }) .pipe(takeUntil(this.unsubscribeSubject)) diff --git a/apps/client/src/app/components/home-market/home-market.html b/apps/client/src/app/components/home-market/home-market.html index 0ef4b5ef8..f3d8315dd 100644 --- a/apps/client/src/app/components/home-market/home-market.html +++ b/apps/client/src/app/components/home-market/home-market.html @@ -1,18 +1,10 @@
- Last 30 Days + Last {{ numberOfDays }} Days
(`/api/symbol/${dataSource}/${symbol}`, { - params: { includeHistoricalData } + params }); }