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

Prasanna895
Hi,
I am new to algo,after placing the order
I am getting the below error frequently every 5sec.
“Connection error: 1006 - connection was closed uncleanly (None)
Connection closed: 1006 - connection was closed uncleanly (None)”
can anyone please help me to use async python to resolve the above issue.
  • rakeshr
    @Prasanna895
    Are you placing order inside on_tick method?
    If yes, you need to create another method for order_placement and call that asynchronically from on_tick thread.
    You can go through this thread to know ways to use async method in main ticker.
  • Prasanna895
    Thanks for your response @rakeshr
    Already I am using separate method for placing the order and calculation. below are the code I am using.here I didn't use thread because I am using only one token.
    I tried queue method but it takes time for calculation .
    ****************
    def on_ticks(ws, ticks):
    dev(ticks)

    inst_token = [Token]
    def on_connect(ws, response):
    ws.subscribe(inst_token)
    ws.set_mode(ws. MODE_FULL, inst_token)




    kws.on_ticks = on_ticks
    kws.on_connect = on_connect
    kws.connect()
    *********************
    can you please check and let me know,If anything wrong in this code.
    waiting for you reply
  • rakeshr
    @Prasanna895
    def on_ticks(ws, ticks):
    dev(ticks)
    You shouldn't call method inside on_ticks thread unless you are using queuing.
    here I didn't use thread because I am using only one token
    You can create another thread with one token as well.You can go through 2nd example given in this link.
  • Prasanna895
    @rakeshr
    I tried that way also but on_ticks method which I have used inside while loop is not running
    only one on_ticks method is running.
    def on_ticks(ws,ticks):
    print(ticks)


    inst_token = [Token]
    def on_connect(ws, response):
    ws.subscribe(inst_token)
    ws.set_mode(ws. MODE_FULL, inst_token)

    kws.on_ticks = on_ticks
    kws.on_connect = on_connect
    kws.connect(threaded=True)
    while True:
    def on_ticks(ws,ticks):
    dev(ticks)

    def dev(single_company):
    *****
    calculation
    *****
    Please suggest any other solution for this, correct me if anything wrong in above code
  • Prasanna895
    @rakeshr @sujith please help me to resolve this
  • rakeshr
    @Prasanna895
    You need to assign call back in the threaded section for on_tick(*args).
    As below:
    while True:
    def on_ticks(ws,ticks):
    dev(ticks)

    def dev(single_company):
    *****
    calculation
    *****
    #Assign callback
    kws.on_ticks=on_ticks
Sign In or Register to comment.