update pay ui

This commit is contained in:
2025-12-13 22:36:59 +08:00
parent 7ebe365b0a
commit 1471bf806a

View File

@@ -4609,42 +4609,41 @@ def api_event_related_stocks(event_id):
try:
if stock_codes:
print(f"批量查询 {len(stock_codes)} 只股票的价格数据...")
print(f" 股票代码: {stock_codes}")
print(f" 时间范围: {start_datetime}{end_datetime}")
# 3.1 批量查询价格和涨跌幅数据(使用子查询方式,避免窗口函数与 GROUP BY 冲突)
# 诊断:检查这些股票在 ClickHouse 中是否有数据
diag_query = """
SELECT code, MIN(timestamp) as min_ts, MAX(timestamp) as max_ts, COUNT(*) as cnt
FROM stock_minute
WHERE code IN %(codes)s
GROUP BY code
"""
diag_result = client.execute(diag_query, {'codes': tuple(stock_codes)})
print(f" 诊断 - 各股票数据情况: {diag_result}")
# 3.1 批量查询价格和涨跌幅数据(简化版,避免 CTE 兼容性问题)
# 使用 argMin/argMax 聚合函数获取第一条和最后一条记录的值
batch_price_query = """
WITH first_prices AS (SELECT code,
close as first_price \
, ROW_NUMBER() OVER (PARTITION BY code ORDER BY timestamp ASC) as rn
FROM stock_minute
WHERE code IN %(codes)s
AND timestamp >= %(start)s
AND timestamp <= %(end)s
) \
, last_prices AS (
SELECT
code, close as last_price, open as open_price, high as high_price, low as low_price, volume, amt as amount, ROW_NUMBER() OVER (PARTITION BY code ORDER BY timestamp DESC) as rn
code,
argMin(close, timestamp) as first_price,
argMax(close, timestamp) as last_price,
(argMax(close, timestamp) - argMin(close, timestamp)) / argMin(close, timestamp) * 100 as change_pct,
argMax(open, timestamp) as open_price,
max(high) as high_price,
min(low) as low_price,
sum(volume) as volume,
sum(amt) as amount
FROM stock_minute
WHERE code IN %(codes)s
AND timestamp >= %(start)s
AND timestamp <= %(end)s
)
SELECT fp.code, \
fp.first_price, \
lp.last_price, \
(lp.last_price - fp.first_price) / fp.first_price * 100 as change_pct, \
lp.open_price, \
lp.high_price, \
lp.low_price, \
lp.volume, \
lp.amount
FROM first_prices fp
INNER JOIN last_prices lp ON fp.code = lp.code
WHERE fp.rn = 1 \
AND lp.rn = 1 \
GROUP BY code
"""
price_data = client.execute(batch_price_query, {
'codes': stock_codes,
'codes': tuple(stock_codes),
'start': start_datetime,
'end': end_datetime
})
@@ -4691,7 +4690,7 @@ def api_event_related_stocks(event_id):
"""
minute_data = client.execute(minute_chart_query, {
'codes': stock_codes,
'codes': tuple(stock_codes),
'start': start_datetime,
'end': end_datetime
})