diff --git a/vnpy/app/cta_strategy/engine.py b/vnpy/app/cta_strategy/engine.py index 38e06d30..4e94ac2f 100644 --- a/vnpy/app/cta_strategy/engine.py +++ b/vnpy/app/cta_strategy/engine.py @@ -209,12 +209,18 @@ class CtaEngine(BaseEngine): if not strategy: return + # Update strategy pos before calling on_trade method if trade.direction == Direction.LONG: strategy.pos += trade.volume else: strategy.pos -= trade.volume self.call_strategy_func(strategy, strategy.on_trade, trade) + + # Sync strategy variables to data file + self.sync_strategy_data(strategy) + + # Update GUI self.put_strategy_event(strategy) def process_position_event(self, event: Event): @@ -675,6 +681,9 @@ class CtaEngine(BaseEngine): # Cancel all orders of the strategy self.cancel_all(strategy) + # Sync strategy variables to data file + self.sync_strategy_data(strategy) + # Update GUI self.put_strategy_event(strategy)