diff --git a/src/screener/t_atr_ema_v2.py b/src/screener/t_atr_ema_v2.py index ba144ab..3c29f5d 100644 --- a/src/screener/t_atr_ema_v2.py +++ b/src/screener/t_atr_ema_v2.py @@ -82,16 +82,23 @@ def run_atr_ema_target_scanner(min_price: float, max_price: float, min_volume: i try: df = get_stock_data(ticker, start_date, end_date, interval) - # **Check if DataFrame has expected columns** + # VALIDATION CHECKS - BEGIN + required_columns = ['date', 'open', 'high', 'low', 'close', 'volume'] if df.empty: - print(f"⚠️ No data found for {ticker}. Skipping.") + print(f"⚠️ {ticker}: Empty DataFrame from get_stock_data()") + continue + + missing_cols = set(required_columns) - set(df.columns) + if missing_cols: + print(f"⚠️ {ticker}: Missing columns {missing_cols} in DataFrame") + print(f"Actual columns: {df.columns.tolist()}") continue - missing_cols = [col for col in ["close", "open", "high", "low", "volume"] if col not in df.columns] - if missing_cols: - print(f"⚠️ {ticker} data is missing columns: {missing_cols}. Skipping.") - print(df.head()) # Debugging output + if 'close' not in df.columns: + print(f"⚠️ {ticker}: 'close' column missing, cannot process") + print(f"Available columns: {df.columns.tolist()}") continue + # VALIDATION CHECKS - END results = indicator.calculate(df) last_row = results.iloc[-1] @@ -155,4 +162,4 @@ def run_atr_ema_target_scanner(min_price: float, max_price: float, min_volume: i print("❌ No bullish signals found.") except Exception as e: - print(f"❌ Error during scan: {e}") \ No newline at end of file + print(f"❌ Error during scan: {e}") diff --git a/src/screener/t_sunnyband.py b/src/screener/t_sunnyband.py index 130f1bb..59a23e9 100644 --- a/src/screener/t_sunnyband.py +++ b/src/screener/t_sunnyband.py @@ -88,9 +88,12 @@ def get_stock_data(ticker: str, start_date: datetime, end_date: datetime, interv df = pd.DataFrame( result.result_rows, columns=['date', 'open', 'high', 'low', 'close', 'volume'] - ) + ).dropna(subset=['close']) # Filter out rows with null close prices # Convert date column if needed + if df.empty or 'close' not in df.columns: + return pd.DataFrame() + if df['date'].dtype == object: df['date'] = pd.to_datetime(df['date'])