[bug fix]
This commit is contained in:
parent
f9aad85db9
commit
ec75d5ffc5
@ -825,7 +825,12 @@ class CtaEngine(BaseEngine):
|
|||||||
level=logging.CRITICAL)
|
level=logging.CRITICAL)
|
||||||
|
|
||||||
def add_strategy(
|
def add_strategy(
|
||||||
self, class_name: str, strategy_name: str, vt_symbol: str, setting: dict
|
self, class_name: str,
|
||||||
|
strategy_name: str,
|
||||||
|
vt_symbol: str,
|
||||||
|
setting: dict,
|
||||||
|
auto_init: bool = False,
|
||||||
|
auto_start: bool = False
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Add a new strategy.
|
Add a new strategy.
|
||||||
@ -858,8 +863,8 @@ class CtaEngine(BaseEngine):
|
|||||||
self.put_strategy_event(strategy)
|
self.put_strategy_event(strategy)
|
||||||
|
|
||||||
# 判断设置中是否由自动初始化和自动启动项目
|
# 判断设置中是否由自动初始化和自动启动项目
|
||||||
if setting.get('auto_init', False):
|
if auto_init:
|
||||||
self.init_strategy(strategy_name, auto_start=setting.get('auto_start', False))
|
self.init_strategy(strategy_name, auto_start=auto_start)
|
||||||
|
|
||||||
def init_strategy(self, strategy_name: str, auto_start: bool = False):
|
def init_strategy(self, strategy_name: str, auto_start: bool = False):
|
||||||
"""
|
"""
|
||||||
@ -1315,10 +1320,12 @@ class CtaEngine(BaseEngine):
|
|||||||
|
|
||||||
for strategy_name, strategy_config in self.strategy_setting.items():
|
for strategy_name, strategy_config in self.strategy_setting.items():
|
||||||
self.add_strategy(
|
self.add_strategy(
|
||||||
strategy_config["class_name"],
|
class_name=strategy_config["class_name"],
|
||||||
strategy_name,
|
strategy_name=strategy_name,
|
||||||
strategy_config["vt_symbol"],
|
vt_symbol=strategy_config["vt_symbol"],
|
||||||
strategy_config["setting"]
|
setting=strategy_config["setting"],
|
||||||
|
auto_init=strategy_config.get('auto_init', False),
|
||||||
|
auto_start=strategy_config.get('auto_start', False)
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_strategy_setting(self, strategy_name: str, setting: dict):
|
def update_strategy_setting(self, strategy_name: str, setting: dict):
|
||||||
@ -1327,10 +1334,14 @@ class CtaEngine(BaseEngine):
|
|||||||
"""
|
"""
|
||||||
strategy = self.strategies[strategy_name]
|
strategy = self.strategies[strategy_name]
|
||||||
|
|
||||||
|
strategy_config = self.strategy_setting.get('strategy_name', {})
|
||||||
|
|
||||||
self.strategy_setting[strategy_name] = {
|
self.strategy_setting[strategy_name] = {
|
||||||
"class_name": strategy.__class__.__name__,
|
"class_name": strategy.__class__.__name__,
|
||||||
"vt_symbol": strategy.vt_symbol,
|
"vt_symbol": strategy.vt_symbol,
|
||||||
"setting": setting,
|
"auto_init": strategy_config.get('auto_init', False),
|
||||||
|
"auto_start": strategy_config.get('auto_start', False),
|
||||||
|
"setting": setting
|
||||||
}
|
}
|
||||||
save_json(self.setting_filename, self.strategy_setting)
|
save_json(self.setting_filename, self.strategy_setting)
|
||||||
|
|
||||||
|
@ -854,12 +854,12 @@ class PortfolioTestingEngine(object):
|
|||||||
if 'auto_start' in strategy_setting:
|
if 'auto_start' in strategy_setting:
|
||||||
strategy_setting.update({'auto_start': False})
|
strategy_setting.update({'auto_start': False})
|
||||||
|
|
||||||
# 强制更新回测为True
|
|
||||||
strategy_setting.update({'backtesting': True})
|
|
||||||
|
|
||||||
# 策略参数设置
|
# 策略参数设置
|
||||||
setting = strategy_setting.get('setting', {})
|
setting = strategy_setting.get('setting', {})
|
||||||
|
|
||||||
|
# 强制更新回测为True
|
||||||
|
setting.update({'backtesting': True})
|
||||||
|
|
||||||
# 创建实例
|
# 创建实例
|
||||||
strategy = strategy_class(self, strategy_name, vt_symbol, setting)
|
strategy = strategy_class(self, strategy_name, vt_symbol, setting)
|
||||||
|
|
||||||
|
@ -874,7 +874,7 @@ class CtaProTemplate(CtaTemplate):
|
|||||||
|
|
||||||
# 找出非主力合约的持仓网格
|
# 找出非主力合约的持仓网格
|
||||||
for g in self.gt.get_opened_grids(direction=Direction.SHORT):
|
for g in self.gt.get_opened_grids(direction=Direction.SHORT):
|
||||||
none_mi_symbol = g.snapshot.get('miSymbol')
|
none_mi_symbol = g.snapshot.get('mi_symbol')
|
||||||
if none_mi_symbol is None or none_mi_symbol == self.vt_symbol:
|
if none_mi_symbol is None or none_mi_symbol == self.vt_symbol:
|
||||||
continue
|
continue
|
||||||
if not g.open_status or g.order_status or g.volume - g.traded_volume <= 0:
|
if not g.open_status or g.order_status or g.volume - g.traded_volume <= 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user