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.
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.
Can you paste the error/exception message here?
Can you let us know the subscribed token list?
<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)