4
$\begingroup$

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):
    print(msg)

def acct_update(msg):
    print(msg)


con = ibConnection(clientId=100)
con.register(acct_update,
         message.updateAccountValue,
         message.updateAccountTime,
         message.updatePortfolio)
con.register(error_handler, "Error")
con.connect()
con.reqAccountUpdates(True, 'DU000000')

sleep(1)
con.disconnect()

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?

$\endgroup$
1
  • 2
    $\begingroup$ I’m voting to close this question because it is more of an IT-related operational question. $\endgroup$
    – KaiSqDist
    Commented Nov 29, 2023 at 17:30

1 Answer 1

0
$\begingroup$

you forgot the parameter port:

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

works for me

$\endgroup$

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