From bf6c5e0880801a60feae91c06da78c0d29cec54c Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Sun, 9 Feb 2025 00:32:58 -0800 Subject: [PATCH] refactor: Update SQL queries for consistent date handling in screeners --- src/screener/t_sunnyband.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/screener/t_sunnyband.py b/src/screener/t_sunnyband.py index 05f7c2d..cc29558 100644 --- a/src/screener/t_sunnyband.py +++ b/src/screener/t_sunnyband.py @@ -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 )