Unable to save data into csv

Sashank_Chittipeddi
Hello,

Could you help me out here? Why isn't the following code saving a csv file with tick data

from kiteconnect import KiteTicker
import datetime
import time
import logging
logging.basicConfig(level=logging.DEBUG)
import csv
kws = KiteTicker("", "")

# Callback for tick reception.
def on_ticks(ticks, ws):
logging.debug("Ticks: {}".format(ticks))
outputFile = open('crude03052018.csv', 'a', newline='')
outputWriter = csv.writer(outputFile)
#outputWriter.writerow(['Date','ID','LTP','VOLUME'])



for i in ticks:
T1 = datetime.datetime.now()
outputWriter.writerow([T1,i['instrument_token'],i['last_price'],i['volume']])


def on_connect(ws, response):
ws.subscribe([209029])
ws.set_mode(ws.MODE_LTP, [209029])

# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect

#kws.on_tick = _parse_binary
# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect(threaded=True)

count = 0
while True:
count += 1
#print("This is main thread. Will change webosocket mode every 5 seconds.")
if False:
if kws.is_connected():
#print("Set mode to LTP")
r=kws.set_mode(kws.MODE_LTP, [209029])

#kws.set_mode(kws.MODE_QUOTE, [209029])

else:
if kws.is_connected():
print("Set mode to quote")
kws.set_mode(kws.MODE_QUOTE, [209029])

time.sleep(1)

Sign In or Register to comment.