[Mod] sync strategy data to file when stopped or receive trade update
This commit is contained in:
parent
1cfbbe5d30
commit
f5dd168a73
@ -209,12 +209,18 @@ class CtaEngine(BaseEngine):
|
|||||||
if not strategy:
|
if not strategy:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Update strategy pos before calling on_trade method
|
||||||
if trade.direction == Direction.LONG:
|
if trade.direction == Direction.LONG:
|
||||||
strategy.pos += trade.volume
|
strategy.pos += trade.volume
|
||||||
else:
|
else:
|
||||||
strategy.pos -= trade.volume
|
strategy.pos -= trade.volume
|
||||||
|
|
||||||
self.call_strategy_func(strategy, strategy.on_trade, trade)
|
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)
|
self.put_strategy_event(strategy)
|
||||||
|
|
||||||
def process_position_event(self, event: Event):
|
def process_position_event(self, event: Event):
|
||||||
@ -675,6 +681,9 @@ class CtaEngine(BaseEngine):
|
|||||||
# Cancel all orders of the strategy
|
# Cancel all orders of the strategy
|
||||||
self.cancel_all(strategy)
|
self.cancel_all(strategy)
|
||||||
|
|
||||||
|
# Sync strategy variables to data file
|
||||||
|
self.sync_strategy_data(strategy)
|
||||||
|
|
||||||
# Update GUI
|
# Update GUI
|
||||||
self.put_strategy_event(strategy)
|
self.put_strategy_event(strategy)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user