Hey I'm trying to get live market data and only purpose of subscribing api is to get live data into python for back testing . But below is my code I created with the help of AI and I'm totally beginner to this kindly help
import sqlite3 import threading import time from kiteconnect import KiteConnect, KiteTicker from datetime import datetime import logging
# Constants API_KEY = '' ACCESS_TOKEN = '' DB_NAME = 'market_data.db' RATE_LIMIT_DELAY = 1 # Delay in seconds between API requests
# Fetch instrument tokens for Nifty 50 and Nifty Midcap 500 def fetch_instrument_tokens(): instruments = kite.instruments() nifty_50_tokens = [instrument['instrument_token'] for instrument in instruments if instrument['tradingsymbol'] in NIFTY_50_SYMBOLS] nifty_midcap_500_tokens = [instrument['instrument_token'] for instrument in instruments if instrument['tradingsymbol'] in NIFTY_MIDCAP_500_SYMBOLS] return nifty_50_tokens + nifty_midcap_500_tokens