Is there any issue today, getting error : Connection error 1006

vaishali
today getting error: Connection error 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous websoket closing handshake).
till yesterday night same codes were working properly.
  • sujith
    Can you paste the complete stacktrace here?
  • rakeshr
    @vaishali
    No, issue here. Seems like the main thread getting block.
    You can go through python Websocket Streaming FAQs here.
  • vaishali
    @sujith: below is the code for getting Open High Low & LTP

    from kiteconnect import KiteConnect
    from kiteconnect import KiteTicker

    kws = ""
    kite = ""
    api_k = "xxxxxxxxxxx" # api_key
    api_s = "xxxxxxxxxxxx" # api_secret
    access_token = "xxxxxxxxxxxx"

    def get_login(api_k, api_s): # log in to zerodha API panel
    global kws, kite
    kite = KiteConnect(api_key=api_k)

    #print("[*] Generate access Token : ", kite.login_url())
    #request_tkn = input("[*] Enter Your Request Token Here : ")
    #data = kite.generate_session(request_tkn, api_secret=api_s)
    #kite.set_access_token(data["access_token"])
    #kws = KiteTicker(api_k, data["access_token"])
    #print(data['access_token'])

    kite.set_access_token(access_token)
    kws = KiteTicker(api_k, access_token)


    get_login(api_k, api_s)

    trd_portfolio = {5633: {'name' : 'ACC'}, 11350786: {'name' : 'ACC20AUGFUT'}, 6401: {'name' : 'ADANIENT'}, 11351042: {'name' : 'ADANIENT20AUGFUT'}, 3861249: {'name' : 'ADANIPORTS'}}

    def on_ticks(ws, ticks):
    for single_comapny in ticks:
    inst_of_single_company = single_comapny['instrument_token']
    name = trd_portfolio[inst_of_single_company]['name']

    open = single_comapny['ohlc']['open']
    high = single_comapny['ohlc']['high']
    low = single_comapny['ohlc']['low']
    ltp = single_comapny['last_price']

    trd_portfolio[inst_of_single_company]['open'] = open
    trd_portfolio[inst_of_single_company]['high'] = high
    trd_portfolio[inst_of_single_company]['low'] = low

    print(single_comapny, name)
    print("\n")
    print(trd_portfolio[inst_of_single_company])

    inst_token = [5633, 11350786, 6401, 11351042, 3861249]

    def on_connect(ws, response):
    ws.subscribe(inst_token)
    ws.set_mode(ws.MODE_QUOTE, inst_token)

    kws.on_ticks = on_ticks
    kws.on_connect = on_connect
    kws.connect()

Sign In or Register to comment.