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,