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 { 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));
}
}

10
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();
});

1
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'];
})[];
}

Loading…
Cancel
Save