softwarespartan / IB4m

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

Closing an open connection #114

Closed ajdore closed 3 years ago

ajdore commented 3 years ago

Sorry for the very basic question but I didn't see it in the docs/examples. How do you close an open session?

For example, I've set up an open connection to pull data on a live account:

session.eClientSocket.eConnect('127.0.0.1',7496,0);

Now, close the live account connection above, and connect to the paper trading account to trade

session.eClientSocket.eConnect('127.0.0.2',7497,0);

Both paper and live accounts are open on TWS concurrently and the sockets etc have been configured accordingly in each account.

softwarespartan commented 3 years ago

Thanks for asking - the IB api call is eClientSocket.eDisconnect.

https://interactivebrokers.github.io/tws-api/classIBApi_1_1EClient.html#a7d9ed965cf5738965bcfb482aad494c3

You can also check out the delete function in the +TWS/Session.m src file. This function cleans up all listeners and closes the TWS connection. This function also gets called automatically if session obj goes out of scope (eg clear sess or clear all)

ajdore commented 3 years ago

thank you!