|
@ -31,7 +31,7 @@ export class DataGatheringService { |
|
|
private readonly configurationService: ConfigurationService, |
|
|
private readonly configurationService: ConfigurationService, |
|
|
private readonly dataProviderService: DataProviderService, |
|
|
private readonly dataProviderService: DataProviderService, |
|
|
private readonly ghostfolioScraperApi: GhostfolioScraperApiService, |
|
|
private readonly ghostfolioScraperApi: GhostfolioScraperApiService, |
|
|
private prisma: PrismaService |
|
|
private readonly prismaService: PrismaService |
|
|
) {} |
|
|
) {} |
|
|
|
|
|
|
|
|
public async gather7Days() { |
|
|
public async gather7Days() { |
|
@ -41,7 +41,7 @@ export class DataGatheringService { |
|
|
console.log('7d data gathering has been started.'); |
|
|
console.log('7d data gathering has been started.'); |
|
|
console.time('7d-data-gathering'); |
|
|
console.time('7d-data-gathering'); |
|
|
|
|
|
|
|
|
await this.prisma.property.create({ |
|
|
await this.prismaService.property.create({ |
|
|
data: { |
|
|
data: { |
|
|
key: 'LOCKED_DATA_GATHERING', |
|
|
key: 'LOCKED_DATA_GATHERING', |
|
|
value: new Date().toISOString() |
|
|
value: new Date().toISOString() |
|
@ -53,7 +53,7 @@ export class DataGatheringService { |
|
|
try { |
|
|
try { |
|
|
await this.gatherSymbols(symbols); |
|
|
await this.gatherSymbols(symbols); |
|
|
|
|
|
|
|
|
await this.prisma.property.upsert({ |
|
|
await this.prismaService.property.upsert({ |
|
|
create: { |
|
|
create: { |
|
|
key: 'LAST_DATA_GATHERING', |
|
|
key: 'LAST_DATA_GATHERING', |
|
|
value: new Date().toISOString() |
|
|
value: new Date().toISOString() |
|
@ -65,7 +65,7 @@ export class DataGatheringService { |
|
|
console.error(error); |
|
|
console.error(error); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
await this.prisma.property.delete({ |
|
|
await this.prismaService.property.delete({ |
|
|
where: { |
|
|
where: { |
|
|
key: 'LOCKED_DATA_GATHERING' |
|
|
key: 'LOCKED_DATA_GATHERING' |
|
|
} |
|
|
} |
|
@ -77,7 +77,7 @@ export class DataGatheringService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async gatherMax() { |
|
|
public async gatherMax() { |
|
|
const isDataGatheringLocked = await this.prisma.property.findUnique({ |
|
|
const isDataGatheringLocked = await this.prismaService.property.findUnique({ |
|
|
where: { key: 'LOCKED_DATA_GATHERING' } |
|
|
where: { key: 'LOCKED_DATA_GATHERING' } |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -85,7 +85,7 @@ export class DataGatheringService { |
|
|
console.log('Max data gathering has been started.'); |
|
|
console.log('Max data gathering has been started.'); |
|
|
console.time('max-data-gathering'); |
|
|
console.time('max-data-gathering'); |
|
|
|
|
|
|
|
|
await this.prisma.property.create({ |
|
|
await this.prismaService.property.create({ |
|
|
data: { |
|
|
data: { |
|
|
key: 'LOCKED_DATA_GATHERING', |
|
|
key: 'LOCKED_DATA_GATHERING', |
|
|
value: new Date().toISOString() |
|
|
value: new Date().toISOString() |
|
@ -97,7 +97,7 @@ export class DataGatheringService { |
|
|
try { |
|
|
try { |
|
|
await this.gatherSymbols(symbols); |
|
|
await this.gatherSymbols(symbols); |
|
|
|
|
|
|
|
|
await this.prisma.property.upsert({ |
|
|
await this.prismaService.property.upsert({ |
|
|
create: { |
|
|
create: { |
|
|
key: 'LAST_DATA_GATHERING', |
|
|
key: 'LAST_DATA_GATHERING', |
|
|
value: new Date().toISOString() |
|
|
value: new Date().toISOString() |
|
@ -109,7 +109,7 @@ export class DataGatheringService { |
|
|
console.error(error); |
|
|
console.error(error); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
await this.prisma.property.delete({ |
|
|
await this.prismaService.property.delete({ |
|
|
where: { |
|
|
where: { |
|
|
key: 'LOCKED_DATA_GATHERING' |
|
|
key: 'LOCKED_DATA_GATHERING' |
|
|
} |
|
|
} |
|
@ -139,7 +139,7 @@ export class DataGatheringService { |
|
|
currentData |
|
|
currentData |
|
|
)) { |
|
|
)) { |
|
|
try { |
|
|
try { |
|
|
await this.prisma.symbolProfile.upsert({ |
|
|
await this.prismaService.symbolProfile.upsert({ |
|
|
create: { |
|
|
create: { |
|
|
currency, |
|
|
currency, |
|
|
dataSource, |
|
|
dataSource, |
|
@ -203,7 +203,7 @@ export class DataGatheringService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
await this.prisma.marketData.create({ |
|
|
await this.prismaService.marketData.create({ |
|
|
data: { |
|
|
data: { |
|
|
symbol, |
|
|
symbol, |
|
|
date: currentDate, |
|
|
date: currentDate, |
|
@ -271,7 +271,7 @@ export class DataGatheringService { |
|
|
private async getSymbols7D(): Promise<IDataGatheringItem[]> { |
|
|
private async getSymbols7D(): Promise<IDataGatheringItem[]> { |
|
|
const startDate = subDays(resetHours(new Date()), 7); |
|
|
const startDate = subDays(resetHours(new Date()), 7); |
|
|
|
|
|
|
|
|
const distinctOrders = await this.prisma.order.findMany({ |
|
|
const distinctOrders = await this.prismaService.order.findMany({ |
|
|
distinct: ['symbol'], |
|
|
distinct: ['symbol'], |
|
|
orderBy: [{ symbol: 'asc' }], |
|
|
orderBy: [{ symbol: 'asc' }], |
|
|
select: { dataSource: true, symbol: true }, |
|
|
select: { dataSource: true, symbol: true }, |
|
@ -332,7 +332,7 @@ export class DataGatheringService { |
|
|
} |
|
|
} |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
const distinctOrders = await this.prisma.order.findMany({ |
|
|
const distinctOrders = await this.prismaService.order.findMany({ |
|
|
distinct: ['symbol'], |
|
|
distinct: ['symbol'], |
|
|
orderBy: [{ date: 'asc' }], |
|
|
orderBy: [{ date: 'asc' }], |
|
|
select: { dataSource: true, date: true, symbol: true }, |
|
|
select: { dataSource: true, date: true, symbol: true }, |
|
@ -354,7 +354,7 @@ export class DataGatheringService { |
|
|
private async getSymbolsProfileData(): Promise<IDataGatheringItem[]> { |
|
|
private async getSymbolsProfileData(): Promise<IDataGatheringItem[]> { |
|
|
const startDate = subDays(resetHours(new Date()), 7); |
|
|
const startDate = subDays(resetHours(new Date()), 7); |
|
|
|
|
|
|
|
|
const distinctOrders = await this.prisma.order.findMany({ |
|
|
const distinctOrders = await this.prismaService.order.findMany({ |
|
|
distinct: ['symbol'], |
|
|
distinct: ['symbol'], |
|
|
orderBy: [{ symbol: 'asc' }], |
|
|
orderBy: [{ symbol: 'asc' }], |
|
|
select: { dataSource: true, symbol: true } |
|
|
select: { dataSource: true, symbol: true } |
|
@ -371,11 +371,11 @@ export class DataGatheringService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private async isDataGatheringNeeded() { |
|
|
private async isDataGatheringNeeded() { |
|
|
const lastDataGathering = await this.prisma.property.findUnique({ |
|
|
const lastDataGathering = await this.prismaService.property.findUnique({ |
|
|
where: { key: 'LAST_DATA_GATHERING' } |
|
|
where: { key: 'LAST_DATA_GATHERING' } |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const isDataGatheringLocked = await this.prisma.property.findUnique({ |
|
|
const isDataGatheringLocked = await this.prismaService.property.findUnique({ |
|
|
where: { key: 'LOCKED_DATA_GATHERING' } |
|
|
where: { key: 'LOCKED_DATA_GATHERING' } |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|