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

请问如果是纯自己写的脚本策略(不是no_ui启动),如何开启风控?

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

请问有办法开启风控吗?

Member
avatar
加入于:
帖子: 4883
声望: 293
from vnpy_riskmanger import RiskManagerApp

engine = init_cli_engine(xxx)

engine.main_engine.add_app(RiskManagerApp)
Member
avatar
加入于:
帖子: 164
声望: 0

谢谢,已运行上述代码,但是运行以后没有输出,请问在哪里可以设置风控的条件(如委托笔数,报单次数等)?

from vnpy_riskmanager import RiskManagerApp
engine = init_cli_trading([CtpGateway])
engine.main_engine.add_app(RiskManagerApp)

Member
avatar
加入于:
帖子: 4883
声望: 293

vnpy_riskmanager.engine的update_setting、save_setting

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

是这样写吗?报错了

from vnpy_riskmanager import RiskManagerApp
engine = init_cli_trading([CtpGateway])
engine.main_engine.add_app(RiskManagerApp)
from vnpy_riskmanager.engine import RiskEngine
setting = {}
setting["active"] = True
setting["order_flow_limit"] = 10
setting["order_flow_clear"] = 100
setting["order_size_limit"] = 10
setting["trade_limit"] = 100
setting["active_order_limit"] = 10
setting["order_cancel_limit"] = 10
engine.update_setting(setting)

报错内容:
PS C:\Users\wp61413_114147317492> & D:/veighna_studio/python.exe c:/Users/wp61413_114147317492/期权交易/终稿/Boxarbitrage.py
找不到数据服务驱动vnpy
,使用默认的RQData数据服务
Traceback (most recent call last):
File "c:\Users\wp61413_114147317492\期权交易\终稿\Box_arbitrage.py", line 27, in <module>
engine.update_setting(setting)
AttributeError: 'ScriptEngine' object has no attribute 'update_setting'

Member
avatar
加入于:
帖子: 4883
声望: 293

这两个函数都是RiskEngine的函数

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

需要自己创建RishEngine类的对象吗?然后用创建的对象调用update_setting方法?请教对象的参数怎么写?
risk = RiskEngine(main_engine=??, event_engine=??)

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

您好,可以帮助回答吗?

Member
avatar
加入于:
帖子: 44
声望: 2

可以用engine.main_engine.get_engine('RiskManager')访问到已经创建的riskengine

Member
avatar
加入于:
帖子: 54
声望: 1

在命令行运行的时候应该先创建一个RiskManager的实例,比如
risk_manager = RiskEngine(main_engine, event_engine)
再调用
risk_manager.update_setting()

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

谢谢,请问是这样写吗?

'''
from vnpy_riskmanager import RiskManagerApp
from vnpy_ctp import CtpGateway
from vnpy_scripttrader import init_cli_trading
engine = init_cli_trading([CtpGateway])
engine.main_engine.add_app(RiskManagerApp)

a = engine.main_engine.get_engine('RiskManager')

setting = {}
setting["active"] = True
setting["order_flow_limit"] = 10
setting["order_flow_clear"] = 100
setting["order_size_limit"] = 10
setting["trade_limit"] = 100
setting["active_order_limit"] = 10
setting["order_cancel_limit"] = 10
a.update_setting(setting)
a.save_setting()
'''

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

可以帮助回答吗?这样写,是不是就可以启动风控了?

from vnpy_riskmanager import RiskManagerApp
from vnpy_ctp import CtpGateway
from vnpy_scripttrader import init_cli_trading
engine = init_cli_trading([CtpGateway])
engine.main_engine.add_app(RiskManagerApp)

a = engine.main_engine.get_engine('RiskManager')

setting = {}
setting["active"] = True
setting["order_flow_limit"] = 10
setting["order_flow_clear"] = 100
setting["order_size_limit"] = 10
setting["trade_limit"] = 100
setting["active_order_limit"] = 10
setting["order_cancel_limit"] = 10
a.update_setting(setting)
a.save_setting()
Member
avatar
加入于:
帖子: 4883
声望: 293

应该可以的,update_setting且active为True的时候应该会输出”交易风控功能启动“的日志

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

好的,非常感谢!

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

沪公网安备 31011502017034号

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