From e1485aa8df47acdc49d6e2768172abe9a95fa1cd Mon Sep 17 00:00:00 2001 From: Michael Simard Date: Fri, 26 Dec 2025 12:22:37 -0600 Subject: [PATCH] Fix market open price to show opening price instead of stale close MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Extract opening price from Finnhub quote response (field 'o') - At market open, if current price equals previous close, use opening price - Prevents showing yesterday's close when market just opened at 9:30 AM ET - Adds logging when opening price is used 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- stock_api/finnhub_api.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/stock_api/finnhub_api.py b/stock_api/finnhub_api.py index b73d144..2aa0edb 100644 --- a/stock_api/finnhub_api.py +++ b/stock_api/finnhub_api.py @@ -51,6 +51,17 @@ class FinnhubAPI(StockAPIBase): current_price = float(quote['c']) # Current price previous_close = float(quote['pc']) # Previous close + open_price = float(quote.get('o', 0)) # Opening price + + # Use MarketHours utility for accurate market status + from market_hours import MarketHours + market_open = MarketHours.is_market_open() + + # At market open, if current price equals previous close and we have an open price, + # use the opening price as the current price (trades may not have updated yet) + if market_open and current_price == previous_close and open_price > 0: + current_price = open_price + logger.info(f"Using opening price for {ticker} at market open: ${open_price}") if current_price == 0 or previous_close == 0: logger.warning(f"Invalid price data for ticker: {ticker}") @@ -59,10 +70,6 @@ class FinnhubAPI(StockAPIBase): change_dollar = current_price - previous_close change_percent = (change_dollar / previous_close) * 100 - # Use MarketHours utility for accurate market status - from market_hours import MarketHours - market_open = MarketHours.is_market_open() - return { 'ticker': ticker.upper(), 'company_name': company_name,