简体   繁体   中英

Connection to IB broker API PYTHON

I test the IB broker API in python. Here are the code:

from ibapi.client import EClient
from ibapi.wrapper import EWrapper  

class IBapi(EWrapper, EClient):
     def __init__(self):
         EClient.__init__(self, self) 

app = IBapi()
app.connect('127.0.0.1', 7496, 0)
app.run()

But it seems that the program will not end. It is in an endless loop. enter image description here

And the setting of my TWS is enter image description here

Yes that is by design. The run loop continuously processes any incoming messages from Trader Workstation since they are operating as a client and server across a network asynchronously.

Options for structuring an API program include:

  • using an asynchronous framework such as asyncio. This is done in the open source ib_insync library.
  • adding an additional thread to handle the run loop.

You would probably interested in the additional programs examples given in the:

IBKR Traders Academy Course for the TWS Python API

It has simple programs to do common tasks with examples of disconnecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM