# Infinite loop on the main thread. Nothing after this will run. # You have to use the pre-defined callbacks to manage subscriptions. # kws.connect(disable_ssl_verification=True) kws.connect() +++++++++++++++++++++++++++++++++++++++++++++++++
Approch 2 -
from kiteconnect import KiteConnect from kiteconnect import KiteTicker import pandas as pd import os
#get dump of all NSE instruments instrument_dump = kite.instruments("NSE") instrument_df = pd.DataFrame(instrument_dump)
def tokenLookup(instrument_df,symbol_list): """Looks up instrument token for a given script from instrument dump""" token_list = [] for symbol in symbol_list: token_list.append(int(instrument_df[instrument_df.tradingsymbol==symbol].instrument_token.values[0])) return token_list
def on_ticks(ws,ticks): # Callback to receive ticks. #logging.debug("Ticks: {}".format(ticks)) print(ticks)
def on_connect(ws,response): # Callback on successful connect. # Subscribe to a list of instrument_tokens (RELIANCE and ACC here). #logging.debug("on connect: {}".format(response)) ws.subscribe(tokens) #ws.set_mode(ws.MODE_FULL,tokens) # Set all token tick in `full` mode. ws.set_mode(ws.MODE_FULL,[tokens[0]]) # Set one token tick in `full` mode.
File "D:\Investments\AlgoTrading\sample.py", line 79, in kws.connect()
File "C:\Users\91701\anaconda3\lib\site-packages\kiteconnect\ticker.py", line 532, in connect reactor.run(**opts)
File "C:\Users\91701\anaconda3\lib\site-packages\twisted\internet\base.py", line 1282, in run self.startRunning(installSignalHandlers=installSignalHandlers)
File "C:\Users\91701\anaconda3\lib\site-packages\twisted\internet\base.py", line 1262, in startRunning ReactorBase.startRunning(self)
File "C:\Users\91701\anaconda3\lib\site-packages\twisted\internet\base.py", line 765, in startRunning raise error.ReactorNotRestartable()
@sujith thanks for the reply. from the link I got some code info now I used this code below - +++++++++++++++++++ from kiteconnect import KiteTicker import os
I found the solution is related to the setup. for setting up the TCP connection in jupyter or spider. we need to restart our kernel then it will work fine.
I used this code below -
+++++++++++++++++++
from kiteconnect import KiteTicker
import os
cwd = os.chdir("D:\Investments\AlgoTrading")
access_token = open("access_token.txt",'r').read()
key_secret = open("api_key.txt",'r').read().split()
api_key = key_secret[0]
access_token = access_token
kws = KiteTicker(api_key,access_token)
def on_ticks(ws,ticks):
print(ticks)
print("\n")
# token i am using here is of TCS
def on_connect(ws,response):
ws.subscribe([2953217])
ws.set_mode(ws.MODE_QUOTE,[2953217])
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect()
++++++++++++++++++++++++++++++++
I am getting the still the same error.
I am also sure that my acces_token and api_key is correct
and can anyone tell me what could be the way to react to the Zerodha tech support?
Refer to FAQs on anaconda setup here.