It looks like you're new here. If you want to get involved, click one of these buttons!
tokens = [256265]
from kiteconnect import KiteTicker
# Initialise.
kws = KiteTicker(my_api_key, access_token)
# Callback for tick reception.
def on_ticks(ws,ticks):
global lastupdatetime
df = pd.DataFrame(ticks)
time = X.strftime("%Y-%m-%d %H:%M:%S")
df.insert(0,'Time',time)
df = df.to_csv(header=None,index=False)
logging.debug(df)
lastupdatetime = time
# Callback for successful connection.
def on_connect(ws,response):
print("connected")
ws.subscribe(tokens)
ws.set_mode(ws.MODE_LTP, tokens)
# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect(threaded=True)
# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
#
try:
while (True):
time.sleep(5)
CurrentTime = datetime.datetime.now()
LastTime = datetime.datetime.strptime(lastupdatetime,"%Y-%m-%d %H:%M:%S")
X = CurrentTime > LastTime + datetime.timedelta(seconds =60)
if (X):
kws.close()
kws = KiteTicker(my_api_key, access_token)
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect(threaded=True)
except KeyboardInterrupt:
print 'interrupted!'
Firstly, remove infinite while loop. Once ticker is closed and ws.stop gets called, you won't be able to restart the ticker in the same process.