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

syker
I was getting the above-mentioned error. Hence, I made certain changes in my code to rectify this error, but it didn't work for me. Can you tell me how else can I remove this error?

def on_ticks(ws, ticks):
save_data(ticks)
#my strategy run in this function

kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect(threaded=True)

while True:
time.sleep(2)

The "threaded=True" helps in manually calling the quotes and I am putting this function on sleep for 2 seconds. After doing this, my strategy function has time for 2 seconds to completely run the code and close it cleanly, but still, I am getting a connection error.
  • sujith
    Once you run Kite Ticker, it keeps receiving ticks. You shouldn't block the thread at all. You need to offload your calculations to a secondary thread.
  • syker
    Alright, so I will remove the "threaded=True" and sleep time. But I have a few more questions:
    1. I have used save_data(ticks) in my on_ticks function. So, it means that I have already offloaded my calculations to a secondary thread.. right?
    2. Is there any way I can stop receiving this error on my output pannel as I am unable to track my outputs of the code using "print". This error keeps on flooding my panel.
    3. Is there any method/setting of the function using which I can slow down the receiving ticks ??
  • rakeshr
    I have used save_data(ticks) in my on_ticks function. So, it means that I have already offloaded my calculations to a secondary thread.. right?
    No, you are not offloading it but blocking the single running thread. To offload, first, you need to create another parallel thread and then offload it gracefully. You can go through this thread to know more.
    Is there any way I can stop receiving this error on my output pannel as I am unable to track my outputs of the code using "print". This error keeps on flooding my panel.
    You need to offload ticks gracefully. Go through the above thread.
    Is there any method/setting of the function using which I can slow down the receiving ticks ??
    It directly streams data from the exchange. We don't any setting to hide/slow down the ticks. You need to do this at your end.
  • syker
    syker edited December 2020
    Thanks a lot, @rakeshr . I have gone through the post regarding offloading. I think the celery or rq method might delay the code functioning. So, I will go with your second option and try to implement it. I will let you know in case of any issue. Below is just the gist of what you suggested in the thread for offloading.


    kws.connect(threaded=True)
    while True:
    #Perform required data operation using tick data
    def on_ticks(ws, ticks):
    ..........
    helper_method(ticks)
    .........

    def helper_method(ticks):
    .........
    Perform computation here
    ........
    #Assign callback
    kws.on_ticks=on_ticks
Sign In or Register to comment.