-
How to fetch historical data using kite connect
Algo Trading is a method of trading in the stock market where computer programs automatically place buy and sell orders based on pre-defined rules. These rules are created using mathematical models, technical indicators, or market conditions. Explanation Learn how to use the Zerodha Kite Connect API in Python to fetch historical stock data. This step-by-step guide explains each line of code Importing Required Libraries Change Working Directory Generate Trading Session Fetch All NSE Instruments Helper Function: Fetch Instrument Token Fetch Historical OHLC Data 1.instrument = fetchInstrument(instrument_df, ticker)→ Finds the instrument token for the stock. 2. kite.historical_data(...) 3. Converts the returned JSON data into a Pandas DataFrame. 4. data.set_index("date", inplace=True)→ Sets the…
-
Automating Zerodha Login with Python, Selenium, and TOTP.
This Python script automates the login process to Zerodha’s Kite Connect API using Selenium and TOTP-based two-factor authentication. It begins by setting the working directory and reading API credentials from a file, then initializes the Kite Connect session and opens the Zerodha login page in a Chrome browser. Using Selenium, it inputs the user ID and password, generates a time-based OTP using a secret key, and submits the login form. After successfully logging in and being redirected, the script extracts the request token from the URL, uses it along with the API secret to generate an access token, and saves this token to a file for future API interactions. Explanation…