feat: 行情K线优先CTP tick聚合,修复手续费同步主力列表解析

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-24 13:18:43 +08:00
parent 09f4649d79
commit 3fe4add8e1
8 changed files with 390 additions and 24 deletions
+30 -2
View File
@@ -221,6 +221,9 @@ def fetch_market_klines(
period: str,
db_path: Optional[str] = None,
force_remote: bool = False,
*,
trading_mode: Optional[str] = None,
prefer_ctp: bool = True,
) -> dict:
chart_sym = ths_to_sina_chart_symbol(symbol)
p = (period or "15m").lower()
@@ -232,8 +235,32 @@ def fetch_market_klines(
bars: list = []
source = "remote"
cached_at = None
ctp_connected = False
if db_path and chart_sym and not force_remote:
if prefer_ctp:
try:
from ctp_kline import fetch_ctp_klines
from vnpy_bridge import ctp_status
mode = trading_mode
if not mode:
try:
from app import get_setting
from trading_context import get_trading_mode
mode = get_trading_mode(get_setting)
except Exception:
mode = "simulation"
ctp_connected = bool(ctp_status(mode).get("connected"))
if ctp_connected:
ctp_bars = fetch_ctp_klines(symbol, p, mode)
if ctp_bars:
bars = ctp_bars
source = "ctp"
except Exception as exc:
logger.debug("ctp kline fetch failed %s %s: %s", symbol, p, exc)
if not bars and db_path and chart_sym and not force_remote:
try:
conn = connect_db(db_path)
cached = get_cached_entry(conn, chart_sym, p)
@@ -250,7 +277,7 @@ def fetch_market_klines(
if remote_bars:
bars = remote_bars
source = "remote"
if db_path and chart_sym:
if db_path and chart_sym and not ctp_connected:
try:
conn = connect_db(db_path)
ensure_kline_tables(conn)
@@ -290,6 +317,7 @@ def fetch_market_klines(
"prev_close": prev_close,
"source": source,
"cached_at": cached_at,
"ctp_connected": ctp_connected,
}