From ba2138e1cff16fe33765ded4a3de09f977bfbbc5 Mon Sep 17 00:00:00 2001 From: claude_dev Date: Tue, 7 Jul 2026 15:15:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(trader):=20volume=C3=97size(A=E8=82=A11?= =?UTF-8?q?=E6=89=8B=3D100=E8=82=A1)=20=E2=80=94=20DoubleMa=20=E7=9C=9F?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E5=9B=9E=E6=94=BE=20filled=3D3=20=E8=B7=91?= =?UTF-8?q?=E9=80=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sanguo_api/routes_paper.py | 4 ++-- sanguo_trader/cta_adapter.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sanguo_api/routes_paper.py b/sanguo_api/routes_paper.py index 13aede8..3ba236a 100644 --- a/sanguo_api/routes_paper.py +++ b/sanguo_api/routes_paper.py @@ -146,14 +146,14 @@ def _run_replay(db, aid, req: PaperCreateRequest): if cls is None: continue # 策略不可用(本机无 vnpy_ctastrategy)→ 跳过 cta = PaperCtaEngine(s.name, match_session=s.match_session, - listing_days=s.listing_days) + listing_days=s.listing_days, size=100) # A 股 1 手=100 股 vt_symbol = f"{s.symbol}.{guess_exchange(s.symbol).value}" strat = cls(cta, s.name, vt_symbol, s.params) # CtaTemplate(cta_engine, name, vt_symbol, setting) strat.trading = True # 允许 send_order(等价 on_start) try: from vnpy.trader.utility import ArrayManager if not hasattr(strat, "am"): - strat.am = ArrayManager(100) + strat.am = ArrayManager(20) # 默认 100 根才 inited,短区间不够;用 20 兼容 except Exception: pass cta.set_strategy(strat) diff --git a/sanguo_trader/cta_adapter.py b/sanguo_trader/cta_adapter.py index 3adc1f9..f451733 100644 --- a/sanguo_trader/cta_adapter.py +++ b/sanguo_trader/cta_adapter.py @@ -30,10 +30,11 @@ class PaperCtaEngine: def __init__(self, strategy_id: str, match_session: MatchSession | str = MatchSession.NEXT_OPEN, - listing_days: int = 0) -> None: + listing_days: int = 0, size: int = 1) -> None: self.strategy_id = strategy_id self.match_session = MatchSession(match_session) if isinstance(match_session, str) else match_session self.listing_days = listing_days + self.size = size # 合约乘数:A 股 1 手=100 股 → size=100;mock 默认 1 self.strategy = None self.pending_orders: list[PaperOrder] = [] @@ -51,7 +52,7 @@ class PaperCtaEngine: symbol=symbol, side=_direction_to_side(direction), price=float(price), - volume=int(volume), + volume=int(volume) * self.size, # vnpy 策略 volume 单位=手,转股(A 股 ×100) is_market=True, match_session=self.match_session, listing_days=self.listing_days,