Browse Source

Changes attempted as per request.

pull/2546/head
Manushreshta B L 2 years ago
parent
commit
b5d64b0c30
  1. 6
      apps/api/src/app/admin/admin.controller.ts
  2. 24
      apps/api/src/services/data-gathering/data-gathering.service.ts
  3. 14
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts
  4. 6
      apps/client/src/app/services/admin.service.ts

6
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<MarketData | number> {
@Param('symbol') symbol: string,
@Query('dryRun') isDryRun?: boolean
): Promise<MarketData> {
if (
!hasPermission(
this.request.user.permissions,
@ -246,6 +247,7 @@ export class AdminController {
return this.dataGatheringService.gatherSymbolForDate({
dataSource,
date,
isDryRun,
symbol
});
}

24
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;
}
}

14
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);
}
});
}

6
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<MarketData | number | void>(url, {});
return this.http.post<MarketData | void>(url, {});
}
public fetchSymbolForDate({

Loading…
Cancel
Save