Files
sanguo_vnpy_v2/sanguo_api/kline.py
T
claude_dev 28aea67232 feat(s1): 回测核心端到端跑通(vnpy client 对齐)
- 修 submit_cta/optimize 策略字符串→类解析(get_strategy_class)
- cta_engine: worker 进程设 vnpy DB→quant_trading.db(修 0 根数据)
- equity_curve 取自 calculate_result 的 daily_df(修 get_all_daily_results 对象问题)
- kline 补 cfg(find_config_path 共享)
- 端到端冒烟通过:DoubleMaStrategy 600000 → equity111/pnl111/trades1/kline117
2026-07-07 06:21:17 +08:00

36 lines
1.2 KiB
Python

"""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
]