diff --git a/src/screener/t_sunnyband.py b/src/screener/t_sunnyband.py index f88b165..fdb7827 100644 --- a/src/screener/t_sunnyband.py +++ b/src/screener/t_sunnyband.py @@ -127,16 +127,23 @@ def get_valid_tickers(min_price: float, max_price: float, min_volume: int, inter print(f"\nFound {len(tickers)} stocks matching price and volume criteria") if interval != "daily": - # Now verify these tickers have intraday data today + # Now verify these tickers have intraday data in the last trading day + # Get the most recent trading day's timestamp range today = datetime.now().date() - market_open = int(datetime.combine(today, datetime.strptime("09:30", "%H:%M").time()).timestamp()) - market_close = int(datetime.combine(today, datetime.strptime("16:00", "%H:%M").time()).timestamp()) + yesterday_open = int(datetime.combine(yesterday, datetime.strptime("09:30", "%H:%M").time()).timestamp()) + yesterday_close = int(datetime.combine(yesterday, datetime.strptime("16:00", "%H:%M").time()).timestamp()) + today_open = int(datetime.combine(today, datetime.strptime("09:30", "%H:%M").time()).timestamp()) + today_close = int(datetime.combine(today, datetime.strptime("16:00", "%H:%M").time()).timestamp()) intraday_query = f""" SELECT DISTINCT ticker FROM stock_db.stock_prices WHERE ticker IN ({','.join([f"'{t}'" for t in tickers])}) - AND window_start BETWEEN {market_open} AND {market_close} + AND ( + (window_start BETWEEN {yesterday_open} AND {yesterday_close}) + OR + (window_start BETWEEN {today_open} AND {today_close}) + ) GROUP BY ticker HAVING count() >= 10 -- Ensure we have enough data points """