简体   繁体   中英

Connecting to IB TWS using IBpy

I downloaded the standalone TWX for Mac OS X. Then I also installed IBpy through pip. I have the TWX open and I ran the following lines:

from ib.opt import ibConnection
con = ibConnection()
print(con.connect())

However, it prints False. What am I doing wrong? In TWX I have the localhost IP 127.0.0.1 as a trusted address.

You also have to check "enable activex and socket clients" in the API settings. There may be a bug in newer versions 950-952 where you don't specify 127.0.0.1, but instead check the box where it says "allow connections from localhost only". I haven't tested that, but have read about it.

If you use IB gateway, "enable socket clients" isn't required as the only way to use it is with an API. Note that gateway is port 4001 by default. Use con = ibConnection(port=4001,clientId=123)

You're connecting with clientId 0, you could use con = ibConnection(123) for example to use a different clientId.

Don't forget to call con.disconnect() to close the connection or the server won't allow you to re-connect using that id.

add: here's the bug I read about at IB-API yahoo user group.

But as soon as I uncheck 'Allow connections from localhost only', it won't accept connections from any address, not even local ones (ie even with 127.0.0.1 as a Trusted IP address).

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