fix(trader): volume×size(A股1手=100股) — DoubleMa 真策略回放 filled=3 跑通
This commit is contained in:
@@ -146,14 +146,14 @@ def _run_replay(db, aid, req: PaperCreateRequest):
|
|||||||
if cls is None:
|
if cls is None:
|
||||||
continue # 策略不可用(本机无 vnpy_ctastrategy)→ 跳过
|
continue # 策略不可用(本机无 vnpy_ctastrategy)→ 跳过
|
||||||
cta = PaperCtaEngine(s.name, match_session=s.match_session,
|
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}"
|
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 = cls(cta, s.name, vt_symbol, s.params) # CtaTemplate(cta_engine, name, vt_symbol, setting)
|
||||||
strat.trading = True # 允许 send_order(等价 on_start)
|
strat.trading = True # 允许 send_order(等价 on_start)
|
||||||
try:
|
try:
|
||||||
from vnpy.trader.utility import ArrayManager
|
from vnpy.trader.utility import ArrayManager
|
||||||
if not hasattr(strat, "am"):
|
if not hasattr(strat, "am"):
|
||||||
strat.am = ArrayManager(100)
|
strat.am = ArrayManager(20) # 默认 100 根才 inited,短区间不够;用 20 兼容
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
cta.set_strategy(strat)
|
cta.set_strategy(strat)
|
||||||
|
|||||||
@@ -30,10 +30,11 @@ class PaperCtaEngine:
|
|||||||
|
|
||||||
def __init__(self, strategy_id: str,
|
def __init__(self, strategy_id: str,
|
||||||
match_session: MatchSession | str = MatchSession.NEXT_OPEN,
|
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.strategy_id = strategy_id
|
||||||
self.match_session = MatchSession(match_session) if isinstance(match_session, str) else match_session
|
self.match_session = MatchSession(match_session) if isinstance(match_session, str) else match_session
|
||||||
self.listing_days = listing_days
|
self.listing_days = listing_days
|
||||||
|
self.size = size # 合约乘数:A 股 1 手=100 股 → size=100;mock 默认 1
|
||||||
self.strategy = None
|
self.strategy = None
|
||||||
self.pending_orders: list[PaperOrder] = []
|
self.pending_orders: list[PaperOrder] = []
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ class PaperCtaEngine:
|
|||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
side=_direction_to_side(direction),
|
side=_direction_to_side(direction),
|
||||||
price=float(price),
|
price=float(price),
|
||||||
volume=int(volume),
|
volume=int(volume) * self.size, # vnpy 策略 volume 单位=手,转股(A 股 ×100)
|
||||||
is_market=True,
|
is_market=True,
|
||||||
match_session=self.match_session,
|
match_session=self.match_session,
|
||||||
listing_days=self.listing_days,
|
listing_days=self.listing_days,
|
||||||
|
|||||||
Reference in New Issue
Block a user