I am using ibPy to connect to TWS on a fairly fresh ubuntu machine. I have been successful in logging into the paper trading account and submitting buy and sell orders programatically via the ibPy interface.

However, I am now trying to do more than simply submit orders. Namely, I am trying to obtain position updated from TWS. I am interested in successfully running the following code:

from time import sleep
from ib.opt import ibConnection, message

def error_handler(msg):

def acct_update(msg):

con = ibConnection(clientId=100)
con.register(error_handler, "Error")
con.reqAccountUpdates(True, 'DU000000')


When executed however I obtain the following error:

<error id=-1, errorCode=502, errorMsg=Couldn't connect to TWS.  
Confirm that "Enable ActiveX and Socket Clients" is enabled on 
the TWS "Configure->API" menu.>

I have ensured that indeed ActiveX and socket clients are enabled in the TWS preferences, so that is not the issue. It surprises me that I would be able to submit orders successfully but not obtain account updates from TWS. Does anyone know why this could be happening?

  • $\begingroup$ I’m voting to close this question because it is more of an IT-related operational question. $\endgroup$
    – Kai
    2 hours ago

1 Answer 1


you forgot the parameter port:

con = ibConnection(port=7497, clientId=100)

works for me


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.