Browse Source

Discard market prices carried forward beyond the data of the data provider

pull/7694/head
Thomas Kaul 1 week ago
parent
commit
c9d4d13056
  1. 21
      apps/api/src/services/queues/data-gathering/data-gathering.processor.ts
  2. 4
      apps/api/src/services/queues/data-gathering/data-gathering.service.ts

21
apps/api/src/services/queues/data-gathering/data-gathering.processor.ts

@ -125,6 +125,7 @@ export class DataGatheringProcessor {
const data: Prisma.MarketDataUpdateInput[] = []; const data: Prisma.MarketDataUpdateInput[] = [];
let lastMarketPrice: number; let lastMarketPrice: number;
let numberOfMarketDataItemsToKeep = 0;
while ( while (
isBefore( isBefore(
@ -139,15 +140,13 @@ export class DataGatheringProcessor {
) )
) )
) { ) {
if ( const marketPriceOfDataProvider =
historicalData[assetProfileIdentifier]?.[
format(currentDate, DATE_FORMAT)
]?.marketPrice
) {
lastMarketPrice =
historicalData[assetProfileIdentifier]?.[ historicalData[assetProfileIdentifier]?.[
format(currentDate, DATE_FORMAT) format(currentDate, DATE_FORMAT)
]?.marketPrice; ]?.marketPrice;
if (marketPriceOfDataProvider) {
lastMarketPrice = marketPriceOfDataProvider;
} }
if (lastMarketPrice) { if (lastMarketPrice) {
@ -158,11 +157,21 @@ export class DataGatheringProcessor {
marketPrice: lastMarketPrice, marketPrice: lastMarketPrice,
state: 'CLOSE' state: 'CLOSE'
}); });
if (marketPriceOfDataProvider) {
numberOfMarketDataItemsToKeep = data.length;
}
} }
currentDate = addDays(currentDate, 1); 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) { if (force) {
await this.marketDataService.replaceForSymbol({ await this.marketDataService.replaceForSymbol({
data, data,

4
apps/api/src/services/queues/data-gathering/data-gathering.service.ts

@ -310,9 +310,9 @@ export class DataGatheringService {
}); });
const marketPrice = const marketPrice =
historicalData[getAssetProfileIdentifier({ dataSource, symbol })][ historicalData[getAssetProfileIdentifier({ dataSource, symbol })]?.[
format(date, DATE_FORMAT) format(date, DATE_FORMAT)
].marketPrice; ]?.marketPrice;
if (marketPrice) { if (marketPrice) {
return await this.prismaService.marketData.upsert({ return await this.prismaService.marketData.upsert({

Loading…
Cancel
Save