This commit is contained in:
sam 2025-10-06 12:41:56 +08:00
parent 15aa959c9a
commit 3351ca6b5a

View File

@ -13,17 +13,22 @@ from app.utils.db import db_session
from app.ui.shared import LOGGER, LOG_EXTRA from app.ui.shared import LOGGER, LOG_EXTRA
def _load_stock_options(limit: int = 500) -> list[str]: def _load_stock_options(limit: int = 500, min_history: int = 30) -> list[str]:
try: try:
with db_session(read_only=True) as conn: with db_session(read_only=True) as conn:
rows = conn.execute( rows = conn.execute(
""" """
SELECT DISTINCT ts_code SELECT ts_code
FROM (
SELECT ts_code, MAX(trade_date) AS latest_date, COUNT(*) AS history_rows
FROM daily FROM daily
ORDER BY trade_date DESC GROUP BY ts_code
)
WHERE history_rows >= ?
ORDER BY ts_code ASC
LIMIT ? LIMIT ?
""", """,
(limit,), (min_history, limit),
).fetchall() ).fetchall()
except Exception: # noqa: BLE001 except Exception: # noqa: BLE001
LOGGER.exception("加载股票列表失败", extra=LOG_EXTRA) LOGGER.exception("加载股票列表失败", extra=LOG_EXTRA)
@ -85,6 +90,11 @@ def render_market_visualization() -> None:
selection = st.selectbox("选择标的", options, index=0) selection = st.selectbox("选择标的", options, index=0)
ts_code = _parse_ts_code(selection) ts_code = _parse_ts_code(selection)
manual_input = st.text_input("或直接输入标的代码", value=ts_code, key="market_manual_ts_code")
if manual_input:
manual_ts = manual_input.strip().upper()
if manual_ts:
ts_code = manual_ts
min_date, max_date = _load_trade_date_range(ts_code) min_date, max_date = _load_trade_date_range(ts_code)
if not max_date: if not max_date:
st.info("所选标的暂无可视化数据,请先同步行情。") st.info("所选标的暂无可视化数据,请先同步行情。")