Unable to run live tick feeds on websocket

D11458
@sujith , @rakeshr Hi Team,

I just renewed my API subscription after a couple of months, the live feeds code I used to run isnt working, anything changed? Though I can run kite.holding() and kite.postions() successfully.

Thanks,
Kalpesh
  • rakeshr
    I just renewed my API subscription after a couple of months, the live feeds code I used to run isn't working
    No, there isn't any change in the code. You can check the WebSocket sample code here.
    Can you paste the error/exception message here?
  • D11458
    thanks - its working with this one...
  • anmolsinghalpkl
    Yes. I have been facing the same issue. My code is structured in the same manner as in link posted. It runs for 2-3 ticks and then stops unless is re-establish the connection.
  • rakeshr
    It runs for 2-3 ticks and then stops unless is re-establish the connection.
    You need to paste the complete exception message. The exception message will have the disconnection reason.
  • anmolsinghalpkl
    The connection doesn't disconnect. It just doesn't give any ticks to process further.
  • rakeshr
    Ticks will come only when there is any change in the subscribed mode fields.
    Can you let us know the subscribed token list?
  • anmolsinghalpkl
    Its NIFTY BANk and NIFTY 50
  • anmolsinghalpkl
    anmolsinghalpkl edited July 2021
    <code class="CodeInline">

    def on_ticks(ws, ticks):
    print("new")

    tickQ.put(ticks)

    def on_connect(ws, response):
    ws.subscribe(tokens)
    ws.set_mode(ws.MODE_LTP,tokens)


    def on_close(ws, code, reason):
    #add check for exiting all positions
    time = dt.datetime.now()
    if time.time().hour >= 15 and time.time().hour >= 20:
    open_pos = kite.positions[kite.positions.quantity >0]
    if(len(open_pos) >0):
    ws.stop()
    sys.exit()

    tickQ = queue.Queue()
    while(True):
    try:
    kite = KiteAPI(mode=1)
    break
    except Exception as e:
    print('couldnt connect order due to'+e)


    tokens = [ int(kite.symbolLookup("NIFTY BANK","NSE").instrument_token.values[0]), int(kite.symbolLookup("NIFTY 50","NSE").instrument_token.values[0]) ]
    kite.kws.on_ticks = on_ticks
    kite.kws.on_connect = on_connect
    kite.kws.on_close = on_close
    kite.kws.connect(threaded= True)

    def main():
    global kite
    if( kite.getWorkingDay(dt.date.today(),0) is None):
    sys.exit()
    strat = shortStraddle(kite,dt.date.today())


    while True:
    if tickQ.empty():
    continue
    else:
    ticks = tickQ.get()
    #convertTick(ticks)



Sign In or Register to comment.