diff --git a/apps/api/src/app/admin/admin.controller.ts b/apps/api/src/app/admin/admin.controller.ts index ab48ff5cc..2bd822fe2 100644 --- a/apps/api/src/app/admin/admin.controller.ts +++ b/apps/api/src/app/admin/admin.controller.ts @@ -220,8 +220,9 @@ export class AdminController { public async gatherSymbolForDate( @Param('dataSource') dataSource: DataSource, @Param('dateString') dateString: string, - @Param('symbol') symbol: string - ): Promise { + @Param('symbol') symbol: string, + @Query('dryRun') isDryRun?: boolean + ): Promise { if ( !hasPermission( this.request.user.permissions, @@ -246,6 +247,7 @@ export class AdminController { return this.dataGatheringService.gatherSymbolForDate({ dataSource, date, + isDryRun, symbol }); } diff --git a/apps/api/src/services/data-gathering/data-gathering.service.ts b/apps/api/src/services/data-gathering/data-gathering.service.ts index 421e0a176..54ef14416 100644 --- a/apps/api/src/services/data-gathering/data-gathering.service.ts +++ b/apps/api/src/services/data-gathering/data-gathering.service.ts @@ -21,7 +21,7 @@ import { import { BenchmarkProperty, UniqueAsset } from '@ghostfolio/common/interfaces'; import { InjectQueue } from '@nestjs/bull'; import { Inject, Injectable, Logger } from '@nestjs/common'; -import { DataSource } from '@prisma/client'; +import { DataSource, MarketDataState } from '@prisma/client'; import { JobOptions, Queue } from 'bull'; import { format, min, subDays, subYears } from 'date-fns'; import { isEmpty } from 'lodash'; @@ -84,10 +84,12 @@ export class DataGatheringService { public async gatherSymbolForDate({ dataSource, date, + isDryRun, symbol }: { dataSource: DataSource; date: Date; + isDryRun: boolean; symbol: string; }) { try { @@ -96,11 +98,23 @@ export class DataGatheringService { date, date ); - - var marketPrice = + const marketPrice = historicalData[symbol]?.[format(getYesterday(), DATE_FORMAT)] .marketPrice; + if (isDryRun) { + const date = new Date(); + return { + dataSource, + date, + marketPrice, + symbol, + createdAt: null, + id: null, + state: MarketDataState.INTRADAY + }; + } + if (marketPrice) { return await this.prismaService.marketData.upsert({ create: { @@ -116,9 +130,7 @@ export class DataGatheringService { } catch (error) { Logger.error(error, 'DataGatheringService'); } finally { - if (dataSource === 'MANUAL' && marketPrice !== undefined) - return marketPrice; - else return undefined; + return undefined; } } diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts index 9d205d127..f7c4fc57e 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts @@ -243,11 +243,19 @@ export class AssetProfileDialog implements OnDestroy, OnInit { public onTestScraper(symbol: string) { const today = new Date(); this.adminService - .gatherSymbol({ dataSource: 'MANUAL', date: today, symbol }) + .gatherSymbol({ + dataSource: 'MANUAL', + date: today, + isDryRun: true, + symbol + }) .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((response) => { - if (response !== null) alert('Current Market Price is: ' + response); - else alert('Please try again.'); + if (response !== null) { + alert($localize`Please try again.`); + } else { + alert($localize`Current Market Price is:` + ' ' + response); + } }); } diff --git a/apps/client/src/app/services/admin.service.ts b/apps/client/src/app/services/admin.service.ts index 0ca75fe2d..49e990b8c 100644 --- a/apps/client/src/app/services/admin.service.ts +++ b/apps/client/src/app/services/admin.service.ts @@ -175,14 +175,16 @@ export class AdminService { symbol }: UniqueAsset & { date?: Date; + } & { + isDryRun?: boolean; }) { let url = `/api/v1/admin/gather/${dataSource}/${symbol}`; if (date) { - url = `${url}/${format(date, DATE_FORMAT)}`; + url = `${url}/${format(date, DATE_FORMAT)}?dryRun=true`; } - return this.http.post(url, {}); + return this.http.post(url, {}); } public fetchSymbolForDate({