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.
@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.
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)
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 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)
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.
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
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
You need to assign call back in the threaded section for on_tick(*args).
As below: