Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Add date to markets overview by benchmarks (#2436)

Kevin6c66033eb443
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8e7a5f4e15..6fc1309224 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 7fe1911a48..2547e57cc9 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<number>[] = [];
+ 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 414c247aad..5760096bf8 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<number> {
- 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 906e30759e..d1a63e1f4f 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;
};
};