Browse Source
Add date to markets overview by benchmarks (#2436)
* Add date
* Update changelog
pull/2462/head^2
Kevin
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
20 additions and
9 deletions
-
CHANGELOG.md
-
apps/api/src/app/benchmark/benchmark.service.ts
-
apps/api/src/services/market-data/market-data.service.ts
-
libs/common/src/lib/interfaces/benchmark.interface.ts
|
|
@ -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 |
|
|
|
|
|
@ -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 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
@ -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({ |
|
|
|
|
|
@ -5,6 +5,7 @@ export interface Benchmark { |
|
|
|
name: EnhancedSymbolProfile['name']; |
|
|
|
performances: { |
|
|
|
allTimeHigh: { |
|
|
|
date: Date; |
|
|
|
performancePercent: number; |
|
|
|
}; |
|
|
|
}; |
|
|
|