Browse Source

Fix positive performance from all time high

pull/8012/head
Thomas Kaul 2 weeks ago
parent
commit
8f6888a1a4
  1. 4
      apps/api/src/app/endpoints/watchlist/watchlist.service.ts
  2. 10
      apps/api/src/services/benchmark/benchmark.service.spec.ts
  3. 13
      apps/api/src/services/benchmark/benchmark.service.ts

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

@ -142,7 +142,9 @@ export class WatchlistService {
allTimeHigh: { allTimeHigh: {
date: allTimeHigh?.date, date: allTimeHigh?.date,
performancePercent: performancePercent:
performancePercent >= 0 ? 0 : performancePercent this.benchmarkService.getPerformancePercentFromAllTimeHigh(
performancePercent
)
} }
}, },
trend50d: trends.trend50d, trend50d: trends.trend50d,

10
apps/api/src/services/benchmark/benchmark.service.spec.ts

@ -24,4 +24,14 @@ describe('BenchmarkService', () => {
); );
expect(benchmarkService.getMarketCondition(-0.2)).toEqual('BEAR_MARKET'); expect(benchmarkService.getMarketCondition(-0.2)).toEqual('BEAR_MARKET');
}); });
it('getPerformancePercentFromAllTimeHigh', async () => {
expect(benchmarkService.getPerformancePercentFromAllTimeHigh(0.1)).toEqual(
0
);
expect(benchmarkService.getPerformancePercentFromAllTimeHigh(0)).toEqual(0);
expect(benchmarkService.getPerformancePercentFromAllTimeHigh(-0.1)).toEqual(
-0.1
);
});
}); });

13
apps/api/src/services/benchmark/benchmark.service.ts

@ -216,6 +216,12 @@ export class BenchmarkService {
} }
} }
public getPerformancePercentFromAllTimeHigh(performancePercent: number) {
const isAtAllTimeHigh = performancePercent >= 0;
return isAtAllTimeHigh ? 0 : performancePercent;
}
public async isBenchmark(symbolProfileId: string): Promise<boolean> { public async isBenchmark(symbolProfileId: string): Promise<boolean> {
const benchmarks = await this.getBenchmarksProperty(); const benchmarks = await this.getBenchmarksProperty();
@ -288,10 +294,9 @@ export class BenchmarkService {
performances: { performances: {
allTimeHigh: { allTimeHigh: {
date: allTimeHigh?.date, date: allTimeHigh?.date,
performancePercent: performancePercent: this.getPerformancePercentFromAllTimeHigh(
performancePercentFromAllTimeHigh >= 0 performancePercentFromAllTimeHigh
? 0 )
: performancePercentFromAllTimeHigh
} }
}, },
symbol: benchmarkAssetProfiles[index].symbol, symbol: benchmarkAssetProfiles[index].symbol,

Loading…
Cancel
Save