vnpy / vnpy_ib

VeighNa框架的InteractiveBrokers交易接口
https://www.vnpy.com
MIT License
34 stars 31 forks source link

timezone问题 #14

Closed dalitang closed 1 year ago

dalitang commented 1 year ago

有好意思又开一个

更新数据时候

ib_gateway.py

Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniforge/base/envs/py310/lib/python3.10/site-packages/vnpy_datamanager/ui/widget.py", line 384, in update_data
    self.engine.download_bar_data(
  File "/opt/homebrew/Caskroom/miniforge/base/envs/py310/lib/python3.10/site-packages/vnpy_datamanager/engine.py", line 206, in download_bar_data
    data: List[BarData] = self.main_engine.query_history(
  File "/opt/homebrew/Caskroom/miniforge/base/envs/py310/lib/python3.10/site-packages/vnpy/trader/engine.py", line 223, in query_history
    return gateway.query_history(req)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/py310/lib/python3.10/site-packages/vnpy_ib/ib_gateway.py", line 232, in query_history
    return self.api.query_history(req)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/py310/lib/python3.10/site-packages/vnpy_ib/ib_gateway.py", line 773, in query_history
    delta: timedelta = end - req.start
TypeError: can't subtract offset-naive and offset-aware datetimes

换掉pytz的原因? `@dataclass class HistoryRequest: """ Request sending to specific gateway for querying history data. """

symbol: str
exchange: Exchange
start: datetime
end: datetime = None
interval: Interval = None

def __post_init__(self) -> None:
    """"""
    self.vt_symbol: str = f"{self.symbol}.{self.exchange.value}"`
noranhe commented 1 year ago

veighna3.3.0全面调整了相关交易接口、数据服务接口、数据库适配器、应用模块,使用新的ZoneInfo对象来标识时区信息。

abz53378 commented 1 year ago

寫給後人看 我遇到跟樓主一樣的問題 debug 後發現 end 和 req.start 的時區不同導致的 後來改了一段 code 就好了

delta: timedelta = end - req.start(tzinfo=LOCAL_TZ)