From 1b852b2d8deb01c0e99d0f35184b9536ab6c0161 Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Sat, 8 Feb 2025 20:55:11 -0800 Subject: [PATCH] fix: Remove nested try block and fix indentation in SQL query --- src/screener/t_sunnyband.py | 47 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/screener/t_sunnyband.py b/src/screener/t_sunnyband.py index 42a7515..25329be 100644 --- a/src/screener/t_sunnyband.py +++ b/src/screener/t_sunnyband.py @@ -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 - """ - - try: - result = client.query(query) + 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 + """ + + 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]