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
+23 -9
View File
@@ -35,6 +35,28 @@ def ctp_commission_to_fee_fields(data: dict, ths_code: str) -> dict:
}
def _collect_main_ths_codes() -> list[str]:
"""从主力列表收集同花顺合约代码(供 CTP 手续费查询)。"""
from datetime import date
from symbols import PRODUCTS, build_ths_code, list_main_contracts_grouped
symbols: list[str] = []
for group in list_main_contracts_grouped():
for item in group.get("items") or []:
ths = (item.get("ths_code") or item.get("ths") or item.get("code") or "").strip()
if ths and not ths.endswith("888"):
symbols.append(ths)
if symbols:
return symbols
today = date.today()
for p in PRODUCTS:
symbols.append(build_ths_code(p, today.year, today.month))
return symbols
def sync_fees_from_ctp(mode: str, *, max_symbols: int = 80) -> tuple[int, str]:
"""CTP 已连接时,按主力合约查询手续费并写入 fee_ratessource=ctp)。"""
bridge = get_bridge()
@@ -45,15 +67,7 @@ def sync_fees_from_ctp(mode: str, *, max_symbols: int = 80) -> tuple[int, str]:
if not bridge.ping():
return 0, "CTP 连接无效,请重连"
from symbols import list_main_contracts_grouped
mains = list_main_contracts_grouped()
symbols: list[str] = []
for g in mains:
ths = (g.get("ths") or g.get("code") or "").strip()
if ths:
symbols.append(ths)
symbols = symbols[:max_symbols]
symbols = _collect_main_ths_codes()[:max_symbols]
if not symbols:
return 0, "无主力合约列表"