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

用trader界面 下ib单以后(成交也没问题),会触发一个异常,异常信息如下:

Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.10/dist-packages/ibapi-10.19.1-py3.10.egg/ibapi/client.py", line 263, in run
    self.decoder.interpret(fields)
  File "/usr/local/lib/python3.10/dist-packages/ibapi-10.19.1-py3.10.egg/ibapi/decoder.py", line 1387, in interpret
    handleInfo.processMeth(self, iter(fields))
  File "/usr/local/lib/python3.10/dist-packages/ibapi-10.19.1-py3.10.egg/ibapi/decoder.py", line 504, in processExecutionDataMsg
    self.wrapper.execDetails(reqId, contract, execution)
  File "/home/zj/.local/lib/python3.10/site-packages/vnpy_ib/ib_gateway.py", line 678, in execDetails
    dt: datetime = datetime.strptime(time_str, "%Y%m%d  %H:%M:%S")
  File "/usr/lib/python3.10/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/usr/lib/python3.10/_strptime.py", line 352, in _strptime
    raise ValueError("unconverted data remains: %s" %
ValueError: unconverted data remains:  Hongkong

看了下这部分代码ib_gateway.py execDetails里,看着是解析时间错误,把execution.time打出来,

    def execDetails(self, reqId: int, contract: Contract, execution: Execution) -> None:
        """交易数据更新回报"""
        super().execDetails(reqId, contract, execution)
        print("-------------------")          #我加的
        print(execution.time)            #我加的
        if "/" in execution.time:
            timezone = execution.time.split(" ")[-1]
            time_str = execution.time.replace(f" {timezone}", "")
            tz = ZoneInfo(timezone)
        else:
            time_str = execution.time
            tz = LOCAL_TZ
        dt: datetime = datetime.strptime(time_str, "%Y%m%d  %H:%M:%S")
        dt: datetime = dt.replace(tzinfo=tz)

输出是这样的
20231009 09:54:25 Hongkong

代码里用"/"来判断是否接了地域信息,实际打出来好像没有"/",不知道哪里出了问题
版本:
vnpy 3.8
ibapi 10.19.1
ib tws 10.19code text here

Member
avatar
加入于:
帖子: 4709
声望: 287

可以参考一下这个PR
https://github.com/vnpy/vnpy_ib/pull/29

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

沪公网安备 31011502017034号

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