refactor: Update stock data retrieval to use consistent 60-day lookback
This commit is contained in:
parent
1d04986a07
commit
bf4c5a1b94
@ -31,6 +31,10 @@ def get_stock_data(ticker: str, start_date: datetime, end_date: datetime, interv
|
||||
"""Fetch stock data from the database"""
|
||||
client = create_client()
|
||||
|
||||
# Always look back 60 days for proper DMA calculation
|
||||
today = datetime.now().date()
|
||||
start_date = today - timedelta(days=60)
|
||||
|
||||
if interval == "daily":
|
||||
table = "stock_prices_daily"
|
||||
date_col = "date"
|
||||
@ -44,7 +48,7 @@ def get_stock_data(ticker: str, start_date: datetime, end_date: datetime, interv
|
||||
volume
|
||||
FROM stock_db.{table}
|
||||
WHERE ticker = '{ticker}'
|
||||
AND {date_col} BETWEEN '{start_date.date()}' AND '{end_date.date()}'
|
||||
AND {date_col} BETWEEN '{start_date}' AND '{today}'
|
||||
ORDER BY date ASC
|
||||
"""
|
||||
else:
|
||||
@ -69,7 +73,7 @@ def get_stock_data(ticker: str, start_date: datetime, end_date: datetime, interv
|
||||
sum(volume) as volume
|
||||
FROM stock_db.{table}
|
||||
WHERE ticker = '{ticker}'
|
||||
AND {date_col} BETWEEN toUnixTimestamp('{start_date.date()}') AND toUnixTimestamp('{end_date.date()}')
|
||||
AND {date_col} BETWEEN toUnixTimestamp('{start_date}') AND toUnixTimestamp('{today}')
|
||||
GROUP BY interval_start
|
||||
ORDER BY interval_start ASC
|
||||
"""
|
||||
@ -166,12 +170,11 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int) -> No
|
||||
# Get user's preferred interval
|
||||
interval = get_interval_choice()
|
||||
|
||||
# Adjust date range based on interval
|
||||
# Set date range to 60 days for proper DMA calculation
|
||||
end_date = datetime.now()
|
||||
if interval == "daily":
|
||||
start_date = end_date - timedelta(days=60)
|
||||
else:
|
||||
start_date = end_date - timedelta(days=5) # Less history needed for intraday
|
||||
start_date = end_date - timedelta(days=60)
|
||||
|
||||
print(f"\nAnalyzing data from {start_date.date()} to {end_date.date()}")
|
||||
|
||||
# Get valid tickers
|
||||
print("\nFetching qualified stocks...")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user