VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 218
声望: 0

求助 vnpy_spreading 如何在no_ui 中运行

Member
avatar
加入于:
帖子: 218
声望: 0

no_ui 中 run_child()函数修改为以下内容,但在执行过程中报错。
def run_child():
"""
Running in the child process.
"""
SETTINGS["log.file"] = True

event_engine = EventEngine()
main_engine = MainEngine(event_engine)
main_engine.add_gateway(CtpGateway)
strategy_engine = main_engine.add_app(SpreadTradingApp)
main_engine.write_log("主引擎创建成功")

log_engine = main_engine.get_engine("log")
event_engine.register(EVENT_SPREAD_LOG, log_engine.process_log_event)
main_engine.write_log("注册日志事件监听")

main_engine.connect(ctp_setting, "CTP")
main_engine.write_log("连接CTP接口")

sleep(20)
strategy_engine.add_spread(name='y2209-y2211', leg_settings=[{
    "variable": "A",
    "vt_symbol": "y2209.DCE",
    "trading_direction": 1,
    "trading_multiplier": 1
},
    {
        "variable": "B",
        "vt_symbol": "y2211.DCE",
        "trading_direction": -1,
        "trading_multiplier": -1
    }], price_formula='A-B', active_symbol='y2209.DCE', min_volume=0)

strategy_engine.start()
main_engine.write_log("CTA策略初始化完成")

 # 初始化刚创建的策略
strategy_engine.strategy_engine.add_strategy(class_name, strategy_name, 'y2209-y2211', strategy_setting)
strategy_engine.strategy_engine.init_strategy(strategy_name)
sleep(30)
#启动某个策略
strategy_engine.strategy_engine.start_strategy(strategy_name)

while True:
    sleep(10)
    trading = check_trading_period()
    if not trading:
        print("关闭子进程")
        main_engine.close()
        sys.exit(0)

description

Member
avatar
加入于:
帖子: 3583
声望: 234

add_strategy失败了,可以自己打印排查一下

© 2015-2022 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】