erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.8k stars 743 forks source link

NameError: name 'IB' is not defined #335

Closed believeitcould closed 3 years ago

believeitcould commented 3 years ago

I have installed ib_insync and I am using python3.6 on windows. Code below

from ib_insync import *
# util.startLoop()  # uncomment this line when in a notebook

ib = IB()
ib.connect('127.0.0.1', 7497, clientId=1)

contract = Forex('EURUSD')
bars = ib.reqHistoricalData(
    contract, endDateTime='', durationStr='30 D',
    barSizeSetting='1 hour', whatToShow='MIDPOINT', useRTH=True)

# convert to pandas dataframe:
df = util.df(bars)
print(df)
Traceback (most recent call last):
  File "ib_insync.py", line 1, in <module>
    from ib_insync import *
  File "D:\TWS API\samples\Python\ib_insync.py", line 4, in <module>
    ib = IB()
NameError: name 'IB' is not defined

What is the problem? Thanks!

erdewit commented 3 years ago

File "ib_insync.py", line 1, in

That's the problem right there. A local file should have a different name then any installed package.

believeitcould commented 3 years ago

My stupid!

joecrawford1111 commented 1 year ago

Hi. I have the same error. I cannot see an installed package called IB? Please explain how to fix this in baby terms if you don't mind. Thanks.

jlixfeld commented 1 year ago

Rename your script something other than ib_insync.py

evergreen2mdt commented 1 year ago

Hi. Brand new at this. I got the same error. I changed the name of the local file, and still received this error. Any help would be great (in baby terms pls)

C:\Users\evergren\PycharmProjects\venv\Scripts\python.exe "C:\Users\evergreen\PycharmProjects\anotehr ib api.py" Traceback (most recent call last): File "C:\Users\evergreen\PycharmProjects\anotehr ib api.py", line 1, in from ib_insync import * File "C:\Users\evergreen\PycharmProjects\ib_insync.py", line 4, in ib = IB() ^^ NameError: name 'IB' is not defined

Process finished with exit code 1