ib_isync issue with util.df() function stemming from pandas

162 views Asked by At

I am trying to retrieve some stock data from interactive brokers api via the IB gateway using the reqHistoricalData a function provided by ib_isync. Once I have the data I want to convert it into a data frame using util.df() but I get the following issue:

File "/Users/rorymurray/venv001/lib/python3.8/site-packages/pandas/core/arrays/datetimelike.py", line 415, in astype converted = ints_to_pydatetime( File "pandas/_libs/tslibs/vectorized.pyx", line 158, in pandas._libs.tslibs.vectorized.ints_to_pydatetime File "pandas/_libs/tslibs/timezones.pyx", line 266, in pandas._libs.tslibs.timezones.get_dst_info AttributeError: 'NoneType' object has no attribute 'total_seconds'

Here is the code :

from ib_insync import *
ib = IB()
ib.connect('127.0.0.1',4001,clientId=1)
print(ib.isConnected())


contract = Stock('MSFT', 'SMART', 'USD')
bars = ib.reqHistoricalData(contract,durationStr='30 D',endDateTime='',barSizeSetting='1 hour'
                            ,whatToShow='MIDPOINT',useRTH=True,formatDate=1)
df = util.df(bars)
print(df)
1

There are 1 answers

0
Schachk On

formatDate=2 solves the issue for me.