feat: Add date validation to stock data queries
This commit is contained in:
parent
69f0bd532c
commit
5b07a565f9
@ -32,6 +32,7 @@ def run_atr_ema_target_scanner(min_price: float, max_price: float, min_volume: i
|
|||||||
sum(transactions) AS transaction_count
|
sum(transactions) AS transaction_count
|
||||||
FROM stock_db.stock_prices
|
FROM stock_db.stock_prices
|
||||||
WHERE window_start BETWEEN {start_ts} AND {end_ts}
|
WHERE window_start BETWEEN {start_ts} AND {end_ts}
|
||||||
|
AND toYear(window_start) <= {end_date.year}
|
||||||
GROUP BY ticker
|
GROUP BY ticker
|
||||||
HAVING last_close BETWEEN {min_price} AND {max_price}
|
HAVING last_close BETWEEN {min_price} AND {max_price}
|
||||||
AND total_volume >= {min_volume}
|
AND total_volume >= {min_volume}
|
||||||
@ -83,6 +84,14 @@ def run_atr_ema_target_scanner(min_price: float, max_price: float, min_volume: i
|
|||||||
# Get historical data
|
# Get historical data
|
||||||
df = get_stock_data(ticker, start_date, end_date, interval)
|
df = get_stock_data(ticker, start_date, end_date, interval)
|
||||||
|
|
||||||
|
# Add date validation
|
||||||
|
if not df.empty:
|
||||||
|
max_date = df['date'].max()
|
||||||
|
min_date = df['date'].min()
|
||||||
|
if max_date.year > end_date.year or min_date.year < (end_date.year - 1):
|
||||||
|
print(f"⚠️ {ticker}: Invalid date range ({min_date.date()} to {max_date.date()})")
|
||||||
|
continue
|
||||||
|
|
||||||
# Enhanced validation with debugging
|
# Enhanced validation with debugging
|
||||||
if df.empty:
|
if df.empty:
|
||||||
print(f"⚠️ {ticker}: Empty DataFrame")
|
print(f"⚠️ {ticker}: Empty DataFrame")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user