Websockets : connection is closed


I am trying to read streaming real time data and the websocket connection closes with the exception:

webSocketConnectionClosedException: Connection is already closed.

What could be causing it and whats the workaround?


The main reason the server would disconnect is if you send a message it doesn’t understand. The exception you posted is not from the server but from your client library so it’s hard to say more about the cause.

You can stream data with the CLI (quantrocket realtime stream) to verify it works before trying to implement a connection over Python.


When I stream from CLI, with the conid and lastprice filter. It gives nothing. The exception is thrown only when it is getting the last price data. See attached.


To get streaming data, all of the following must happen:

  1. You must tell QuantRocket to collect the data.
  2. You must have permission for the data with IB. (No permission errors in flightlog).
  3. The security must be actively trading at the time.

If you’re not getting data, one of those isn’t happening.