Frequent Disconnections

prakash.jj
HI,

Is there a way to increase the timeout for websocket in python client. I am facing too many disconnects from last couple of days. Not sure why this happens.

I even tried using ws.reconnect on on_close method, but thats working. Its not reconnecting.

Its really annoying to see this error.
  • sujith
    Hi @prakash.jj,
    We are planning to release reconnection feature for pykiteconnect by the end of this week, it will resolve your issue.
  • prakash.jj
    Is this released yet?
  • ankur0101
    @sujith , looking at the forum, I feel kite API is half baked cake and charging a fee for this is not good at all. It's like people are paying for service and not getting it properly. Instead of this, why don't you give it as a free to users and perform beta testing?
  • naz
    @sujith @Kailash : I would agree with @ankur0101 on this. Also, since kite API is based on Python, at least python websocket client should have been a stable one and should have been the first one for new stable features like reconnect (based on tick).
    On the other hand it looks like python websocket client is the least stable and last to get feature updates.
    While I was going through other threads, people have reported that they have gotten 90+ disconnections throughout the day on python websocket client (i.e. one disconnection every 4 min). Also, all disconnections (at least in my case) are the ones where Zerodha server is closing/Terminating connection. Any specific reasons for this.

    Would request your urgent attention on this - else, I am not sure how to go ahead with automated trading using Kite APIs when data sanctity is in question.
  • prakash.jj
    It's like clients are paying money as well as testing the KiteAPI for Zerodha. Why don't Zerodha does proper testing of the services and then start collecting the fee. On one hand Zerodha collecting money for API development from clients and also getting clients test their API. Not stable at all.
  • prakash.jj
    @sujith is this resolved yet?
  • Vivek
    @prakash.jj Here is a beta version of PyKiteconnect with auto reconnect feature -
    https://github.com/rainmattertech/pykiteconnect/tree/reconnection
    Only change you need to make to your code will be enabling auto reconnect (its not enabled default)

    kws.enable_reconnect(reconnect_interval=5, reconnect_tries=50)
  • naz
    @vivek Thanks a tonne.

    1) Should we just do a "pip install pykiteconnect" for this upgrade ? Or we need to clone/download it?
    2) where should we put the line "kws.enable_reconnect(reconnect_interval=5, reconnect_tries=50)" in our code - just before calling ws.connect() ?
  • sujith
    Hi @naz,
    You will have to clone the repo and try it.
    Check out usage information here.
  • prakash.jj
    after the installation getting this error

    AttributeError: 'WebSocket' object has no attribute 'enable_reconnect'

    Also, is there any issues today with socket. The socket keeps closing after few secs of connecting and now I am not even able to issue ws.reconnect() or kws.connect() in on_close() call back method.
  • naz
    naz edited April 2017
    @vivek @sujith : same issue. can you please use it at your end first and let us know.

    AttributeError: 'WebSocket' object has no attribute 'enable_reconnect'

    Issue seems to be as below:
    setup.py in the beta version doesn't seem to be configured properly.
    Build and setup seems to be broken. I did "python setup.py install" and still program is taking old "__init__.py".

  • prakash.jj
    I got the new package installed by doing the below command

    pip install directory where setup.py exists

    now also, the socket is getting closed every second. and its reconnecting. there is really something wrong with the socket connection today.
  • naz
    @prakash.jj : figured out a quick fix - setup.py was not building/setting up the new files in python packages hence there was an error.

    I copied "__init_.py" and "exceptions.py" from the beta version package folder "C:\Users\xxxxx\Desktop\pykiteconnect-reconnection\kiteconnect"

    to below folder and overwrote the old files.

    "C:\ProgramData\Anaconda3\Lib\site-packages\kiteconnect"


    It has at least started working now (since enable_reconnect method is present in the beta version of __init__.py). Need to see if auto-reconnect actually works.
  • naz
    naz edited April 2017
    @vivek @sujith : am using the beta version now (and running 3 websockets)

    Following is the issue - first disconnection gets reconnected successfully. On second disconnection, no reconnection is made.
    Can you please check the code and see if all the disconnections are covered or only first.
  • Vivek
    @naz I ran it for the entire day and I could see it got disconnected few times and automatically picked up. A simple exercise to test is to run it and disconnect your wifi for few seconds and then connect it back.

    @prakash.jj Maybe you are this in Ubuntu 14.04 or other Linux which has issues with OpenSSL. You can try sending disable_ssl_verification as True while connecting.

    kws.connect(disable_ssl_verification=True)
  • Vivek
    Vivek edited April 2017
    For people having issue with installing.

    1. Uninstall current kiteconnect package or create a new virtualenv to test. (pip unininstall kiteconnect)
    2. Install the new package from Github branch -
    pip install https://github.com/rainmattertech/pykiteconnect/archive/master.zip
  • pinkpanther
    @vivek I am facing frequent disconnections. I am on Ubuntu 14.04 and using JavaConnect.
    Is there any parameter disable_ssl_verification=True for the Java wrapper?
  • sujith
    sujith edited April 2017
    @pinkpanther,
    You can do it using NaiveSSLContext
    It will just accept all certificates.

    You will have to set this naive context to your websocket factory. Code looks like this,
    WebSocketFactory wsf = new WebSocketFactory();
    SSLContext context = NaiveSSLContext.getInstance("TLS");
    wsf.setSSLContext(context);
  • naz
    naz edited April 2017
    In case, any other community member is also facing frequent disconnection issue, it might be good to check if you are doing heavy data processing/saving work inside on_tick() function. In my case, frequent disconnection was happening because heavy data processing/saving work (inside on_tick() ) was not getting completed before another on_tick() call back.

    @sujith @vivek : thanks for your support and patience so far. Really appreciate you keeping up with all the queries of almost all the community members.
This discussion has been closed.