fix: Correct interval format and enhance data fetching error handling in ATR-EMA scanner

This commit is contained in:
Bobby (aider) 2025-02-08 10:53:27 -08:00
parent 86686125f3
commit 114e0f6165

View File

@ -56,8 +56,19 @@ def run_atr_ema_target_scanner(min_price: float, max_price: float, min_volume: i
for ticker, current_price, current_volume, last_update in stocks:
try:
df = get_stock_data(ticker, start_date, end_date, "1D")
if df.empty or len(df) < 50:
# Validate interval and fetch data
VALID_INTERVALS = ["1d", "5m", "15m", "30m", "1h", "4h", "1w"]
try:
df = get_stock_data(ticker, start_date, end_date, "1d")
if df.empty or len(df) < 50:
print(f"⚠️ {ticker}: Insufficient historical data ({len(df)} bars)")
continue
if "1d" not in VALID_INTERVALS:
raise ValueError(f"Invalid interval format. Must be one of: {VALID_INTERVALS}")
except Exception as e:
print(f"❌ Data fetch failed for {ticker}: {str(e)}")
continue
results = indicator.calculate(df)
@ -123,4 +134,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}")
print(f"❌ Error during scan: {e}")