From f5dd168a73997e2a7f7a2513cdf46c72550bb252 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sun, 30 Jun 2019 17:10:23 +0800 Subject: [PATCH] [Mod] sync strategy data to file when stopped or receive trade update --- vnpy/app/cta_strategy/engine.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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)