Fix market open price to show opening price instead of stale close

- 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 <noreply@anthropic.com>
This commit is contained in:
Michael Simard
2025-12-26 12:22:37 -06:00
parent 8792c03e64
commit e1485aa8df

View File

@@ -51,6 +51,17 @@ class FinnhubAPI(StockAPIBase):
current_price = float(quote['c']) # Current price current_price = float(quote['c']) # Current price
previous_close = float(quote['pc']) # Previous close 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: if current_price == 0 or previous_close == 0:
logger.warning(f"Invalid price data for ticker: {ticker}") logger.warning(f"Invalid price data for ticker: {ticker}")
@@ -59,10 +70,6 @@ class FinnhubAPI(StockAPIBase):
change_dollar = current_price - previous_close change_dollar = current_price - previous_close
change_percent = (change_dollar / previous_close) * 100 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 { return {
'ticker': ticker.upper(), 'ticker': ticker.upper(),
'company_name': company_name, 'company_name': company_name,