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: with create_client() as client:
# Query to get stocks meeting criteria with their latest data # Query to get stocks meeting criteria with their latest data
query = f""" query = f"""
WITH latest_data AS ( WITH latest_data AS (
SELECT SELECT
ticker, ticker,
argMax(close, window_start) as last_close, argMax(close, window_start) as last_close,
sum(volume) as total_volume, sum(volume) as total_volume,
max(window_start) as last_update max(window_start) as last_update
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 toDateTime(window_start/1000000000) <= now() AND toDateTime(window_start/1000000000) <= now()
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}
) )
SELECT SELECT
ticker, ticker,
last_close, last_close,
total_volume, total_volume,
last_update last_update
FROM latest_data FROM latest_data
ORDER BY ticker 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]
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]