I’m about to start trading with IB through the python API. It will check on prices every half hour and possibly trade, depending on situations. should I open a connection to TWS once and close at end of the day, or should I open and close as needed, likely every 1/2 hour? thanks
%% I like to leave stuff open; if it dosent slam jam you up...........................................................................
Disconnecting, then waiting half an hour, followed by reconnecting is no problem. You can do this, or leave the connection open the entire day (or week). However, IB advises against immediately reconnecting after disconnecting (when using the same session id). I have had issues by doing so, after which IB gave me that advice. IB told me that their servers need some time to process the disconnect, cancelling any remaining streaming market data subscriptions and so on. The server may end up in an unclear state if you reconnect while this process is still ongoing. If, for some reason, you do want to reconnect immediately after a disconnect it is advisable to use a unique session id, different from the one you've previously used.