How to disconnect from TWS

Discussion in 'Interactive Brokers' started by chami, Apr 21, 2020.

  1. chami

    chami

    I've been trying out scripts to get a feel of using the API, and in the process of changing the client ID I now have several connections through port 7497.

    How can I disconnect from them? Either one at a time or all at once?

    Here is what I've tried without success:


    from ibapi.client import EClient
    from ibapi.wrapper import EWrapper

    class IBapi(EWrapper, EClient):
    def __init__(self):
    EWrapper.__init__(self)
    EClient.__init__(self,self)

    app = IBapi()
    #app.connect('127.0.0.1', 7497, 103)
    app.disconnect()
    app.run()


    I would've thought I could put the client_id into app.disconnect() but it throws an error.

    I've enabled/disabled the "ActiveX and Sockets" setting in TWS but it seems like a crude method to use.

    Do you usually put app.disconnect() at the end of every function?
     
  2. FrankInLa

    FrankInLa

    Pull the plug. That simple

     
  3. maxinger

    maxinger

    upload_2020-4-22_8-52-41.jpeg
     
  4. TWS/Gateway monitors activity on the API connections. If a connection is not active for a certain amount of time will it be discarded. But I don't know how long it takes for this to happen.
     
  5. chami

    chami

    Is there a simple script to run to disconnect?

    It comes with a connection script, but replacing connect() with disconnect() doesn't seem to be the solution.
     
  6. Yes there is. But I don't program with Python and don't know the correct name for this disconnect command.
     
    chami likes this.
  7. FrankInLa

    FrankInLa

  8. chami

    chami

    FrankInLa likes this.