Connection Error 1006

chiragkeswani
Hello everyone,
For past few days, I am continuously facing web socket disconnection issue. I am generating candles using the web socket data. But as web socket gets disconnected, it is not able to collect all the ticks and create correct candle. Below is the error:

Connection closed: 1006 - connection was closed uncleanly (None)
Connection error: 1006 - connection was closed uncleanly (None)

Whole log file is filled with this only. I have been trying to find the solution for the same on the forum but it's not working.
I would really appreciate the help. Thanks in advance.

Thanks, Regards,
Chirag Keswani
  • rakeshr
    @chiragkeswani
    Can you check if you are not blocking on_tick method in any condition? If you are performing any additional calculation on on_tick method, you need to pass it to a different thread to prevent blocking of the on_tick method.
  • chiragkeswani
    @rakeshr
    Yes, I checked that. It is not blocking on_tick method at all. I am just initiating a new thread once I receive the tick.
    It was working fine for long time but once I setup it on a new system, it has started giving this issue. Any chance there is any problem in configuration?
  • rakeshr
    @chiragkeswani
    Can you paste here your WebSocket code,we will look to it?
  • gkaranam
    Hi @rakeshr

    i am also facing the same issue where i continuously get the below errors.

    Connection closed: 1006 - connection was closed uncleanly (None)
    Connection error: 1006 - connection was closed uncleanly (None)

    Pasting my websocket and connection code for your reference.
    ----------------------------------------------------------------------------------------------------------------------
    def on_ticks(ws, ticks): # retrieve continuous ticks in JSON format
    global ohlc_final_1min, RENKO_Final, final_position, order_quantity
    try:
    for company_data in ticks:
    if (company_data['last_trade_time'].time()) > datetime.time(9, 15,00) and (company_data['last_trade_time'].time()) < datetime.time(15, 31,00):
    calculate_ohlc_one_minute(company_data)
    RENKO_TRIMA(company_data)
    except Exception as e:
    traceback.print_exc()


    def on_connect(ws, response):
    ws.subscribe([x for x in trd_portfolio])
    ws.set_mode(ws.MODE_FULL, [x for x in trd_portfolio])


    kws.on_ticks = on_ticks
    kws.on_connect = on_connect
    kws.connect()
    ----------------------------------------------------------------------------------------------------------------------

    Can you please look into this, as i am not using the historical data and am using the ticks to form my analysis and decision.
  • rakeshr
    @gkaranam
    You are blocking on_tick method by calling internal methods within.You need to pass it as thread without blocking it, check multi-threading example here.
  • gagneetkalsi
    gagneetkalsi edited June 10
    Hi @rakeshr ,

    I have the same error.

    Without fail, it gives me an error at 9:16 when I try to do some computations in a different thread, but then it runs rather smoothly throughout rest of the day.
    Just when I try to do some calculations at 9:16, it fails. And it happens everyday at the same time. If there was a problem with the ticker code, I should face this issue throughout the day, but I can't figure out why it is always at the same time.


    My ticker code is as follows:

    def on_ticks(ws, ticks):
    global TICKS
    TICKS = TICKS.append(pd.DataFrame(ticks)[['instrument_token','timestamp,'last_price']],ignore_index=True)

    def on_connect(ws, response):
    ws.subscribe(Data.instrument_token.tolist())
    ws.set_mode(ws.MODE_FULL,(Data.instrument_token.tolist())

    # Assign the callbacks.
    kws.on_ticks = on_ticks
    kws.on_connect = on_connect

    kws.connect(threaded=True)
  • rakeshr
    @gagneetkalsi
    Can you implement on_error method and paste the complete error log here?
    Also, we will check the same at our end for threading error at 09:16 AM.
Sign In or Register to comment.