|
|
@ -2,8 +2,7 @@ import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.se
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
DATA_GATHERING_QUEUE,
|
|
|
|
DATA_GATHERING_QUEUE,
|
|
|
|
GATHER_HISTORICAL_MARKET_DATA_PROCESS,
|
|
|
|
GATHER_HISTORICAL_MARKET_DATA_PROCESS,
|
|
|
|
GATHER_HISTORICAL_MARKET_DATA_PROCESS_OPTIONS,
|
|
|
|
GATHER_HISTORICAL_MARKET_DATA_PROCESS_OPTIONS
|
|
|
|
QUEUE_JOB_STATUS_LIST
|
|
|
|
|
|
|
|
} from '@ghostfolio/common/config';
|
|
|
|
} from '@ghostfolio/common/config';
|
|
|
|
import { DATE_FORMAT, resetHours } from '@ghostfolio/common/helper';
|
|
|
|
import { DATE_FORMAT, resetHours } from '@ghostfolio/common/helper';
|
|
|
|
import { UniqueAsset } from '@ghostfolio/common/interfaces';
|
|
|
|
import { UniqueAsset } from '@ghostfolio/common/interfaces';
|
|
|
@ -34,17 +33,14 @@ export class DataGatheringService {
|
|
|
|
private readonly symbolProfileService: SymbolProfileService
|
|
|
|
private readonly symbolProfileService: SymbolProfileService
|
|
|
|
) {}
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
|
|
public async addJobToQueue(name: string, data: any, options?: JobOptions) {
|
|
|
|
public async addJobToQueue(name: string, data: any, opts?: JobOptions) {
|
|
|
|
const hasJob = await this.hasJob(name, data);
|
|
|
|
return this.dataGatheringQueue.add(name, data, opts);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (hasJob) {
|
|
|
|
public async addJobsToQueue(
|
|
|
|
Logger.log(
|
|
|
|
jobs: { data: any; name: string; opts?: JobOptions }[]
|
|
|
|
`Job ${name} with data ${JSON.stringify(data)} already exists.`,
|
|
|
|
) {
|
|
|
|
'DataGatheringService'
|
|
|
|
return this.dataGatheringQueue.addBulk(jobs);
|
|
|
|
);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return this.dataGatheringQueue.add(name, data, options);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async gather7Days() {
|
|
|
|
public async gather7Days() {
|
|
|
@ -209,17 +205,22 @@ export class DataGatheringService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async gatherSymbols(aSymbolsWithStartDate: IDataGatheringItem[]) {
|
|
|
|
public async gatherSymbols(aSymbolsWithStartDate: IDataGatheringItem[]) {
|
|
|
|
for (const { dataSource, date, symbol } of aSymbolsWithStartDate) {
|
|
|
|
await this.addJobsToQueue(
|
|
|
|
await this.addJobToQueue(
|
|
|
|
aSymbolsWithStartDate.map(({ dataSource, date, symbol }) => {
|
|
|
|
GATHER_HISTORICAL_MARKET_DATA_PROCESS,
|
|
|
|
return {
|
|
|
|
{
|
|
|
|
data: {
|
|
|
|
dataSource,
|
|
|
|
dataSource,
|
|
|
|
date,
|
|
|
|
date,
|
|
|
|
symbol
|
|
|
|
symbol
|
|
|
|
},
|
|
|
|
},
|
|
|
|
GATHER_HISTORICAL_MARKET_DATA_PROCESS_OPTIONS
|
|
|
|
name: GATHER_HISTORICAL_MARKET_DATA_PROCESS,
|
|
|
|
);
|
|
|
|
opts: {
|
|
|
|
}
|
|
|
|
...GATHER_HISTORICAL_MARKET_DATA_PROCESS_OPTIONS,
|
|
|
|
|
|
|
|
jobId: `${dataSource}-${symbol}-${format(date, DATE_FORMAT)}`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async getSymbolsMax(): Promise<IDataGatheringItem[]> {
|
|
|
|
public async getSymbolsMax(): Promise<IDataGatheringItem[]> {
|
|
|
@ -341,18 +342,4 @@ export class DataGatheringService {
|
|
|
|
|
|
|
|
|
|
|
|
return [...currencyPairsToGather, ...symbolProfilesToGather];
|
|
|
|
return [...currencyPairsToGather, ...symbolProfilesToGather];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async hasJob(name: string, data: any) {
|
|
|
|
|
|
|
|
const jobs = await this.dataGatheringQueue.getJobs(
|
|
|
|
|
|
|
|
QUEUE_JOB_STATUS_LIST.filter((status) => {
|
|
|
|
|
|
|
|
return status !== 'completed';
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return jobs.some((job) => {
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
job.name === name && JSON.stringify(job.data) === JSON.stringify(data)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|