Interactive Brokers TWS API usage example.
TWS API Guide http://interactivebrokers.github.io/tws-api/#gsc.tab=0
config.py
if necessarypythonw main.py
To allow connection between your application and TWS you have to set several options in the TWS configuration:
In the TWS window:
Edit config.py file directly to change the configuration.
Client has to check not just messages from the TWS but messages from the GUI as well.
To do so I just copied the EClient.run() method body from the API code and added onLoopIteration() hook call inside the EClient infinite loop.
I'm using this hook to process messages from other sources (GUI), not just TWS.
Uncomment self.onIdle() to create another hook to process something while no messages are comming from the TWS.