From aaabcb97b6654ddaa60ce293777c834074e78df0 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 2 May 2025 14:50:16 +0200 Subject: [PATCH] Extend watchlist by current market condition --- .../endpoints/watchlist/watchlist.service.ts | 15 ++++++++---- .../services/benchmark/benchmark.service.ts | 24 +++++++++---------- .../home-watchlist.component.ts | 4 ++-- .../home-watchlist/home-watchlist.html | 2 +- .../responses/watchlist-response.interface.ts | 1 + 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/apps/api/src/app/endpoints/watchlist/watchlist.service.ts b/apps/api/src/app/endpoints/watchlist/watchlist.service.ts index cf44fee3c..b5c6da4f7 100644 --- a/apps/api/src/app/endpoints/watchlist/watchlist.service.ts +++ b/apps/api/src/app/endpoints/watchlist/watchlist.service.ts @@ -106,7 +106,8 @@ export class WatchlistService { return { dataSource, symbol }; }) }); - const symbolProfiles = await this.symbolProfileService.getSymbolProfiles( + + const assetProfiles = await this.symbolProfileService.getSymbolProfiles( user.watchlist ); @@ -116,19 +117,23 @@ export class WatchlistService { dataSource, symbol }); + const performancePercent = this.benchmarkService.calculateChangeInPercentage( allTimeHigh?.marketPrice, quotes[symbol]?.marketPrice ); - const symbolProfile = symbolProfiles.find((profile) => { + + const assetProfile = assetProfiles.find((profile) => { return profile.dataSource === dataSource && profile.symbol === symbol; }); return { dataSource, symbol, - name: symbolProfile?.name, + marketCondition: + this.benchmarkService.getMarketCondition(performancePercent), + name: assetProfile?.name, performances: { allTimeHigh: { date: allTimeHigh?.date, @@ -139,6 +144,8 @@ export class WatchlistService { }) ); - return watchlist.sort((a, b) => a.name.localeCompare(b.name)); + return watchlist.sort((a, b) => { + return a.name.localeCompare(b.name); + }); } } diff --git a/apps/api/src/services/benchmark/benchmark.service.ts b/apps/api/src/services/benchmark/benchmark.service.ts index 95cb9e5d2..f37f26bfc 100644 --- a/apps/api/src/services/benchmark/benchmark.service.ts +++ b/apps/api/src/services/benchmark/benchmark.service.ts @@ -212,6 +212,18 @@ export class BenchmarkService { }; } + public getMarketCondition( + aPerformanceInPercent: number + ): Benchmark['marketCondition'] { + if (aPerformanceInPercent >= 0) { + return 'ALL_TIME_HIGH'; + } else if (aPerformanceInPercent <= -0.2) { + return 'BEAR_MARKET'; + } else { + return 'NEUTRAL_MARKET'; + } + } + private async calculateAndCacheBenchmarks({ enableSharing = false }): Promise { @@ -302,16 +314,4 @@ export class BenchmarkService { return benchmarks; } - - private getMarketCondition( - aPerformanceInPercent: number - ): Benchmark['marketCondition'] { - if (aPerformanceInPercent >= 0) { - return 'ALL_TIME_HIGH'; - } else if (aPerformanceInPercent <= -0.2) { - return 'BEAR_MARKET'; - } else { - return 'NEUTRAL_MARKET'; - } - } } diff --git a/apps/client/src/app/components/home-watchlist/home-watchlist.component.ts b/apps/client/src/app/components/home-watchlist/home-watchlist.component.ts index e00858f5f..efad2fef5 100644 --- a/apps/client/src/app/components/home-watchlist/home-watchlist.component.ts +++ b/apps/client/src/app/components/home-watchlist/home-watchlist.component.ts @@ -120,12 +120,12 @@ export class HomeWatchlistComponent implements OnDestroy, OnInit { .pipe(takeUntil(this.unsubscribeSubject)) .subscribe(({ watchlist }) => { this.watchlist = watchlist.map( - ({ dataSource, name, performances, symbol }) => ({ + ({ dataSource, marketCondition, name, performances, symbol }) => ({ dataSource, + marketCondition, name, performances, symbol, - marketCondition: null, trend50d: 'UNKNOWN' as BenchmarkTrend, trend200d: 'UNKNOWN' as BenchmarkTrend }) diff --git a/apps/client/src/app/components/home-watchlist/home-watchlist.html b/apps/client/src/app/components/home-watchlist/home-watchlist.html index ef073d331..d290a4a2d 100644 --- a/apps/client/src/app/components/home-watchlist/home-watchlist.html +++ b/apps/client/src/app/components/home-watchlist/home-watchlist.html @@ -7,7 +7,7 @@ } -
+