refactor: Update get_valid_tickers to support intraday and daily intervals
This commit is contained in:
parent
971a5dd4a1
commit
abcdd561ca
@ -89,21 +89,40 @@ def get_stock_data(ticker: str, start_date: datetime, end_date: datetime, interv
|
||||
print(f"Error fetching data for {ticker}: {str(e)}")
|
||||
return pd.DataFrame()
|
||||
|
||||
def get_valid_tickers(min_price: float, max_price: float, min_volume: int) -> list:
|
||||
def get_valid_tickers(min_price: float, max_price: float, min_volume: int, interval: str) -> list:
|
||||
"""Get tickers that meet the price and volume criteria"""
|
||||
client = create_client()
|
||||
yesterday = (datetime.now() - timedelta(days=1)).date()
|
||||
|
||||
if interval == "daily":
|
||||
table = "stock_prices_daily"
|
||||
date_col = "date"
|
||||
date_condition = f"{date_col} = '{yesterday}'"
|
||||
else:
|
||||
table = "stock_prices"
|
||||
date_col = "window_start"
|
||||
# Get yesterday's timestamp range
|
||||
start_ts = int(datetime.combine(yesterday, datetime.min.time()).timestamp())
|
||||
end_ts = int(datetime.combine(yesterday, datetime.max.time()).timestamp())
|
||||
date_condition = f"{date_col} BETWEEN {start_ts} AND {end_ts}"
|
||||
|
||||
query = f"""
|
||||
SELECT DISTINCT ticker
|
||||
FROM stock_db.stock_prices_daily
|
||||
WHERE date = '{yesterday}'
|
||||
FROM stock_db.{table}
|
||||
WHERE {date_condition}
|
||||
AND close BETWEEN {min_price} AND {max_price}
|
||||
AND volume >= {min_volume}
|
||||
ORDER BY ticker ASC
|
||||
"""
|
||||
|
||||
result = client.query(query)
|
||||
return [row[0] for row in result.result_rows]
|
||||
try:
|
||||
result = client.query(query)
|
||||
tickers = [row[0] for row in result.result_rows]
|
||||
print(f"Found {len(tickers)} stocks matching price and volume criteria")
|
||||
return tickers
|
||||
except Exception as e:
|
||||
print(f"Error fetching tickers: {str(e)}")
|
||||
return []
|
||||
|
||||
def run_sunny_scanner(min_price: float, max_price: float, min_volume: int) -> None:
|
||||
"""Run the SunnyBand scanner and save results"""
|
||||
@ -122,7 +141,7 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int) -> No
|
||||
|
||||
# Get valid tickers
|
||||
print("\nFetching qualified stocks...")
|
||||
tickers = get_valid_tickers(min_price, max_price, min_volume)
|
||||
tickers = get_valid_tickers(min_price, max_price, min_volume, interval)
|
||||
|
||||
if not tickers:
|
||||
print("No stocks found matching your criteria.")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user