Browse Source

resolve comments

pull/4634/head
KenTandrian 4 months ago
parent
commit
10785d9f89
  1. 28
      apps/api/src/app/endpoints/watchlist/watchlist.service.ts
  2. 10
      apps/client/src/app/components/home-watchlist/home-watchlist.component.ts
  3. 1
      libs/common/src/lib/interfaces/responses/watchlist-response.interface.ts

28
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 { BadRequestException, Injectable } from '@nestjs/common';
import { DataSource, Prisma } from '@prisma/client'; import { DataSource, Prisma } from '@prisma/client';
import ms from 'ms';
@Injectable() @Injectable()
export class WatchlistService { export class WatchlistService {
@ -105,32 +104,41 @@ export class WatchlistService {
const quotes = await this.dataProviderService.getQuotes({ const quotes = await this.dataProviderService.getQuotes({
items: user.watchlist.map(({ dataSource, symbol }) => { items: user.watchlist.map(({ dataSource, symbol }) => {
return { dataSource, symbol }; return { dataSource, symbol };
}), })
requestTimeout: ms('30 seconds'),
useCache: false
}); });
const symbolProfiles = await this.symbolProfileService.getSymbolProfiles(
user.watchlist
);
const watchlist = await Promise.all( const watchlist = await Promise.all(
user.watchlist.map(async ({ dataSource, symbol }) => { user.watchlist.map(async ({ dataSource, symbol }) => {
const ath = await this.marketDataService.getMax({ dataSource, symbol }); const allTimeHigh = await this.marketDataService.getMax({
dataSource,
symbol
});
const performancePercent = const performancePercent =
this.benchmarkService.calculateChangeInPercentage( this.benchmarkService.calculateChangeInPercentage(
ath.marketPrice, allTimeHigh?.marketPrice,
quotes[symbol]?.marketPrice quotes[symbol]?.marketPrice
); );
const symbolProfile = symbolProfiles.find((profile) => {
return profile.dataSource === dataSource && profile.symbol === symbol;
});
return { return {
dataSource, dataSource,
symbol,
name: symbolProfile?.name,
performances: { performances: {
allTimeHigh: { allTimeHigh: {
date: ath?.date, date: allTimeHigh?.date,
performancePercent performancePercent
} }
}, }
symbol
}; };
}) })
); );
return watchlist; return watchlist.sort((a, b) => a.name.localeCompare(b.name));
} }
} }

10
apps/client/src/app/components/home-watchlist/home-watchlist.component.ts

@ -119,17 +119,17 @@ export class HomeWatchlistComponent implements OnDestroy, OnInit {
.fetchWatchlist() .fetchWatchlist()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe(({ watchlist }) => { .subscribe(({ watchlist }) => {
this.watchlist = watchlist this.watchlist = watchlist.map(
.map(({ dataSource, performances, symbol }) => ({ ({ dataSource, name, performances, symbol }) => ({
dataSource, dataSource,
name,
performances, performances,
symbol, symbol,
marketCondition: null, marketCondition: null,
name: symbol,
trend50d: 'UNKNOWN' as BenchmarkTrend, trend50d: 'UNKNOWN' as BenchmarkTrend,
trend200d: 'UNKNOWN' as BenchmarkTrend trend200d: 'UNKNOWN' as BenchmarkTrend
})) })
.sort((a, b) => a.name.localeCompare(b.name)); );
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
}); });

1
libs/common/src/lib/interfaces/responses/watchlist-response.interface.ts

@ -5,6 +5,7 @@ import {
export interface WatchlistResponse { export interface WatchlistResponse {
watchlist: (AssetProfileIdentifier & { watchlist: (AssetProfileIdentifier & {
name: string;
performances: Benchmark['performances']; performances: Benchmark['performances'];
})[]; })[];
} }

Loading…
Cancel
Save