refactor: Update SQL queries for consistent date handling in screeners
This commit is contained in:
parent
0a5ffbcadb
commit
bf6c5e0880
@ -222,7 +222,7 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int, portf
|
|||||||
window_start,
|
window_start,
|
||||||
close,
|
close,
|
||||||
volume,
|
volume,
|
||||||
toDate(toDateTime(window_start/1000000000)) as trade_date
|
toDateTime(toDateTime(window_start/1000000000)) as trade_date
|
||||||
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()
|
||||||
@ -230,11 +230,11 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int, portf
|
|||||||
daily_data AS (
|
daily_data AS (
|
||||||
SELECT
|
SELECT
|
||||||
ticker,
|
ticker,
|
||||||
trade_date,
|
toDate(trade_date) as trade_date,
|
||||||
argMax(close, window_start) as daily_close,
|
argMax(close, window_start) as daily_close,
|
||||||
sum(volume) as daily_volume
|
sum(volume) as daily_volume
|
||||||
FROM filtered_data
|
FROM filtered_data
|
||||||
GROUP BY ticker, trade_date
|
GROUP BY ticker, toDate(trade_date)
|
||||||
HAVING daily_close BETWEEN {min_price} AND {max_price}
|
HAVING daily_close BETWEEN {min_price} AND {max_price}
|
||||||
AND daily_volume >= {min_volume}
|
AND daily_volume >= {min_volume}
|
||||||
),
|
),
|
||||||
@ -243,7 +243,7 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int, portf
|
|||||||
ticker,
|
ticker,
|
||||||
argMax(daily_close, trade_date) as last_close,
|
argMax(daily_close, trade_date) as last_close,
|
||||||
sum(daily_volume) as total_volume,
|
sum(daily_volume) as total_volume,
|
||||||
max(trade_date) as last_update
|
max(toUnixTimestamp(trade_date)) as last_update
|
||||||
FROM daily_data
|
FROM daily_data
|
||||||
GROUP BY ticker
|
GROUP BY ticker
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user