From 873fd537158b92c0a47b99f4fb0e0275a751212d Mon Sep 17 00:00:00 2001 From: Eduardo Marinho <87383586+SirZemar@users.noreply.github.com> Date: Wed, 12 Jun 2024 19:28:55 +0100 Subject: [PATCH] Feature/extend market data with currencies preset by activities count and date (#3460) * Extend market data with currencies preset by activities count and date * Update changelog --- CHANGELOG.md | 4 ++ apps/api/src/app/admin/admin.service.ts | 63 ++++++++++++------- .../interfaces/admin-market-data.interface.ts | 4 +- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddc7f796e..ddd17a698 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Extended the historical market data table with currencies preset by date and activities count in the admin control panel + ### Changed - Improved the language localization for German (`de`) diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts index 3323e775d..c061c996c 100644 --- a/apps/api/src/app/admin/admin.service.ts +++ b/apps/api/src/app/admin/admin.service.ts @@ -409,30 +409,49 @@ export class AdminService { by: ['dataSource', 'symbol'] }); - const marketData: AdminMarketDataItem[] = this.exchangeRateDataService - .getCurrencyPairs() - .map(({ dataSource, symbol }) => { - const marketDataItemCount = - marketDataItems.find((marketDataItem) => { - return ( - marketDataItem.dataSource === dataSource && - marketDataItem.symbol === symbol - ); - })?._count ?? 0; + const marketDataPromise: Promise[] = + this.exchangeRateDataService + .getCurrencyPairs() + .map(async ({ dataSource, symbol }) => { + const currency = symbol.replace(DEFAULT_CURRENCY, ''); + + const { _count, _min } = await this.prismaService.order.aggregate({ + _count: true, + _min: { + date: true + }, + where: { + SymbolProfile: { + currency + } + } + }); - return { - dataSource, - marketDataItemCount, - symbol, - assetClass: AssetClass.LIQUIDITY, - countriesCount: 0, - currency: symbol.replace(DEFAULT_CURRENCY, ''), - id: undefined, - name: symbol, - sectorsCount: 0 - }; - }); + const marketDataItemCount = + marketDataItems.find((marketDataItem) => { + return ( + marketDataItem.dataSource === dataSource && + marketDataItem.symbol === symbol + ); + })?._count ?? 0; + + return { + currency, + dataSource, + marketDataItemCount, + symbol, + activitiesCount: _count as number, + assetClass: AssetClass.LIQUIDITY, + assetSubClass: AssetSubClass.CASH, + countriesCount: 0, + date: _min.date, + id: undefined, + name: symbol, + sectorsCount: 0 + }; + }); + const marketData = await Promise.all(marketDataPromise); return { marketData, count: marketData.length }; } diff --git a/libs/common/src/lib/interfaces/admin-market-data.interface.ts b/libs/common/src/lib/interfaces/admin-market-data.interface.ts index 6f3a82a0b..d52ac03b9 100644 --- a/libs/common/src/lib/interfaces/admin-market-data.interface.ts +++ b/libs/common/src/lib/interfaces/admin-market-data.interface.ts @@ -6,13 +6,13 @@ export interface AdminMarketData { } export interface AdminMarketDataItem { - activitiesCount?: number; + activitiesCount: number; assetClass?: AssetClass; assetSubClass?: AssetSubClass; countriesCount: number; currency: string; dataSource: DataSource; - date?: Date; + date: Date; id: string; isBenchmark?: boolean; marketDataItemCount: number;