|
@ -21,7 +21,7 @@ import { |
|
|
import { BenchmarkProperty, UniqueAsset } from '@ghostfolio/common/interfaces'; |
|
|
import { BenchmarkProperty, UniqueAsset } from '@ghostfolio/common/interfaces'; |
|
|
import { InjectQueue } from '@nestjs/bull'; |
|
|
import { InjectQueue } from '@nestjs/bull'; |
|
|
import { Inject, Injectable, Logger } from '@nestjs/common'; |
|
|
import { Inject, Injectable, Logger } from '@nestjs/common'; |
|
|
import { DataSource } from '@prisma/client'; |
|
|
import { DataSource, MarketDataState } from '@prisma/client'; |
|
|
import { JobOptions, Queue } from 'bull'; |
|
|
import { JobOptions, Queue } from 'bull'; |
|
|
import { format, min, subDays, subYears } from 'date-fns'; |
|
|
import { format, min, subDays, subYears } from 'date-fns'; |
|
|
import { isEmpty } from 'lodash'; |
|
|
import { isEmpty } from 'lodash'; |
|
@ -84,10 +84,12 @@ export class DataGatheringService { |
|
|
public async gatherSymbolForDate({ |
|
|
public async gatherSymbolForDate({ |
|
|
dataSource, |
|
|
dataSource, |
|
|
date, |
|
|
date, |
|
|
|
|
|
isDryRun, |
|
|
symbol |
|
|
symbol |
|
|
}: { |
|
|
}: { |
|
|
dataSource: DataSource; |
|
|
dataSource: DataSource; |
|
|
date: Date; |
|
|
date: Date; |
|
|
|
|
|
isDryRun: boolean; |
|
|
symbol: string; |
|
|
symbol: string; |
|
|
}) { |
|
|
}) { |
|
|
try { |
|
|
try { |
|
@ -96,11 +98,23 @@ export class DataGatheringService { |
|
|
date, |
|
|
date, |
|
|
date |
|
|
date |
|
|
); |
|
|
); |
|
|
|
|
|
const marketPrice = |
|
|
var marketPrice = |
|
|
|
|
|
historicalData[symbol]?.[format(getYesterday(), DATE_FORMAT)] |
|
|
historicalData[symbol]?.[format(getYesterday(), DATE_FORMAT)] |
|
|
.marketPrice; |
|
|
.marketPrice; |
|
|
|
|
|
|
|
|
|
|
|
if (isDryRun) { |
|
|
|
|
|
const date = new Date(); |
|
|
|
|
|
return { |
|
|
|
|
|
dataSource, |
|
|
|
|
|
date, |
|
|
|
|
|
marketPrice, |
|
|
|
|
|
symbol, |
|
|
|
|
|
createdAt: null, |
|
|
|
|
|
id: null, |
|
|
|
|
|
state: MarketDataState.INTRADAY |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (marketPrice) { |
|
|
if (marketPrice) { |
|
|
return await this.prismaService.marketData.upsert({ |
|
|
return await this.prismaService.marketData.upsert({ |
|
|
create: { |
|
|
create: { |
|
@ -116,9 +130,7 @@ export class DataGatheringService { |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
Logger.error(error, 'DataGatheringService'); |
|
|
Logger.error(error, 'DataGatheringService'); |
|
|
} finally { |
|
|
} finally { |
|
|
if (dataSource === 'MANUAL' && marketPrice !== undefined) |
|
|
return undefined; |
|
|
return marketPrice; |
|
|
|
|
|
else return undefined; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|