As discussed and fixed here:
http://code.google.com/p/ibpy/issues/detail?id=2If you try to reconnect to TWS following a disconnect and the socket hasn't been shut down, you get the following error:
## error:
code=326 message=Unable connect as the client id is already in use. Retry
with a unique client id.
Since the above fix was on a very old version of IB API, I rebuilt IBpy based on the 9.64 TWS. When I try to apply the above fix manually to the eDisconnect() function in EClientSocket, I found that the code has changed so I'm not sure what to modify. Here is the old code and the fixed version next to it (scroll down until you see green highlight)
http://code.google.com/p/ibpy/source/diff?spec=svn292&r=292&format=side&path=/trunk/ib/ext/EClientSocket.py
Notice this line was added after "if self.m_socket is not None:"
self.m_socket.shutdown(self.m_socket.SHUT_RDWR)
But in my EClientSocket.py, my eDisconnect function looks like this:
def eDisconnect(self):
if self.m_dos is None:
return
self.m_connected = False
self.m_serverVersion = 0
self.m_TwsTime = ""
dos = self.m_dos
self.m_dos = None
self.reader = self.m_reader
self.m_reader = None
try:
if self.reader is not None:
self.reader.interrupt()
except (Exception, ), e:
pass
try:
if dos is not None:
# dos.shutdown(dos.SHUT_RDWR) TRIED ADDING THIS LINE BUT DIDN'T WORK
dos.close()
except (Exception, ), e:
pass
Any help would be much appreciated!
-Viraj