While Fetching ticker data,Connection error: 1006 is occurring in every 5-10 min

neerleo88
Why Connection error: 1006 is occurring in every 5-10 minutes. Also its takes at least 20-30 sec to reconnect and some time it is taking more than 1-2 minutes. I am unable to get correct data for 5,10 min candles. Please find below errors at different times in a matter of just 1.5 hours.
Please note : I am fetching data foe Nifty Bank Index (260105)

0 2019-01-14 09:34:45 27253.6
ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (None)
ERROR:root:closed connection on error: 1006 connection was closed uncleanly (None)
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (None)
0 2019-01-14 09:35:03 27251.95


Below it took more than 1 min
0 2019-01-14 09:38:03 27265.35
ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (None)
ERROR:root:closed connection on error: 1006 connection was closed uncleanly (None)
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (None)
ERROR:kiteconnect.ticker:Retrying connection. Retry attempt count: 1. Next retry in around: 3 seconds
ERROR:kiteconnect.ticker:Retrying connection. Retry attempt count: 2. Next retry in around: 10 seconds
0 2019-01-14 09:39:15 27264.55


0 2019-01-14 10:00:29 27231.05
ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (None)
ERROR:root:closed connection on error: 1006 connection was closed uncleanly (None)
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (None)
0 2019-01-14 10:00:36 27228.7

0 2019-01-14 10:12:54 27231.85
ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (None)
ERROR:root:closed connection on error: 1006 connection was closed uncleanly (None)
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (None)
ERROR:kiteconnect.ticker:Retrying connection. Retry attempt count: 1. Next retry in around: 3 seconds
0 2019-01-14 10:13:23 27224.65

0 2019-01-14 10:26:03 27231.6
ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (None)
ERROR:root:closed connection on error: 1006 connection was closed uncleanly (None)
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (None)
ERROR:kiteconnect.ticker:Retrying connection. Retry attempt count: 1. Next retry in around: 2 seconds
0 2019-01-14 10:26:33 27233.7
  • neerleo88
    Can somebody check above error . Today also I am getting the same error , Please find below the error

    0 2019-01-15 10:00:53 27389.6
    0 2019-01-15 10:00:54 27388.2
    ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (None)
    ERROR:root:closed connection on error: 1006 connection was closed uncleanly (None)
    ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (None)
    ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket opening handshake timeout (peer did not finish the opening handshake in time))
    ERROR:root:closed connection on error: 1006 connection was closed uncleanly (WebSocket opening handshake timeout (peer did not finish the opening handshake in time))
    ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (WebSocket opening handshake timeout (peer did not finish the opening handshake in time))
    ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket opening handshake timeout (peer did not finish the opening handshake in time))
    ERROR:root:closed connection on error: 1006 connection was closed uncleanly (WebSocket opening handshake timeout (peer did not finish the opening handshake in time))
    ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (WebSocket opening handshake timeout (peer did not finish the opening handshake in time))
    0 2019-01-15 10:01:51 27390.7
    0 2019-01-15 10:01:52 27391.2
  • neerleo88
    Please find below the code I am using

    import win32com.client
    import time
    import logging
    from kiteconnect import KiteConnect
    from kiteconnect import KiteTicker
    import datetime
    from datetime import timedelta
    #from datetime import time
    import pandas as pd
    import numpy as np
    import logging
    import pymysql

    db=pymysql.connect(host='localhost',user='root',password='*********',database='ticker_value')
    insert_query='insert into nifty_bank_2(date,last_price) values(%(date)s,%(last_price)s)'

    def insert_ticks(ticks):
    db_cursor=db.cursor()
    for tick in ticks:
    db_cursor.execute(insert_query,{'date':tick['timestamp'],'last_price':tick['last_price']})
    try:
    db.commit()
    except Exception:
    db.rollback()

    api_key="**********"
    api_secret="**************************"
    kite=KiteConnect(api_key=api_key)

    data = kite.generate_session("*****", api_secret=api_secret)
    access_token=data["access_token"]
    kite.set_access_token(access_token)
    tokens=[260105]
    kws=KiteTicker(api_key, access_token)
    def on_ticks(ws,ticks):

    data1 = pd.DataFrame(ticks)
    print(data1[["timestamp","last_price"]].to_string(header=False))
    insert_tick=insert_ticks(ticks)
    def on_connect(ws,response):
    ws.subscribe(tokens)
    ws.set_mode(ws.MODE_FULL,[260105])
    def on_close(ws,code,reason):
    ws.stop()
    def on_order_update(ws, data):
    print("order update: ", data)
    def on_noreconnect(ws):
    logging.error("Reconnecting the websocket failed")
    def on_error(ws, code, reason):
    logging.error("closed connection on error: {} {}".format(code, reason))
    def on_reconnect(ws, attempt_count):
    logging.debug("Reconnecting the websocket: {}".format(attempt_count))

    kws.on_ticks = on_ticks
    kws.on_connect = on_connect
    kws.on_error = on_error
    kws.on_noreconnect = on_noreconnect
    kws.on_reconnect = on_reconnect
    kws.on_order_update = on_order_update
    kws.connect()
  • rakeshr
    @neerleo88
    Please don't create multiple thread for same query.We have answered your above query here.
This discussion has been closed.