I started out with the KiteTicker client today(Python SDK) and copied the code shown in sample in your docs. In order to do fault tolerance checks to ensure our backend ETLs can handle the flow, I closed the PyCharm console (which was running the program) manually and then tried to relaunch. However, now I get this error (we are using Python 3.9.2) ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
We have a valid token (we use it already with a historical data API) so that is not an issue The code is below
import logging from kiteconnect import KiteTicker
logging.basicConfig(level=logging.DEBUG) token = 'our_token' api_key = 'the key we got from our app'
# Initialise kws = KiteTicker(api_key, token)
def on_ticks(ws, ticks):
# Callback to receive ticks. file = 'E:\Projects\Technotradez\codebase\\assets\tick_data.txt' with open(file, 'r') as file: file.write("Ticks: {}\/n".format(ticks)) #logging.debug("Ticks: {}".format(ticks))
def on_connect(ws, response): # Callback on successful connect. # Subscribe to a list of instrument_tokens (RELIANCE and ACC here). ws.subscribe([738561, 5633])
# Set RELIANCE to tick in `full` mode. ws.set_mode(ws.MODE_FULL, [738561])
def on_close(ws, code, reason): # On connection close stop the main loop # Reconnection will not happen after executing `ws.stop()` ws.stop()