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

我想获得CTP连接状态的返回值,CtpMdApi和CtpTdApi有login_status/connect_status变量,请问如何获取connect_status变量的值呢?
写了如下代码:
from vnpy_ctp.gateway.ctp_gateway import CtpMdApi,TdApi
engine2 = CtpMdApi(TdApi)
运行时报错:
Traceback (most recent call last):
File "C:\Users\wp61413_114147317492\期权交易\终稿\ScriptTrader_vnpy_impvplace_commodityDos.py", line 9, in <module>
engine2 = CtpMdApi(TdApi)
File "D:\veighna_studio\lib\site-packages\vnpy_ctp\gateway\ctp_gateway.py", line 250, in init
self.gateway_name: str = gateway.gateway_name
AttributeError: type object 'vnpy_ctp.api.vnctptd.TdApi' has no attribute 'gateway_name'
请问如何获取呢?谢谢!

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

想在创建engine2对象后,通过engine2.connect_status来获取

Member
avatar
加入于:
帖子: 5055
声望: 305

不要自己去创建TdApi的实例,不熟悉底层开发的话不建议去动gateway层面的东西

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

engine.get_gateway('CTP').td_api.connect_status

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

谢谢,使用engine.get_gateway('CTP').td_api.connect_status后,还是报错了:

from vnpy_scripttrader import init_cli_trading
from vnpy_ctp import CtpGateway
engine = init_cli_trading([CtpGateway])
Traceback (most recent call last):
File "c:\Users\wp61413_114147317492\期权交易\终稿\ScriptTrader_vnpy_impvplace_commodityDos.py", line 286, in <module>
run()
File "c:\Users\wp61413_114147317492\期权交易\终稿\ScriptTrader_vnpy_impvplace_commodityDos.py", line 42, in run
print(engine.get_gateway('CTP').td_api.connect_status)
AttributeError: 'ScriptEngine' object has no attribute 'get_gateway'

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

wp61413 wrote:

谢谢,使用engine.get_gateway('CTP').td_api.connect_status后,还是报错了:

from vnpy_scripttrader import init_cli_trading
from vnpy_ctp import CtpGateway
engine = init_cli_trading([CtpGateway])
Traceback (most recent call last):
File "c:\Users\wp61413_114147317492\期权交易\终稿\ScriptTrader_vnpy_impvplace_commodityDos.py", line 286, in <module>
run()
File "c:\Users\wp61413_114147317492\期权交易\终稿\ScriptTrader_vnpy_impvplace_commodityDos.py", line 42, in run
print(engine.get_gateway('CTP').td_api.connect_status)
AttributeError: 'ScriptEngine' object has no attribute 'get_gateway'

哦你是脚本引擎啊,那在engine后面还需要加个main_engine

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

谢谢,请问是这样写吗?
engine.main_engine.get_gateway('CTP').td_api.connect_status

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

沪公网安备 31011502017034号

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