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

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({
enableSharing = false
}): Promise<BenchmarkResponse['benchmarks']> {
@ -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';
}
}
}

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))
.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
})

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

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

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

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

Loading…
Cancel
Save