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

用ScriptEngine订阅多个合约,部分合约取不到tick。

直接上代码:

from vnpy.event import EventEngine
from vnpy.trader.setting import SETTINGS
from vnpy.trader.engine import MainEngine

from vnpy_ctp import CtpGateway
from vnpy_scripttrader import init_cli_trading, ScriptEngine
from vnpy_ctastrategy.base import EVENT_CTA_LOG

SETTINGS["log.active"] = True
SETTINGS["log.level"] = INFO
SETTINGS["log.console"] = True

ctp_setting = {
"用户名": ".........",
"密码": ".......",
"经纪商代码": "",
"交易服务器": "",
"行情服务器": "",
"产品名称": "simnow_client_test",
"授权编码": "0000000000000000",
"产品信息": ""
}
event_engine = EventEngine()
main_engine = MainEngine(event_engine)
scr_engine = ScriptEngine(main_engine, event_engine)
main_engine.add_gateway(CtpGateway)

cta_engine = main_engine.add_app(CtaStrategyApp)

main_engine.write_log("主引擎创建成功")
main_engine.connect(ctp_setting, "CTP")

scr_engine.connect_gateway(ctp_setting, "CTP")

main_engine.write_log("连接CTP接口")

定义合约LIST,包含期权合约,共84个

vt_symbols = ['rb2410.SHFE', 'rb2410C3150.SHFE', 'rb2410P3150.SHFE', 'rb2410C3200.SHFE', 'rb2410P3200.SHFE', 'rb2410C3250.SHFE', 'rb2410P3250.SHFE', 'rb2410C3300.SHFE', 'rb2410P3300.SHFE', 'rb2410C3350.SHFE', 'rb2410P3350.SHFE', 'rb2410C3400.SHFE', 'rb2410P3400.SHFE', 'rb2410C3450.SHFE', 'rb2410P3450.SHFE', 'rb2410C3500.SHFE', 'rb2410P3500.SHFE', 'rb2410C3550.SHFE', 'rb2410P3550.SHFE', 'rb2410C3600.SHFE', 'rb2410P3600.SHFE', 'ru2409.SHFE', 'ru2409C13250.SHFE', 'ru2409P13250.SHFE', 'ru2409C13500.SHFE', 'ru2409P13500.SHFE', 'ru2409C13750.SHFE', 'ru2409P13750.SHFE', 'ru2409C14000.SHFE', 'ru2409P14000.SHFE', 'ru2409C14250.SHFE', 'ru2409P14250.SHFE', 'ru2409C14500.SHFE', 'ru2409P14500.SHFE', 'ru2409C14750.SHFE', 'ru2409P14750.SHFE', 'ru2409C15000.SHFE', 'ru2409P15000.SHFE', 'ru2409C15250.SHFE', 'ru2409P15250.SHFE', 'ru2409C15500.SHFE', 'ru2409P15500.SHFE', 'y2409.DCE', 'y2409-C-7300.DCE', 'y2409-P-7300.DCE', 'y2409-C-7400.DCE',
'y2409-P-7400.DCE', 'y2409-C-7500.DCE', 'y2409-P-7500.DCE', 'y2409-C-7600.DCE', 'y2409-P-7600.DCE', 'y2409-C-7700.DCE', 'y2409-P-7700.DCE', 'y2409-C-7800.DCE', 'y2409-P-7800.DCE', 'y2409-C-7900.DCE', 'y2409-P-7900.DCE', 'y2409-C-8000.DCE', 'y2409-P-8000.DCE', 'y2409-C-8100.DCE', 'y2409-P-8100.DCE', 'y2409-C-8200.DCE', 'y2409-P-8200.DCE', 'SA409.CZCE', 'SA409C1740.CZCE', 'SA409P1740.CZCE', 'SA409C1760.CZCE', 'SA409P1760.CZCE', 'SA409C1780.CZCE', 'SA409P1780.CZCE', 'SA409C1800.CZCE', 'SA409P1800.CZCE', 'SA409C1820.CZCE', 'SA409P1820.CZCE', 'SA409C1840.CZCE', 'SA409P1840.CZCE', 'SA409C1860.CZCE', 'SA409P1860.CZCE', 'SA409C1880.CZCE', 'SA409P1880.CZCE', 'SA409C1900.CZCE', 'SA409P1900.CZCE', 'SA409C1920.CZCE', 'SA409P1920.CZCE']
scr_engine.subscribe(vt_symbols)

查看合约TICK

i = 0
for vt_symbol in vt_symbols:
atick = scr_engine.get_tick(vt_symbol)
i+=1
if atick is None:
print(i, vt_symbol)

#

结果显示,前43个合约tick数据正常,从第44个合约开始取不到TICK数据,tick = None

44 y2409-C-7300.DCE
45 y2409-P-7300.DCE
46 y2409-C-7400.DCE
47 y2409-P-7400.DCE
48 y2409-C-7500.DCE
49 y2409-P-7500.DCE
50 y2409-C-7600.DCE
51 y2409-P-7600.DCE
……
……

请高手支招,如何一次订阅更多合约!

Member
avatar
加入于:
帖子: 5020
声望: 303

单独订阅看看,可能是合约不活跃没有推送

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

沪公网安备 31011502017034号

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