Browse Source

Extend watchlist by current market condition

pull/4634/head
Thomas Kaul 4 months ago
parent
commit
aaabcb97b6
  1. 15
      apps/api/src/app/endpoints/watchlist/watchlist.service.ts
  2. 24
      apps/api/src/services/benchmark/benchmark.service.ts
  3. 4
      apps/client/src/app/components/home-watchlist/home-watchlist.component.ts
  4. 2
      apps/client/src/app/components/home-watchlist/home-watchlist.html
  5. 1
      libs/common/src/lib/interfaces/responses/watchlist-response.interface.ts

15
apps/api/src/app/endpoints/watchlist/watchlist.service.ts

@ -106,7 +106,8 @@ export class WatchlistService {
return { dataSource, symbol }; return { dataSource, symbol };
}) })
}); });
const symbolProfiles = await this.symbolProfileService.getSymbolProfiles(
const assetProfiles = await this.symbolProfileService.getSymbolProfiles(
user.watchlist user.watchlist
); );
@ -116,19 +117,23 @@ export class WatchlistService {
dataSource, dataSource,
symbol symbol
}); });
const performancePercent = const performancePercent =
this.benchmarkService.calculateChangeInPercentage( this.benchmarkService.calculateChangeInPercentage(
allTimeHigh?.marketPrice, allTimeHigh?.marketPrice,
quotes[symbol]?.marketPrice quotes[symbol]?.marketPrice
); );
const symbolProfile = symbolProfiles.find((profile) => {
const assetProfile = assetProfiles.find((profile) => {
return profile.dataSource === dataSource && profile.symbol === symbol; return profile.dataSource === dataSource && profile.symbol === symbol;
}); });
return { return {
dataSource, dataSource,
symbol, symbol,
name: symbolProfile?.name, marketCondition:
this.benchmarkService.getMarketCondition(performancePercent),
name: assetProfile?.name,
performances: { performances: {
allTimeHigh: { allTimeHigh: {
date: allTimeHigh?.date, 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);
});
} }
} }

24
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({ private async calculateAndCacheBenchmarks({
enableSharing = false enableSharing = false
}): Promise<BenchmarkResponse['benchmarks']> { }): Promise<BenchmarkResponse['benchmarks']> {
@ -302,16 +314,4 @@ export class BenchmarkService {
return benchmarks; 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';
}
}
} }

4
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)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe(({ watchlist }) => { .subscribe(({ watchlist }) => {
this.watchlist = watchlist.map( this.watchlist = watchlist.map(
({ dataSource, name, performances, symbol }) => ({ ({ dataSource, marketCondition, name, performances, symbol }) => ({
dataSource, dataSource,
marketCondition,
name, name,
performances, performances,
symbol, symbol,
marketCondition: null,
trend50d: 'UNKNOWN' as BenchmarkTrend, trend50d: 'UNKNOWN' as BenchmarkTrend,
trend200d: 'UNKNOWN' as BenchmarkTrend trend200d: 'UNKNOWN' as BenchmarkTrend
}) })

2
apps/client/src/app/components/home-watchlist/home-watchlist.html

@ -7,7 +7,7 @@
} }
</span> </span>
</h1> </h1>
<div class="mb-3 row"> <div class="row">
<div class="col-xs-12 col-md-8 offset-md-2"> <div class="col-xs-12 col-md-8 offset-md-2">
<gf-benchmark <gf-benchmark
[benchmarks]="watchlist" [benchmarks]="watchlist"

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 & {
marketCondition: Benchmark['marketCondition'];
name: string; name: string;
performances: Benchmark['performances']; performances: Benchmark['performances'];
})[]; })[];

Loading…
Cancel
Save