Closed FallacyWalker closed 7 years ago
目前只需要下单,撤单功能, 就是下单/撤单后,可以在vnpy的vntrader中看到;
如果 vnpy mod 和 vntrader 登录了同一个 CTP 账号的话是可以在 vntrader 中看到的。其实一个CTP 账号可以登录多个终端,所有终端都会收到 CTP 的回报,不仅仅局限于 vnpy mod 和 vntrader。
好的,但是怎样下单/撤单呢?
在策略中调用 rqalpha 的相关 API 即可。 参见此处 http://rqalpha.readthedocs.io/zh_CN/latest/api/base_api.html#buy-open
照着buy_and_hold写了一个简单的策略文件,但运行后vntrader里看不到交易信息; 我现在也无法确定策略文件是否被执行了,我在策略文件里加了logger.info("xxx"), 但是运行时并没有打出来;
策略运行前会有几分钟的时间从 CTP 同步数据。 您可以将 log-level 设置成 verbose,这样能看到一些更详细的 debug 信息。
设置了log-level为verbose; 运行了大约20分钟,报错: CThostFtdcUserApiImplBase::OnSessionDisconnected[0x7f5b640008c8][-1461387263][ 0] Traceback (most recent call last): File "/home/RqalphaNew/rqalpha/rqalpha/main.py", line 191, in run mod_handler.start_up() └ <rqalpha.mod.ModHandler object at 0x7f5b7c71ded0> File "/home/RqalphaNew/rqalpha/rqalpha/mod/init.py", line 67, in start_up self._mod_dict[mod_name].start_up(self._env, mod_config) │ │ │ └ {'CTP': {'brokerID': '9999', 'mdAddress': 'tcp://180.168.146.187:10010', 'password': ‘000000’, 'tdAddress': 'tcp://180... │ │ └ <rqalpha.mod.ModHandler object at 0x7f5b7c71ded0> │ └ 'vnpy' └ <rqalpha.mod.ModHandler object at 0x7f5b7c71ded0> File "/home/RqalphaNew/rqalpha/rqalpha/mod/rqalpha_mod_vnpy/mod.py", line 54, in start_up port = VNPYBroker.get_portfolio() └ <class 'rqalpha.mod.rqalpha_mod_vnpy.vnpy_broker.VNPYBroker'> TypeError: unbound method get_portfolio() must be called with VNPYBroker instance as first argument (got nothing instead) 0000-00-00 ERROR unbound method get_portfolio() must be called with VNPYBroker instance as first argument (got nothing instead) [2017-04-24 15:49:35.546968] ERROR: system_log: 策略运行产生异常 Traceback (most recent call last): File "/home/RqalphaNew/rqalpha/rqalpha/main.py", line 191, in run mod_handler.start_up() File "/home/RqalphaNew/rqalpha/rqalpha/mod/init.py", line 67, in start_up self._mod_dict[mod_name].start_up(self._env, mod_config) File "/home/RqalphaNew/rqalpha/rqalpha/mod/rqalpha_mod_vnpy/mod.py", line 54, in start_up port = VNPYBroker.get_portfolio() TypeError: unbound method get_portfolio() must be called with VNPYBroker instance as first argument (got nothing instead) CThostFtdcUserApiImplBase::OnSessionDisconnected[0x7f5b500008c8][-1461256191][ 0]
麻烦更新一下代码,包括 vnpy 和 vnpy mod
最新的vnpy无法编译CTP接口 。
rqalpha 2.0.9
运行vnpy mod的配置对吗?:
from rqalpha import run
config_mod={
"base":{
"strategy_file" : "/home/RqalphaNew/rqalpha/rqalpha/examples/buy_and_hold.py",
"start_date" : "2017-01-01",
"end_date" : "2017-04-25”,
"stock_starting_cash" : 100000,
"benchmark" : "000300.XSHG",
"strategy_type" : “securities”,
"enabled" : "true",
"frequency" : "tick"
},
"mod": {
"vnpy": {
"gateway_type": "CTP",
"vn_trader_path": "/home/walker/Desktop/vnpy/vn.trader"
"all_day": True,
"query_interval": 2,
"CTP": {
"userID": "userid,
"password": “password”,
"brokerID": "9999",
"tdAddress": "tcp://180.168.146.187:10030",
"mdAddress": "tcp://180.168.146.187:10031"
},
"enabled": “true”,
“log-level”: “verbose”
},
"sys_simulation":{
"enabled": "false"
}
}
}
run(config_mod)
都更新了: rqalpha: 2.1.2 vnpy: clone的最新的,开发者说目前无法查看版本; vnpy mod: 0.9.21 Ubuntu 16.04 LTS
运行vnpy mod几分钟后, 报错:“不支持撮合类型” 。
/usr/bin/python2.7 /home/walker/Desktop/Rqalpha212/rqalpha/startmod.py
Traceback (most recent call last):
File "/home/walker/Desktop/VnpyNew/vnpy/vn.trader/gateway/init.py", line 30, in
Process finished with exit code 0
检查一下是不是你的配置没有被调用,因为报错信息显示 simulation mod 还是被触发了
这是我的配置,有什么问题吗? rqalpha 2.1.2 运行vnpy mod的配置对吗?: from rqalpha import run config_mod={ "base":{ "strategy_file" : "/home/walke/Desktop/Rqalpha212/rqalpha/rqalpha/examples/buy_and_hold.py", "start_date" : "2017-01-01", "end_date" : "2017-04-25”, "stock_starting_cash" : 100000, "benchmark" : "000300.XSHG", "strategy_type" : “securities”, "enabled" : "true", "frequency" : "tick" }, "mod": { "vnpy": { "gateway_type": "CTP", "vn_trader_path": "/home/walker/Desktop/VnpyNew/vnpy/vn.trader" "all_day": True, "query_interval": 2, "CTP": { "userID": "userid, "password": “password”, "brokerID": "9999", "tdAddress": "tcp://180.168.146.187:10030", "mdAddress": "tcp://180.168.146.187:10031" }, "enabled": “true”, “log-level”: “verbose” }, "sys_simulation":{ "enabled": "false" } } } run(config_mod)
使用 rqalpha mod list 命令查看 mod 的启用状态,使用 rqalpha mod disable/enable XXX 开关闭和开启mod。 http://rqalpha.readthedocs.io/zh_CN/latest/development/mod.html#pypi-mod
simulation mod已经关闭:
rqalpha_vnpy_mod必须要安装吗? 怎么不安装,在代码里运行呢 ?
在 setup.py 所在路径执行 pip install -e .
rqalpa和ralpha vnpy mod,我都执行了 pip install -e . ; 然后我把rqalpha_mod_vnpy文件夹复制到rqalpha/mod下了; 你看一下我的配置有什么问题吗?
你可以看一下 rqalpha 的源代码。 对于第三方mod,一般推荐执行 rqalpha mod install xxx , 这个命令主要会干两件事。第一是寻找该 mod 的安装包有没有被安装,如果没有的话调用 pip 进行安装;第二件事是将该mod的信息添加进配置文件中,之后执行 rqalpha mod list 就可以看到对应的信息。 如果你想通过代码运行,pip install -e . 相当于已经安装了 mod 包,下面还需要做的事就是将信息添加到 mod 配置文件中,此时执行 rqalpha mod install vnpy 就可以了。 顺利的话此时执行 rqalpha mod list 就可以在表格中看到 vnpy,并可以执行 rqalpha mod enable vnpy 启用该mod。 另外并不需要将代码复制到 rqalpha 目录下。
我把这个问题单独开了个issue,方便其他用户查看 https://github.com/ricequant/rqalpha-mod-vnpy/issues/18 如果针对通过代码运行的问题可以直接在那里回复。
@FallacyWalker rqalpha 支持 rqalpha mod install -e . 你如果mod 本地开发的话 建议直接使用rqlapha install mod install -e . 来安装需要开发和编辑的Mod
rqalpha下的vnpy mod文件夹删掉了,也找上面说的办法安装了,重新运行,还是报“不支持撮合类型”的错误:
/usr/bin/python2.7 /home/walker/Desktop/Rqalpha212/rqalpha/startmod.py
Traceback (most recent call last):
File "/home/walker/Desktop/VnpyNew/vnpy/vn.trader/gateway/init.py", line 30, in
Process finished with exit code 0
File "/home/walker/Desktop/Rqalpha212/rqalpha/rqalpha/mod/rqalpha_mod_sys_simulation/mod.py", line 47, in start_up raise RuntimeError(("Not supported matching type {}").format(mod_config.matching_type)) RuntimeError: 不支持撮合类型: MATCHING_TYPE.CURRENT_BAR_CLOSE
这个错误确实是 sys_simulation 报出来的。你可以看到 CTP 已经成功连接上了,但是这个报错终止了程序导致 CTP 断连。一般来说 sys_simulation 已经 disable 了是不会启动的,您可否帮忙查看一下是什么原因导致了 sys_simulation 启动?如果关掉了 vnpy mod 这个现象还是否会复现?可以着重看一下 rqalpha 中的 ModHandler 部分。
"sys_simulation":{ "enabled": "false" } 这个错误解决了, 把配置里的这一段删掉就好了,但是重新运行几分钟后,又报错了:
Traceback (most recent call last): File "/home/walker/Desktop/Rqalpha212/rqalpha/rqalpha/main.py", line 289, in run Executor(env).run(bar_dict) │ │ └ BarMap(ZN1804) │ └ <rqalpha.environment.Environment object at 0x7ffbc317fa10> └ <class 'rqalpha.core.executor.Executor'> File "/home/walker/Desktop/Rqalpha212/rqalpha/rqalpha/core/executor.py", line 58, in run event_bus.publish_event(PRE_TICK) │ └ event_type:EVENT.PRE_TICK └ <rqalpha.events.EventBus object at 0x7ffbc317f950> File "/home/walker/Desktop/Rqalpha212/rqalpha/rqalpha/events.py", line 43, in publish_event if l(event): File "/home/walker/Desktop/Rqalpha212/rqalpha/rqalpha/model/account/benchmark_account.py", line 50, in _on_tick tick = event.tick └ event_type:EVENT.PRE_TICK AttributeError: 'Event' object has no attribute 'tick' 2017-04-28 14:13:27.00 ERROR 'Event' object has no attribute 'tick' [2017-04-28 14:13:30.746903] ERROR: system_log: 策略运行产生异常 Traceback (most recent call last): File "/home/walker/Desktop/Rqalpha212/rqalpha/rqalpha/main.py", line 289, in run Executor(env).run(bar_dict) File "/home/walker/Desktop/Rqalpha212/rqalpha/rqalpha/core/executor.py", line 58, in run event_bus.publish_event(PRE_TICK) File "/home/walker/Desktop/Rqalpha212/rqalpha/rqalpha/events.py", line 43, in publish_event if l(event): File "/home/walker/Desktop/Rqalpha212/rqalpha/rqalpha/model/account/benchmark_account.py", line 50, in _on_tick tick = event.tick AttributeError: 'Event' object has no attribute 'tick' CThostFtdcUserApiImplBase::OnSessionDisconnected[0x7ffba80008c8][-589823999][ 0] CThostFtdcUserApiImplBase::OnSessionDisconnected[0x7ffba40008c8][-589758463][ 0]
Process finished with exit code 0
develop 分支已修复
master 分支已修复。
vnpy mod 现支持下单撤单等功能。可否详细描述一下您需要的功能?