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: try:
if stock_codes: if stock_codes:
print(f"批量查询 {len(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 = """ batch_price_query = """
WITH first_prices AS (SELECT code, SELECT
close as first_price \ code,
, ROW_NUMBER() OVER (PARTITION BY code ORDER BY timestamp ASC) as rn argMin(close, timestamp) as first_price,
FROM stock_minute argMax(close, timestamp) as last_price,
WHERE code IN %(codes)s (argMax(close, timestamp) - argMin(close, timestamp)) / argMin(close, timestamp) * 100 as change_pct,
AND timestamp >= %(start)s argMax(open, timestamp) as open_price,
AND timestamp <= %(end)s max(high) as high_price,
) \ min(low) as low_price,
, last_prices AS ( sum(volume) as volume,
SELECT sum(amt) as amount
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 FROM stock_minute
FROM stock_minute WHERE code IN %(codes)s
WHERE code IN %(codes)s AND timestamp >= %(start)s
AND timestamp >= %(start)s AND timestamp <= %(end)s
AND timestamp <= %(end)s GROUP BY code
) """
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 \
"""
price_data = client.execute(batch_price_query, { price_data = client.execute(batch_price_query, {
'codes': stock_codes, 'codes': tuple(stock_codes),
'start': start_datetime, 'start': start_datetime,
'end': end_datetime 'end': end_datetime
}) })
@@ -4691,7 +4690,7 @@ def api_event_related_stocks(event_id):
""" """
minute_data = client.execute(minute_chart_query, { minute_data = client.execute(minute_chart_query, {
'codes': stock_codes, 'codes': tuple(stock_codes),
'start': start_datetime, 'start': start_datetime,
'end': end_datetime 'end': end_datetime
}) })