refactor: Update SQL queries for consistent date handling in screeners

This commit is contained in:
Bobby (aider) 2025-02-09 00:32:58 -08:00
parent 0a5ffbcadb
commit bf6c5e0880

View File

@ -222,7 +222,7 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int, portf
window_start,
close,
volume,
toDate(toDateTime(window_start/1000000000)) as trade_date
toDateTime(toDateTime(window_start/1000000000)) as trade_date
FROM stock_db.stock_prices
WHERE window_start BETWEEN {start_ts} AND {end_ts}
AND toDateTime(window_start/1000000000) <= now()
@ -230,11 +230,11 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int, portf
daily_data AS (
SELECT
ticker,
trade_date,
toDate(trade_date) as trade_date,
argMax(close, window_start) as daily_close,
sum(volume) as daily_volume
FROM filtered_data
GROUP BY ticker, trade_date
GROUP BY ticker, toDate(trade_date)
HAVING daily_close BETWEEN {min_price} AND {max_price}
AND daily_volume >= {min_volume}
),
@ -243,7 +243,7 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int, portf
ticker,
argMax(daily_close, trade_date) as last_close,
sum(daily_volume) as total_volume,
max(trade_date) as last_update
max(toUnixTimestamp(trade_date)) as last_update
FROM daily_data
GROUP BY ticker
)