fix: Remove nested try block and fix indentation in SQL query

This commit is contained in:
Bobby (aider) 2025-02-08 20:55:11 -08:00
parent 819c91ff4a
commit 1b852b2d8d

View File

@ -216,30 +216,29 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int, portf
with create_client() as client:
# Query to get stocks meeting criteria with their latest data
query = f"""
WITH latest_data AS (
SELECT
ticker,
argMax(close, window_start) as last_close,
sum(volume) as total_volume,
max(window_start) as last_update
FROM stock_db.stock_prices
WHERE window_start BETWEEN {start_ts} AND {end_ts}
AND toDateTime(window_start/1000000000) <= now()
GROUP BY ticker
HAVING last_close BETWEEN {min_price} AND {max_price}
AND total_volume >= {min_volume}
)
SELECT
ticker,
last_close,
total_volume,
last_update
FROM latest_data
ORDER BY ticker
"""
WITH latest_data AS (
SELECT
ticker,
argMax(close, window_start) as last_close,
sum(volume) as total_volume,
max(window_start) as last_update
FROM stock_db.stock_prices
WHERE window_start BETWEEN {start_ts} AND {end_ts}
AND toDateTime(window_start/1000000000) <= now()
GROUP BY ticker
HAVING last_close BETWEEN {min_price} AND {max_price}
AND total_volume >= {min_volume}
)
SELECT
ticker,
last_close,
total_volume,
last_update
FROM latest_data
ORDER BY ticker
"""
try:
result = client.query(query)
result = client.query(query)
qualified_stocks = [(row[0], row[1], row[2], row[3]) for row in result.result_rows]
qualified_stocks = [(row[0], row[1], row[2], row[3]) for row in result.result_rows]