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

pat11 edited October 1 in Python client
Dear @rakeshr i went by all through this forum for this connection error solution and even tried which you given before regarding my query.

I also fully tried this method by implementing Celery and Redis server in my application and now it's perfectly streaming after getting tick in one thread and performing other tasks in another thread.

The thing is sir after streaming for more than 2-3hrs continuously I'm again getting the same connection error : 1006 very repeatedly but after 4-5 seconds again it's getting reconnected and streaming goes on .

After streaming for more than 2-3hrs this connection error is happening a lot of times and for sure I'm having a lot of data lags and inconsistency
in my data.

So sir is there any permanent solution to this or any API calls through which i can keep on reconnecting to the kite server without any connection error : 1006 while full day streaming.

Any ideas regarding this would be very much appreciated sir . :smile:
  • sujith
    Looks like your firewall might be blocking or limiting the websocket connection.
  • pat11
    Hey @sujith sir thanks for your valuable opinion but sir I'm using an AWS EC2 console for my streaming purpose and there network and firewall seems to be very much great .

    Any thing else could be helpful sir .
  • pat11
    Hey @sujith and @rakeshr sir i also tried unblocking the port 80 and 443 in the inbound rules of my websocket connections on windows ec2 but still i'm facing the same issue.

    After running the stream for more than 2-3hrs the connection error : 1006 is happening continuously and getting reconnected after a max of 5 seconds.

    But sir due to this i'm having data lag which will make my order placing functions dumb and due to this my order's will miss the oportunities.

    Any helpful API function will be helpful sir other than on.connect () , on.tick() and on.close() methods.
  • rakeshr
    After running the stream for more than 2-3hrs the connection error : 1006 is happening continuously and getting reconnected after a max of 5 seconds
    This can only happen if there is some factor that is blocking the event loop.
    As an alternative, you need to handle this disconnection and try quote call for the required list of instruments.
  • pat11
    pat11 edited October 5
    But @rakeshr sir my whole programming depends upon full day real time streaming data and for that i'm using web socket connection which is very important i think.

    Regarding quote call it only retrieve's huge historical data at the time of the request.
    Can i use quote for streaming purpose as well sir ?

    And @rakeshr if full streaming can be done through quote api call can you please show me how to do the same , sir i'm getting desperate to solve the issue from my end sir please.

    Your valuable opinion and idea matter a lot to me sir.
  • rakeshr
    Regarding quote call it only retrieve's huge historical data at the time of the request.
    No, it doesn't retrieve historical data but only a snapshot of WebSocket data at that request time. You can go through documentation here to know more.
    Can i use quote for streaming purpose as well sir ?
    No, it's not recommended.

    You can use quote call, only for the time, there is disconnection(as you mention it's for few seconds only). Once WebSocket re-connects, you can continue updating from WebSocket streaming.
  • pat11
    Dear @rakeshr your idea seems good but i think i've to go through lot of difficult data manipulation.

    Sir is there any way to renew our web socket connection with the server after 2hrs.

    Because from beginning it works well until the first 2-3hrs and then the problem arises so i was thinking of renewing my web socket connection after every 2-3hrs so that there will be new connection and the problem will be resolved.

    So finally any way to RENEW WEBSOCKET connection after a given certain time of loop will be helpful in solving the issue sir.

    If really any api calls is there can you please specify me @rakeshr @sujith sir.
  • rakeshr
    Sir is there any way to renew our web socket connection with the server after 2hrs.
    No, there is nothing like Websocket renew.
  • sujith
    You can use Kite Ticker with reconnect option on pykiteconnect. You can know more here.

    pykiteconnect will handle reconnection for you and manage subscriptions after reconnection.
  • pat11
    pat11 edited October 6
    @sujith sir how much time will the on_reconnect method will take when implemented ?

    If it's just matter of milliseconds then it's gonna work unless it won't.

    Under my issue that connection error 1006 also happens for a maximum of 5sec and if reconnect will not take more than a 0.5second then it gonna work wonder for me sir.

    And @sujith ,@rakeshr sir i think this issue is happening from kite server side because a lot people are now complaining the same thing as i'm experiencing right now , if you could please try to solve it from your side also then it'll be boon for the whole kite connect community.
  • pat11
    @rakeshr sir and @sujith sir any updates on this please .
  • rakeshr
    For python client WebSocket, re-connection attempts starts from 2 seconds and it keeps increasing exponentially. You can go through a detailed explanation here.
  • pat11
    Hlo @rakeshr sir and @sujith sir do you know any specified port for web sockets and TCP/UDP which could be blocked by the firewall while streaming for a longer time length.

    If there is any can you please specify those ports so that i can unblock those ports on my firewall.
  • npchoubey
    hello Pat,
    if you fixed the issue then do let us know.
    if not, you may check memory/cpu usage of your EC2 instance when u start getting this error.
    specially look if you see memory usage increasing for your processes.
  • pat11
    Hlo @npchoubey

    Thanks for your valuable opinion i'll surely do have a thorough check and will inform here.
    In my case i've seen that when there is a low internet speed less than say 10kbps this error happens and most of the times it happens after 02:00PM.

    I always start my streaming from sharp morning 09:15 to closely look at the issue and this problem always starts after 02:00PM.
    So i think there must be some mismanagement from their side as it only happens in the closing session of the market.

    @sujith sir and @rakeshr sir can you please have a look on this problem because a lot of people are now complaining regarding this.
  • pat11
    pat11 edited October 12
    Hlo @npchoubey

    I tried a lot but not able to find any suitable solution to this error.
    I also kept a very close eye on the memory usage and live cpu but it remains normal throughout the streaming process when this error starts happening regularly after 02:00PM every day.

    From my deep analysis i think that this is a server side problem from zerodha and always keeps happening after 02:00PM only.

    I request @sujith sir and @rakeshr sir to please look after this situation because after 02:00PM the web socket connection is getting very weak and always keeps on dropping after every 10 - 15 seconds of streaming and due to this we're having a huge data lag of 4 to 5 seconds every time.

    I also cross checked if any external factor blocking the main thread in the streaming process but nothing is there in between the main thread because I'm using celery and redis to perform my other operations but still getting the error after 02:00PM while the same code is streaming perfectly from 09:15AM till this time.

    Then what anonymous thing happens after 02:00PM that this error arises oftenly. So clearly it's a server side from zerodha.

    I once again request to kite connect technical team and especially @sujith sir and @rakeshr to please look on this serious concern we're facing while streaming.
Sign In or Register to comment.