vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 6
声望: 0

from vnpy.app.script_trader import init_cli_trading
from vnpy.app.script_trader.cli import process_log_event
from vnpy.gateway.ib import IbGateway
from time import sleep
from datetime import datetime
import pandas as pd

setting = {
"TWS地址": "127.0.0.1",
"TWS端口": 7497,
"客户号":1 ,

}
engine = init_cli_trading([IbGateway]) #返回Script_engine 示例,并且给main_engine注册了gateway
engine.connect_gateway(setting, "IB") #链接

from vnpy.trader.object import HistoryRequest
from vnpy.trader.object import Interval
start = datetime.strptime('20200201 16:30:00', "%Y%m%d %H:%M:%S")
end = datetime.strptime('20200705 16:30:00', "%Y%m%d %H:%M:%S")
print(start)
historyreq = HistoryRequest(
symbol="PDD-USD-STK",
exchange=Exchange.SMART,
start=start,
end = end,
interval=Interval.DAILY
)

bardatalist = engine.main_engine.query_history(historyreq,"IB")
print(bardatalist)

Exception in thread Thread-4:
Traceback (most recent call last):
File "/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/anaconda3/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/anaconda3/lib/python3.7/site-packages/vnpy/gateway/ib/ib_gateway.py", line 828, in run
self.decoder.interpret(fields)
File "/anaconda3/lib/python3.7/site-packages/ibapi/decoder.py", line 1280, in interpret
handleInfo.processMeth(self, iter(fields))
File "/anaconda3/lib/python3.7/site-packages/ibapi/decoder.py", line 517, in processHistoricalDataMsg
self.wrapper.historicalData(reqId, bar)
File "/anaconda3/lib/python3.7/site-packages/vnpy/gateway/ib/ib_gateway.py", line 601, in historicalData
dt = datetime.strptime(ib_bar.date, "%Y%m%d %H:%M:%S")
File "/anaconda3/lib/python3.7/_strptime.py", line 577, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/anaconda3/lib/python3.7/_strptime.py", line 359, in _strptime
(data_string, format))
ValueError: time data '20191120' does not match format '%Y%m%d %H:%M:%S'

报错如下,不知道哪里来的20191120呢,一头雾水,群里有大神可以解惑下吗?多谢呢~

Administrator
avatar
加入于:
帖子: 4655
声望: 266

接口版本问题,请升级到最新的2.1.4再试试

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

我现在知道这个问题是为什么了,你试图下载的是一分钟数据。
可是你的
interval=Interval.DAILY
这个参数选择了日线。
我复制了你的代码,得到了同样的结果。

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

沪公网安备 31011502017034号