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)}")
|
print(f"Error fetching data for {ticker}: {str(e)}")
|
||||||
return pd.DataFrame()
|
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"""
|
"""Get tickers that meet the price and volume criteria"""
|
||||||
client = create_client()
|
client = create_client()
|
||||||
yesterday = (datetime.now() - timedelta(days=1)).date()
|
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"""
|
query = f"""
|
||||||
SELECT DISTINCT ticker
|
SELECT DISTINCT ticker
|
||||||
FROM stock_db.stock_prices_daily
|
FROM stock_db.{table}
|
||||||
WHERE date = '{yesterday}'
|
WHERE {date_condition}
|
||||||
AND close BETWEEN {min_price} AND {max_price}
|
AND close BETWEEN {min_price} AND {max_price}
|
||||||
AND volume >= {min_volume}
|
AND volume >= {min_volume}
|
||||||
|
ORDER BY ticker ASC
|
||||||
"""
|
"""
|
||||||
|
|
||||||
result = client.query(query)
|
try:
|
||||||
return [row[0] for row in result.result_rows]
|
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:
|
def run_sunny_scanner(min_price: float, max_price: float, min_volume: int) -> None:
|
||||||
"""Run the SunnyBand scanner and save results"""
|
"""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
|
# Get valid tickers
|
||||||
print("\nFetching qualified stocks...")
|
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:
|
if not tickers:
|
||||||
print("No stocks found matching your criteria.")
|
print("No stocks found matching your criteria.")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user