diff --git a/apps/api/src/app/benchmark/benchmark.service.ts b/apps/api/src/app/benchmark/benchmark.service.ts index 7fe1911a4..59d0bd296 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<{ marketPrice: number; date: Date }>[] = []; 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 && allTimeHigh.marketPrice && marketPrice) { performancePercentFromAllTimeHigh = this.calculateChangeInPercentage( - allTimeHigh, + allTimeHigh.marketPrice, marketPrice ); } else { storeInCache = false; } - return { marketCondition: this.getMarketCondition( performancePercentFromAllTimeHigh @@ -101,7 +100,8 @@ export class BenchmarkService { name: benchmarkAssetProfiles[index].name, performances: { allTimeHigh: { - performancePercent: performancePercentFromAllTimeHigh + performancePercent: performancePercentFromAllTimeHigh, + date: allTimeHigh.date } } }; 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..724cce689 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,27 @@ export class MarketDataService { }); } - public async getMax({ dataSource, symbol }: UniqueAsset): Promise { - const aggregations = await this.prismaService.marketData.aggregate({ - _max: { - marketPrice: true - }, - where: { - dataSource, - symbol - } - }); - - return aggregations._max.marketPrice; + public async getMax({ + dataSource, + symbol + }: UniqueAsset): Promise<{ marketPrice: number; date: Date }> { + const highestMarketPriceDataRow = + await this.prismaService.marketData.findFirst({ + select: { + marketPrice: true, + date: true + }, + where: { + dataSource, + symbol + }, + orderBy: [ + { + marketPrice: 'desc' + } + ] + }); + return highestMarketPriceDataRow; } 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..ac476c427 100644 --- a/libs/common/src/lib/interfaces/benchmark.interface.ts +++ b/libs/common/src/lib/interfaces/benchmark.interface.ts @@ -6,6 +6,7 @@ export interface Benchmark { performances: { allTimeHigh: { performancePercent: number; + date: Date; }; }; }