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

各位老师:
我再IB Paper测试账户订阅行情时出现如下错误,应该如何修正啊?
提前谢过,感谢。

vt_symbols = ['GBP-USD-CASH.IDEALPRO']
#engine.subscribe(vt_symbols)

from vnpy.trader.constant import Exchange
from vnpy.trader.object import SubscribeRequest
req0 = SubscribeRequest(vt_symbols[0],Exchange.IDEALPRO) #创建行情订阅
engine.main_engine.subscribe(req0,"IB")

ticks = engine.get_ticks(vt_symbols)
print(f'Subscribed:\n{ticks}')
Subscribed:
[None]
ERROR 1 321 Error validating request:-'bQ' : cause - Please enter a valid security type
ERROR 2 321 Error validating request:-'bW' : cause - Please enter a valid security type
2020-07-23 02:37:12.945376  信息通知,代码:321,内容: Error validating request:-'bQ' : cause - Please enter a valid security type
2020-07-23 02:37:12.946373  信息通知,代码:321,内容: Error validating request:-'bW' : cause - Please enter a valid security type
Member
avatar
加入于:
帖子: 3
声望: 1

原因:vt_symbol 和symbol 参数没区分清楚。修正如下:

vt_symbols = ['EUR-USD-CASH.IDEALPRO']
symbols = [x.split('.')[0] for x in vt_symbols]


from vnpy.trader.constant import Exchange
from vnpy.trader.object import SubscribeRequest
req0 = SubscribeRequest(symbols[0],Exchange.IDEALPRO) #创建行情订阅
engine.main_engine.subscribe(req0,"IB")

ticks = engine.get_ticks(vt_symbols)

print(f'Subscribed:\n{ticks}')
Subscribed:
[TickData(gateway_name='IB', symbol='EUR-USD-CASH', exchange=<Exchange.IDEALPRO: 'IDEALPRO'>, datetime=datetime.datetime(2020, 7, 23, 3, 10, 41, 195875, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), name='ŷԪ-European Monetary Union Euro', volume=0, open_interest=0, last_price=1.157035, last_volume=0, limit_up=0, limit_down=0, open_price=0, high_price=1.16015, low_price=1.1507, pre_close=1.1527, bid_price_1=1.15703, bid_price_2=0, bid_price_3=0, bid_price_4=0, bid_price_5=0, ask_price_1=1.15704, ask_price_2=0, ask_price_3=0, ask_price_4=0, ask_price_5=0, bid_volume_1=3000000, bid_volume_2=0, bid_volume_3=0, bid_volume_4=0, bid_volume_5=0, ask_volume_1=1000000, ask_volume_2=0, ask_volume_3=0, ask_volume_4=0, ask_volume_5=0)]

题外话:这个俄文?ŷԪ?是什么东西?

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

沪公网安备 31011502017034号