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 promises: Promise<number>[] = [];
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
}
}
};

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> {
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({

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

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

Loading…
Cancel
Save