I'm getting started with the interactive brokers api, and starting off the examples do seem to work, but the one thing that's not is that the connection hangs pretty much on every instantiation of the IBapi class. Here's a basic example:
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
import time
class IBapi(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
print('testing')
app = IBapi()
app.connect('127.0.0.1', 7497, 0)
app.run()
print("TEST successful: The app will stop running in 5 seconds...")
time.sleep(5)
app.disconnect() <--- suppose to disconnect
The connection works, as I'm able to place an order (with additional code) in my paper account, but the connection stays up, and I'd have to go a different terminal and just kill the python process. Any ideas of how can I run this code and disconnect when done? TIA