diff --git a/apps/api/src/services/queues/data-gathering/data-gathering.processor.ts b/apps/api/src/services/queues/data-gathering/data-gathering.processor.ts index 008603fa8..b49b30cc8 100644 --- a/apps/api/src/services/queues/data-gathering/data-gathering.processor.ts +++ b/apps/api/src/services/queues/data-gathering/data-gathering.processor.ts @@ -125,6 +125,7 @@ export class DataGatheringProcessor { const data: Prisma.MarketDataUpdateInput[] = []; let lastMarketPrice: number; + let numberOfMarketDataItemsToKeep = 0; while ( isBefore( @@ -139,15 +140,13 @@ export class DataGatheringProcessor { ) ) ) { - if ( + const marketPriceOfDataProvider = historicalData[assetProfileIdentifier]?.[ format(currentDate, DATE_FORMAT) - ]?.marketPrice - ) { - lastMarketPrice = - historicalData[assetProfileIdentifier]?.[ - format(currentDate, DATE_FORMAT) - ]?.marketPrice; + ]?.marketPrice; + + if (marketPriceOfDataProvider) { + lastMarketPrice = marketPriceOfDataProvider; } if (lastMarketPrice) { @@ -158,11 +157,21 @@ export class DataGatheringProcessor { marketPrice: lastMarketPrice, state: 'CLOSE' }); + + if (marketPriceOfDataProvider) { + numberOfMarketDataItemsToKeep = data.length; + } } currentDate = addDays(currentDate, 1); } + // A gap at the end means that the market data is not available yet, in + // contrast to a gap in between, which means that the market was closed. + // Therefore, the market prices which are carried forward after the last + // market price of the data provider are discarded. + data.splice(numberOfMarketDataItemsToKeep); + if (force) { await this.marketDataService.replaceForSymbol({ data, diff --git a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts b/apps/api/src/services/queues/data-gathering/data-gathering.service.ts index 968acead5..9596b7614 100644 --- a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts +++ b/apps/api/src/services/queues/data-gathering/data-gathering.service.ts @@ -310,9 +310,9 @@ export class DataGatheringService { }); const marketPrice = - historicalData[getAssetProfileIdentifier({ dataSource, symbol })][ + historicalData[getAssetProfileIdentifier({ dataSource, symbol })]?.[ format(date, DATE_FORMAT) - ].marketPrice; + ]?.marketPrice; if (marketPrice) { return await this.prismaService.marketData.upsert({