I Recreated the entire app on zerodha api portal and passing just sample one instrument token but still getting same error. I replaced the api key and access token multiple times but still getting same error.
import logging from kiteconnect import KiteTicker
# Configure logging for debugging logging.basicConfig(level=logging.DEBUG)
# Replace with your actual API key and access token api_key = "xxxxxxc68wbxxxxx" access_token = "xxxxxxxxxxewCS5D60ecCQxxxxxxxxxxx"
# Callback function to receive ticks def on_ticks(ws, ticks): logging.debug(f"Ticks: {ticks}") # You can process the received tick data here
# Callback function on successful connection def on_connect(ws, response): logging.info("WebSocket connected successfully.") # Subscribe to a list of instrument_tokens (e.g., RELIANCE and ACC) # Replace with your desired instrument tokens instrument_tokens_to_subscribe = [738561, 5633] # Example tokens ws.subscribe(instrument_tokens_to_subscribe)
# Set the mode for specific instruments (e.g., RELIANCE in full mode) ws.set_mode(ws.MODE_FULL, [738561]) # Example: set RELIANCE to full mode
# Callback function on connection close def on_close(ws, code, reason): logging.info(f"Connection closed: {code} - {reason}") # Stop the main loop if you don't want automatic reconnection # If you want reconnection, do not call ws.stop() here ws.stop()
# Connect to the WebSocket # This will run an infinite loop on the main thread, # so subsequent code will only execute after the connection is closed. kws.connect()