vn.py官网
开源量化社区
Member
avatar
加入于:
帖子: 9
声望: 0

新手刚上路,最近尝试连接simnow 做仿真交易,虽然能够成功连接上simnow的行情和交易服务器,但是在尝试获取期货合约的tick信息时返回的是“None”, 求大神指路,代码和运行结果如下(用户名和密码隐去了):
from vnpy.app.script_trader import ScriptEngine
from vnpy.app.script_trader import init_cli_trading
from vnpy.gateway.ctp import CtpGateway
from time import sleep

import sys
import importlib
import traceback
from typing import Sequence, Any
from pathlib import Path
from datetime import datetime
from threading import Thread

from pandas import DataFrame

from vnpy.event import Event, EventEngine
from vnpy.trader.engine import BaseEngine, MainEngine
from vnpy.trader.constant import Direction, Offset, OrderType, Interval
from vnpy.trader.object import (
OrderRequest,
HistoryRequest,
SubscribeRequest,
TickData,
OrderData,
TradeData,
PositionData,
AccountData,
ContractData,
LogData,
BarData
)
from vnpy.trader.rqdata import rqdata_client

APP_NAME = "ScriptTrader"

EVENT_SCRIPT_LOG = "eScriptLog"

engine = init_cli_trading([CtpGateway])

setting = {
"用户名": "xxxx",
"密码": "xxxx",
"经纪商代码": "9999",
"交易服务器":"tcp://180.168.146.187:10100",
"行情服务器":"tcp://180.168.146.187:10110",
"产品名称":"simnow_xxx_test",
"授权编码":"0000000000000000",
"产品信息": ""
}
engine.connect_gateway(setting,"CTP")
engine.subscribe(vt_symbols = ["rb2101.SHFE"])

tick=engine.get_tick(vt_symbol="rb2101.SHFE",use_df=True)
print(tick)
运行结果如下:

description

Member
avatar
加入于:
帖子: 2708
声望: 158

是不是环境用错了没行情。可以图形界面上去看一下订阅后是否有行情

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

谢谢,已解决。应该sleep(5)后再调用tick

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

沪公网安备 31011502017034号