softwarespartan / IB4m

Interactive Brokers API for Matlab
GNU General Public License v2.0
61 stars 21 forks source link

Why does the .isConnected check return true in virtually all scenarios of disconnect? #132

Open ecpgieicg opened 3 years ago

ecpgieicg commented 3 years ago

Why does the .isConnected check return true in virtually all scenarios of disconnect?

For example, I just queried the method (which is during the IB server reset time):

-1 1100 Connectivity between IB and Trader Workstation has been lost.

>> session.eClientSocket.isConnected

ans =

  logical

   1

-1 1100 Connectivity between IB and Trader Workstation has been lost.

-1 1100 Connectivity between IB and Trader Workstation has been lost.

Is the behavior of .isConnected as intended?

Is there a different check for connectivity that would fail if connection to IB server fails? afaik .isConencted check will only fail if no connection has been made between the client on Matlab and IB Gateway/TWS.

The main issue I face with the lack of connectivity check is the erroneous no contract message that either IB Gateway/TWS or the API automatically returns when one makes a .reqContractDetails query (and possibly in other situations) during connection outage with IB server.

(I currently circumvent the issue for internet outage by pinging a few reliable destinations. Although even there, the circumvention fails when internet outage/connectivity is intermittent and so ping still doesn't serve as a reliable connectivity check.)

Despair2000 commented 3 years ago

I wrote a little function that probes the IB status page: https://www.interactivebrokers.com/en/index.php?f=2225

When there is a scheduled maintenance at the weekend for example it is often still possible to connect to the server but some functions don't work properly. There isConnected fails but running my little probe-function solved the problem.

softwarespartan commented 3 years ago

Keep in mind that ‘isConnected” only testing is connected to the local TWS instance. I looked at the code for that function and the ib api likely has a bug there in the disconnect call which doesn’t clean up the vars that isConnected is testing. Either way, that method won’t be able to say anything about if TWS can talk with the remote IB servers to process your api calls. I’ll see if there is easy fix for the api methods and push update

ecpgieicg commented 3 years ago

Thanks!