Browse Source

add new property for benchmark interface

- adjust get max method
pull/2436/head
Kevin Lien 2 years ago
committed by Thomas
parent
commit
6ed7d0ab9d
  1. 10
      apps/api/src/app/benchmark/benchmark.service.ts
  2. 33
      apps/api/src/services/market-data/market-data.service.ts
  3. 1
      libs/common/src/lib/interfaces/benchmark.interface.ts

10
apps/api/src/app/benchmark/benchmark.service.ts

@ -64,7 +64,7 @@ export class BenchmarkService {
const benchmarkAssetProfiles = await this.getBenchmarkAssetProfiles(); const benchmarkAssetProfiles = await this.getBenchmarkAssetProfiles();
const promises: Promise<number>[] = []; const promises: Promise<{ marketPrice: number; date: Date }>[] = [];
const quotes = await this.dataProviderService.getQuotes({ const quotes = await this.dataProviderService.getQuotes({
items: benchmarkAssetProfiles.map(({ dataSource, symbol }) => { items: benchmarkAssetProfiles.map(({ dataSource, symbol }) => {
@ -85,15 +85,14 @@ export class BenchmarkService {
let performancePercentFromAllTimeHigh = 0; let performancePercentFromAllTimeHigh = 0;
if (allTimeHigh && marketPrice) { if (allTimeHigh && allTimeHigh.marketPrice && marketPrice) {
performancePercentFromAllTimeHigh = this.calculateChangeInPercentage( performancePercentFromAllTimeHigh = this.calculateChangeInPercentage(
allTimeHigh, allTimeHigh.marketPrice,
marketPrice marketPrice
); );
} else { } else {
storeInCache = false; storeInCache = false;
} }
return { return {
marketCondition: this.getMarketCondition( marketCondition: this.getMarketCondition(
performancePercentFromAllTimeHigh performancePercentFromAllTimeHigh
@ -101,7 +100,8 @@ export class BenchmarkService {
name: benchmarkAssetProfiles[index].name, name: benchmarkAssetProfiles[index].name,
performances: { performances: {
allTimeHigh: { allTimeHigh: {
performancePercent: performancePercentFromAllTimeHigh performancePercent: performancePercentFromAllTimeHigh,
date: allTimeHigh.date
} }
} }
}; };

33
apps/api/src/services/market-data/market-data.service.ts

@ -39,18 +39,27 @@ export class MarketDataService {
}); });
} }
public async getMax({ dataSource, symbol }: UniqueAsset): Promise<number> { public async getMax({
const aggregations = await this.prismaService.marketData.aggregate({ dataSource,
_max: { symbol
marketPrice: true }: UniqueAsset): Promise<{ marketPrice: number; date: Date }> {
}, const highestMarketPriceDataRow =
where: { await this.prismaService.marketData.findFirst({
dataSource, select: {
symbol marketPrice: true,
} date: true
}); },
where: {
return aggregations._max.marketPrice; dataSource,
symbol
},
orderBy: [
{
marketPrice: 'desc'
}
]
});
return highestMarketPriceDataRow;
} }
public async getRange({ public async getRange({

1
libs/common/src/lib/interfaces/benchmark.interface.ts

@ -6,6 +6,7 @@ export interface Benchmark {
performances: { performances: {
allTimeHigh: { allTimeHigh: {
performancePercent: number; performancePercent: number;
date: Date;
}; };
}; };
} }

Loading…
Cancel
Save