"""Historical K-line loader for the backtest result chart. Reads daily bars from the A-share DB via sanguo_data.datareader.read_db_daily and returns plain dicts for the frontend candlestick chart. Task S1.5. """ from __future__ import annotations def load_kline(symbol: str, start: str, end: str, cfg=None) -> list[dict]: """Return [{datetime, open, high, low, close, volume, vt_symbol}, ...]. Args: symbol: Bare symbol e.g. "600000" (DB stores without exchange suffix). start: Start date YYYY-MM-DD. end: End date YYYY-MM-DD. cfg: Optional data config; None uses default data_platform.yaml. """ from sanguo_data.datareader import read_db_daily from sanguo_data.config import load_config, find_config_path if cfg is None: cfg = load_config(find_config_path()) bars = read_db_daily(symbol, start, end, cfg) return [ { "datetime": str(b.datetime), "open": b.open_price, "high": b.high_price, "low": b.low_price, "close": b.close_price, "volume": getattr(b, "volume", 0), "vt_symbol": getattr(b, "vt_symbol", symbol), } for b in bars ]