diff --git a/apps/api/src/app/endpoints/watchlist/watchlist.service.ts b/apps/api/src/app/endpoints/watchlist/watchlist.service.ts index 08f62706d..cf44fee3c 100644 --- a/apps/api/src/app/endpoints/watchlist/watchlist.service.ts +++ b/apps/api/src/app/endpoints/watchlist/watchlist.service.ts @@ -8,7 +8,6 @@ import { WatchlistResponse } from '@ghostfolio/common/interfaces'; import { BadRequestException, Injectable } from '@nestjs/common'; import { DataSource, Prisma } from '@prisma/client'; -import ms from 'ms'; @Injectable() export class WatchlistService { @@ -105,32 +104,41 @@ export class WatchlistService { const quotes = await this.dataProviderService.getQuotes({ items: user.watchlist.map(({ dataSource, symbol }) => { return { dataSource, symbol }; - }), - requestTimeout: ms('30 seconds'), - useCache: false + }) }); + const symbolProfiles = await this.symbolProfileService.getSymbolProfiles( + user.watchlist + ); const watchlist = await Promise.all( user.watchlist.map(async ({ dataSource, symbol }) => { - const ath = await this.marketDataService.getMax({ dataSource, symbol }); + const allTimeHigh = await this.marketDataService.getMax({ + dataSource, + symbol + }); const performancePercent = this.benchmarkService.calculateChangeInPercentage( - ath.marketPrice, + allTimeHigh?.marketPrice, quotes[symbol]?.marketPrice ); + const symbolProfile = symbolProfiles.find((profile) => { + return profile.dataSource === dataSource && profile.symbol === symbol; + }); + return { dataSource, + symbol, + name: symbolProfile?.name, performances: { allTimeHigh: { - date: ath?.date, + date: allTimeHigh?.date, performancePercent } - }, - symbol + } }; }) ); - return watchlist; + return watchlist.sort((a, b) => a.name.localeCompare(b.name)); } } 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 33f63dfa0..e00858f5f 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 @@ -119,17 +119,17 @@ export class HomeWatchlistComponent implements OnDestroy, OnInit { .fetchWatchlist() .pipe(takeUntil(this.unsubscribeSubject)) .subscribe(({ watchlist }) => { - this.watchlist = watchlist - .map(({ dataSource, performances, symbol }) => ({ + this.watchlist = watchlist.map( + ({ dataSource, name, performances, symbol }) => ({ dataSource, + name, performances, symbol, marketCondition: null, - name: symbol, trend50d: 'UNKNOWN' as BenchmarkTrend, trend200d: 'UNKNOWN' as BenchmarkTrend - })) - .sort((a, b) => a.name.localeCompare(b.name)); + }) + ); this.changeDetectorRef.markForCheck(); }); diff --git a/libs/common/src/lib/interfaces/responses/watchlist-response.interface.ts b/libs/common/src/lib/interfaces/responses/watchlist-response.interface.ts index 8adecc9c5..ed0b29ef8 100644 --- a/libs/common/src/lib/interfaces/responses/watchlist-response.interface.ts +++ b/libs/common/src/lib/interfaces/responses/watchlist-response.interface.ts @@ -5,6 +5,7 @@ import { export interface WatchlistResponse { watchlist: (AssetProfileIdentifier & { + name: string; performances: Benchmark['performances']; })[]; }