From 3c46bde8d50d9bd26e739f6f892e7ad480a833f5 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 11 Sep 2021 11:14:55 +0200 Subject: [PATCH] Bugfix/fix fear and greed index (#359) * Fix fear and greed index * Refactor fear and greed index symbol * GF.FEAR_AND_GREED_INDEX -> _GF_FEAR_AND_GREED_INDEX * Update changelog --- CHANGELOG.md | 6 ++++++ apps/api/src/app/symbol/symbol.service.ts | 2 +- apps/api/src/services/data-gathering.service.ts | 8 ++++++-- .../rakuten-rapid-api/rakuten-rapid-api.service.ts | 9 +++++---- apps/client/src/app/pages/home/home-page.component.ts | 3 ++- libs/common/src/lib/config.ts | 1 + 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76ca40d90..65b2007f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Fixed the _Fear & Greed Index_ (market mood) + ## 1.49.0 - 08.09.2021 ### Added diff --git a/apps/api/src/app/symbol/symbol.service.ts b/apps/api/src/app/symbol/symbol.service.ts index 2be74b19b..3fdb2f753 100644 --- a/apps/api/src/app/symbol/symbol.service.ts +++ b/apps/api/src/app/symbol/symbol.service.ts @@ -17,7 +17,7 @@ export class SymbolService { const response = await this.dataProviderService.get([aSymbol]); const { currency, dataSource, marketPrice } = response[aSymbol] ?? {}; - if (currency && dataSource && marketPrice) { + if (dataSource && marketPrice) { return { dataSource, marketPrice, diff --git a/apps/api/src/services/data-gathering.service.ts b/apps/api/src/services/data-gathering.service.ts index c4a3fd0ec..fa988f739 100644 --- a/apps/api/src/services/data-gathering.service.ts +++ b/apps/api/src/services/data-gathering.service.ts @@ -1,4 +1,8 @@ -import { benchmarks, currencyPairs } from '@ghostfolio/common/config'; +import { + benchmarks, + currencyPairs, + ghostfolioFearAndGreedIndexSymbol +} from '@ghostfolio/common/config'; import { DATE_FORMAT, getUtc, @@ -295,7 +299,7 @@ export class DataGatheringService { benchmarksToGather.push({ dataSource: DataSource.RAKUTEN, date: startDate, - symbol: 'GF.FEAR_AND_GREED_INDEX' + symbol: ghostfolioFearAndGreedIndexSymbol }); } diff --git a/apps/api/src/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service.ts b/apps/api/src/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service.ts index 3b07301ab..a230f88bd 100644 --- a/apps/api/src/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service.ts +++ b/apps/api/src/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service.ts @@ -1,6 +1,7 @@ import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface'; import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service'; +import { ghostfolioFearAndGreedIndexSymbol } from '@ghostfolio/common/config'; import { DATE_FORMAT, getToday, @@ -47,11 +48,11 @@ export class RakutenRapidApiService implements DataProviderInterface { try { const symbol = aSymbols[0]; - if (symbol === 'GF.FEAR_AND_GREED_INDEX') { + if (symbol === ghostfolioFearAndGreedIndexSymbol) { const fgi = await this.getFearAndGreedIndex(); return { - 'GF.FEAR_AND_GREED_INDEX': { + [ghostfolioFearAndGreedIndexSymbol]: { currency: undefined, dataSource: DataSource.RAKUTEN, marketPrice: fgi.now.value, @@ -82,7 +83,7 @@ export class RakutenRapidApiService implements DataProviderInterface { try { const symbol = aSymbols[0]; - if (symbol === 'GF.FEAR_AND_GREED_INDEX') { + if (symbol === ghostfolioFearAndGreedIndexSymbol) { const fgi = await this.getFearAndGreedIndex(); try { @@ -118,7 +119,7 @@ export class RakutenRapidApiService implements DataProviderInterface { } catch {} return { - 'GF.FEAR_AND_GREED_INDEX': { + [ghostfolioFearAndGreedIndexSymbol]: { [format(getYesterday(), DATE_FORMAT)]: { marketPrice: fgi.previousClose.value } diff --git a/apps/client/src/app/pages/home/home-page.component.ts b/apps/client/src/app/pages/home/home-page.component.ts index aaad1e32f..ce9b96956 100644 --- a/apps/client/src/app/pages/home/home-page.component.ts +++ b/apps/client/src/app/pages/home/home-page.component.ts @@ -20,6 +20,7 @@ import { SettingsStorageService } from '@ghostfolio/client/services/settings-storage.service'; import { UserService } from '@ghostfolio/client/services/user/user.service'; +import { ghostfolioFearAndGreedIndexSymbol } from '@ghostfolio/common/config'; import { PortfolioPerformance, PortfolioSummary, @@ -111,7 +112,7 @@ export class HomePageComponent implements OnDestroy, OnInit { if (this.hasPermissionToAccessFearAndGreedIndex) { this.dataService - .fetchSymbolItem('GF.FEAR_AND_GREED_INDEX') + .fetchSymbolItem(ghostfolioFearAndGreedIndexSymbol) .pipe(takeUntil(this.unsubscribeSubject)) .subscribe(({ marketPrice }) => { this.fearAndGreedIndex = marketPrice; diff --git a/libs/common/src/lib/config.ts b/libs/common/src/lib/config.ts index 295ce68c0..6b27b7fae 100644 --- a/libs/common/src/lib/config.ts +++ b/libs/common/src/lib/config.ts @@ -28,6 +28,7 @@ export const currencyPairs: Partial< export const ghostfolioScraperApiSymbolPrefix = '_GF_'; export const ghostfolioCashSymbol = `${ghostfolioScraperApiSymbolPrefix}CASH`; +export const ghostfolioFearAndGreedIndexSymbol = `${ghostfolioScraperApiSymbolPrefix}FEAR_AND_GREED_INDEX`; export const locale = 'de-CH';