Closed rydeen7 closed 1 year ago
Works for me.
It works for me on Windows 10 and Python 3.10 but I updated Python and ib_insync in the last months and got errors with, I guess, util.df(bars). If you can give more details about the error or the traceback, I will try to help.
Thank you all, I reinstalled ib_insync via conda-forge, and now I cannot import ib_insync. My error message is berrow,
`Python 3.8.16 (default, Jan 17 2023, 16:42:09) [Clang 14.0.6 ] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information.
import ib_insync Traceback (most recent call last): File "/Users/pm/miniconda3/envs/ml4t/lib/python3.8/site-packages/ib_insync/util.py", line 17, in
from zoneinfo import ZoneInfo ModuleNotFoundError: No module named 'zoneinfo'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "
Dear all, After all, I did clean install macOS, and made new environment with python3.9. Then, I was able to call util.df.
So please ignore my former comment. Thanks.
It seems backports.zoneinfo
was not installed.
It is not working for me. I am using PyCharm 2022.2.5 (built Mar15, '23) and I installed ib_insync today. Here is the error I am getting:
File "C:\Users\nnrei\PycharmProjects\what_if\venv\lib\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'
Update: There is some kind of version issue somewhere. I cannot resolve this pandas error using 1.4.3 and python 3.9.7 and pycharm. I have also tried this via WSL2 where the rest of my project is but I cannot get around the timeout issue (described in issue 529)
Solved. Here is a replacement for util.df() that seems to work for me based on results from b.reqHistoricalData():
def deconstruct_bardata(bardata):
data = []
for bar in bardata:
data.append({'open': bar.open,
'high': bar.high,
'low': bar.low,
'close': bar.close,
'volume': bar.volume,
'date': bar.date.strftime('%Y-%m-%d %H:%M:%S')})
df = pd.DataFrame(data)
return df
df = deconstruct_bardata(amzn_bars)
print(df)
There are other errors, I cannot get contract data either regardless of which underlying I try SPY, AMZN, TSLA all produce the following error:
Error 321, reqId 5: Error validating request.-'cB' : cause - Invalid contract id
Is there a more stable recent version I should be using? Or can someone message me and try to sort this out? I am exhausted trying to get this library to work.
It might be dependent on my environment (M1 MacBook Air + python3.8), util.df(bars) does not work correctly. Did IB original API change their bar object?