3a0e75fdc1
- strategy_registry 枚举 vnpy_ctastrategy 策略(兜底 STRATEGY_NAMES)
- /strategy/list、/strategy/{name}/params
- /task/{id}/equity-curve、/daily-pnl、/trades(BacktestResult JSON 化)
- /kline(read_db_daily 历史 K 线)
- 9 tests passed(4 strategy_registry + 5 routes)
33 lines
1.1 KiB
Python
33 lines
1.1 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
|
|
|
|
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
|
|
]
|