fix: Remove nested try block and fix indentation in SQL query
This commit is contained in:
parent
819c91ff4a
commit
1b852b2d8d
@ -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]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user