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,