KiteTicker keeps connecting and disconnecting

c00kie
I keep getting these two messages every minute or two
Connection error: 1006 - connection was closed uncleanly (None)
Connection closed: 1006 - connection was closed uncleanly (None)
this only started happening once I moved to kite3. Could you let me know the reason for this?
  • zartimus
    @c00kie Can you post the code here?
  • c00kie
    c00kie edited May 2018
    def on_ticks(ws, ticks):  
    topic.publish(pickle.dumps(ticks))
    for ticker in ticks:
    pickled_object = pickle.dumps(ticker)
    redisconn.lpush(str(ticker['instrument_token']),pickled_object)
    redisconn.set(getname(ticker['instrument_token']),pickled_object)

    def on_connect(ws, response):
    logger.info("connected to ticker")
    ws.subscribe(tokens)
    ws.set_mode(ws.MODE_FULL,tokens)

    def on_reconnect(ws, attempts_count):
    logger.info("attempting to reconnect to ticker")

    def on_noreconnect():
    logger.error("could not reconnect to to the ticker")
    sendSlackNotification("all attempts to reconnect to ticker have failed please check server","TickerSystem","process")

    def on_close(ws, code, reason):
    logger.info("connection with ticker closed")

    def on_error(ws, code, reason):
    logger.info("connection closed with ticker with error: " + str(reason))





    kws.on_ticks = on_ticks
    kws.on_connect = on_connect
    kws.on_reconnect = on_reconnect
    kws.on_noreconnect = on_noreconnect
    kws.on_close = on_close
    kws.on_error = on_error


    def connectTicker():
    createTokenList()
    kws.connect(disable_ssl_verification=True)

    def disconnectTicker():
    kws.close()
  • zartimus
    @c00kie Dont see any issues here. Few qns. How are you invoking disconnectTicker?
    Can you use debug flag on kiteticker and post the logs?
    Why do you use pickle serialisation instead of json?
  • c00kie
    • I am invoking disconnectTicker only when I close my process for the day, at the end of that day.
    • The reason I using pickle is because Kite is sending python date time objects for all day fields, and sending pickled objects across pubsub helps me create data frames for computation much easier .
    I have tried making everything inside on_ticks async but that does not help and the disconnection is not on every tick. It happens exactly every 2-3 minutes. I thought my code was blocking It but that does not seem to be the case.

    I will run code with the debug flag and post the log here.
  • c00kie

    These are the logs, its the same thing repeated again:
    2018-05-15 12:02:48+0530 [-] dropping connection to peer tcp4:52.66.29.203:443 with abort=True: None
    2018-05-15 12:02:48+0530 [-] Connection error: 1006 - connection was closed uncleanly (None)
    2018-05-15 12:02:48+0530 [-] Connection closed: 1006 - connection was closed uncleanly (None)
    2018-05-15 12:02:48+0530 [-] will retry in 2 seconds
    2018-05-15 12:02:48+0530 [-] Stopping factory
    2018-05-15 12:02:51+0530 [-] Starting factory
  • zartimus
    zartimus edited May 2018
    @c00kie Did you rule out network issues at your end? Can you once run ticker example from the pykiteconnect repo.
    https://github.com/zerodhatech/pykiteconnect/blob/kite3/examples/ticker.py

    You can add serializer for json.dumps using `default` param. See this
  • c00kie
    c00kie edited May 2018
    • The application is running on a vm so there shouldn't be any network problems. Also there were no problems like this on Friday last week, It only started once we moved to kite3.
    • I tried using the json serialization as specified by you, but it did not help.
    • The example is running fine with no disconnects.
  • c00kie
    I fixed this problem by wrapping the whole kiteTicker in async loop. You can close this issue
This discussion has been closed.