Keyboard Shortcuts
Likes
Search
checking and reconnnecting python script after tws shutdown (or auto-restart)
Hi there, I am a newbie struggling with the reconnection of my python script after tws auto restarts (or manual restart for that matter). I know similar questions have been asked before and I am trying to follow this advice?to use connectionClosed callback but cant really seem to get it working.? my callback function: def connectionClosed(self): But it doesn't work. apparently the following error
? |
bump this thread
facing the same issue with settimeout the thing is the logic isConnected() ? > disconnect() > connect() is flawed by design, as the thread running the connection will terminate as it disconnects therefore a new thread needs to be created again for every re-connection, and all the objects in memory on the previous thread need to be transferred or lost |
Not sure that there is anything wrong with the connect/disconnect API design. Works well for many of us (and for some of us for decades). Also, not sure what objects of the previous reader thread need to be transported. The reader thread (I guess that is the one you are taking about) has only one purpose and contains no long-term state:
When your client is not connected yet (504) or an existing connection with TWS/IBGW is lost (502), no network socket exists and there is no need for a reader thread. When a new network connection exists upon a successful connect() , a new reader thread is created to process the messages as long as that socket exists. At any point in time, your client may voluntarily call disconnect()/connect() or, upon receiving an error 502, call connect() to reestablish the connection. In the architecture of your application stack, TWS API is way at the bottom as an "Adapter" with a very simple interface contract:
´³¨¹°ù²µ±ð²Ô On Sat, Jul 29, 2023 at 02:31 PM, John wrote: bump this thread |