Reconnection time

pinkpanther
I am facing frequent disconnections in the streaming data...what is the minimum time it takes to reconnect?
Tagged:
  • sujith
    @pinkpanther,
    What KiteConnect client are you using?
  • pinkpanther
    pinkpanther edited May 2017
    Java client is what I am using...
    Also why should it be client centric?
    When I use normal Websocket apis to connect right after disconnectoin,it fails..i wait for 2 seconds after which I connect and subscribe the tokens,but it fails..what is going on?
  • sujith
    @pinkpanther,
    The feature is not client centric but my answer is.
    In java, you can setTimeIntervalForReconnection(). It is based on user's input but minimum value is 5 seconds.
    You need use OnConnected event for the subscription. Check out usage example here.
  • pinkpanther
    Let me say I am using no client ..but just plain websockets,lets say choice of language is perl/julia and ondisconnection I am connecting again,without any waiting time,logically it should work right?But its not working
  • sujith
    @pinkpanther,
    When there is an abrupt change in network or disconnection. OnDisconnect is not called immediately. Hence we have a different mechanism for reconnection.
    Kite Connect client keeps checking every second if tick arrived, if there is no tick for 5 seconds then it will reconnect.
  • pinkpanther
    @sujith thanks for the explanation...i am not using kiteconnect..but normal REST APIs therefore the check that you mentioned for 5 seconds doesnt hold valid in my code.
    For me what i am doing is if i there is a disconnection, i am reconnecting again at the same second or after 1 second...it should work right?
  • sujith
    @pinkpanther,
    If you are looking for uninterrupted Kite Ticker then you need to implement reconnection same way as we have implemented.
    You must be expecting onDisconnect event when there is disconnection but it is not called. Hence we added a different mechanism for reconnection.
  • pinkpanther
    in my case ondisconnection is being called,but as soon as I try to connect it again,the ticks dnt come
  • sujith
    You need to subscribe after you get onConnected event.
  • pinkpanther
    pinkpanther edited May 2017
    yes.. i do subscribe after reconnection..the very second i do this but the ticks donot come... its normal connection i do again
  • sujith
    Can you create a gist of your code and paste the link here? We will check and get back to you.
  • pinkpanther
    from kiteconnect import WebSocket

    # Initialise.
    kws = WebSocket("your_api_key", "your_public_token", "logged_in_user_id")

    totalTokens=[]

    # Callback for tick reception.
    def on_tick(tick, ws):
    print tick

    # Callback for successful connection.
    def on_connect(ws):
    # Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
    ws.subscribe(totalTokens)

    # Set RELIANCE to tick in `full` mode.
    ws.set_mode(ws.MODE_FULL, [738561])

    def on_disconnect(ws):
    print "Connection is dropped...subscribing again"
    on_connect()

    # Assign the callbacks.
    kws.on_tick = on_tick
    kws.on_connect = on_connect
    kws.on_disconnect=on_disconnect

    # Infinite loop on the main thread. Nothing after this will run.
    # You have to use the pre-defined callbacks to manage subscriptions.
    kws.connect()


    This is what i am doing..plainly connecting again when there is disconnection..but this doest work..I get that the connection happens and the ticks are subscribed..but nothing comes..
  • sujith
    Hi @pinkpanther,
    I would suggest using our reconnect feature provided by new beta pykiteconnect version as connect inside disconnect is not a reliable way for reconnection.
    You can check out this thread for more information.
This discussion has been closed.