From 8ecc2bd654bd5dbdc42bb21bd9e73a55e8d4f2f0 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 22 Aug 2026 11:21:13 +0200 Subject: [PATCH] Fix missing close price in historical market data of Yahoo Finance service --- .../yahoo-finance/yahoo-finance.service.ts | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts index 9b0366168..d0c7a204a 100644 --- a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts +++ b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts @@ -143,30 +143,39 @@ export class YahooFinanceService implements DataProviderInterface { [date: string]: DataProviderHistoricalResponse; }> { try { - const historicalResult = this.convertToHistoricalResult( - await this.yahooFinance.chart( - this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol( - symbol - ), - { - interval: '1d', - period1: format(from, DATE_FORMAT), - period2: format( - isSameDay(from, to) ? addDays(to, 1) : to, - DATE_FORMAT - ) - } - ) + const chartResult = await this.yahooFinance.chart( + this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol( + symbol + ), + { + interval: '1d', + period1: format(from, DATE_FORMAT), + period2: format( + isSameDay(from, to) ? addDays(to, 1) : to, + DATE_FORMAT + ) + } ); + const historicalResult = this.convertToHistoricalResult(chartResult); + const response: { [date: string]: DataProviderHistoricalResponse; } = {}; - for (const historicalItem of historicalResult) { - response[format(historicalItem.date, DATE_FORMAT)] = { - marketPrice: historicalItem.close - }; + for (const { close, date } of historicalResult) { + // The chart endpoint can omit the close price of a historical item, for + // example if the daily data of an exchange has not been consolidated yet. + // In this case, the market price of the corresponding quote is taken. + const marketPrice = + close ?? + (isSameDay(date, chartResult.meta.regularMarketTime) + ? chartResult.meta.regularMarketPrice + : undefined); + + if (marketPrice) { + response[format(date, DATE_FORMAT)] = { marketPrice }; + } } return response;