Error in data streaming through KiteTicker

Mohit
Hi,

I am upgrading my systems to kite V3. I am facing following problems while saving tick data in a logger:

1. Error messages are getting saved simultaneously with data in the logger. Please suggest any solution for parsing it so only market data is saved.
2. After closing the connection by kws.close() and connecting again after some time (if there is no ticks received) by kws.connect(), I receive the error as Reactor is already running. Using kws.stop() also doesn't help as I cant't reconnect again after that.

The above errors were not received while using earlier version with Web socket.

MY objective is:

1. To record the live tick data in a log file for specified number of instruments without any error
2. There should not be any data gap because of re-connection /connection issue
3. Automate the whole process so as there is no manual intervention in data recording

Attached is my code.

Please suggest a way to resolve this issue.

Thanks,
Mohit
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!'
Sign In or Register to comment.