diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e7a5f4e1..6fc130922 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- Extended the markets overview by benchmarks (date of last all time high) + ## 2.10.0 - 2023-10-09 ### Added diff --git a/apps/api/src/app/benchmark/benchmark.service.ts b/apps/api/src/app/benchmark/benchmark.service.ts index 7fe1911a4..2547e57cc 100644 --- a/apps/api/src/app/benchmark/benchmark.service.ts +++ b/apps/api/src/app/benchmark/benchmark.service.ts @@ -64,7 +64,7 @@ export class BenchmarkService { const benchmarkAssetProfiles = await this.getBenchmarkAssetProfiles(); - const promises: Promise[] = []; + const promises: Promise<{ date: Date; marketPrice: number }>[] = []; const quotes = await this.dataProviderService.getQuotes({ items: benchmarkAssetProfiles.map(({ dataSource, symbol }) => { @@ -85,15 +85,14 @@ export class BenchmarkService { let performancePercentFromAllTimeHigh = 0; - if (allTimeHigh && marketPrice) { + if (allTimeHigh?.marketPrice && marketPrice) { performancePercentFromAllTimeHigh = this.calculateChangeInPercentage( - allTimeHigh, + allTimeHigh.marketPrice, marketPrice ); } else { storeInCache = false; } - return { marketCondition: this.getMarketCondition( performancePercentFromAllTimeHigh @@ -101,6 +100,7 @@ export class BenchmarkService { name: benchmarkAssetProfiles[index].name, performances: { allTimeHigh: { + date: allTimeHigh.date, performancePercent: performancePercentFromAllTimeHigh } } diff --git a/apps/api/src/services/market-data/market-data.service.ts b/apps/api/src/services/market-data/market-data.service.ts index 414c247aa..5760096bf 100644 --- a/apps/api/src/services/market-data/market-data.service.ts +++ b/apps/api/src/services/market-data/market-data.service.ts @@ -39,18 +39,22 @@ export class MarketDataService { }); } - public async getMax({ dataSource, symbol }: UniqueAsset): Promise { - const aggregations = await this.prismaService.marketData.aggregate({ - _max: { + public async getMax({ dataSource, symbol }: UniqueAsset) { + return this.prismaService.marketData.findFirst({ + select: { + date: true, marketPrice: true }, + orderBy: [ + { + marketPrice: 'desc' + } + ], where: { dataSource, symbol } }); - - return aggregations._max.marketPrice; } public async getRange({ diff --git a/libs/common/src/lib/interfaces/benchmark.interface.ts b/libs/common/src/lib/interfaces/benchmark.interface.ts index 906e30759..d1a63e1f4 100644 --- a/libs/common/src/lib/interfaces/benchmark.interface.ts +++ b/libs/common/src/lib/interfaces/benchmark.interface.ts @@ -5,6 +5,7 @@ export interface Benchmark { name: EnhancedSymbolProfile['name']; performances: { allTimeHigh: { + date: Date; performancePercent: number; }; };