Zerodha Algo Trading Python, How to connect to kiteconnect?
Here I am going to show you how to integrate python program to zerodha kite connect. Let us see each step in detail.
STEP 1: KITE CONNECT SIGN UP
- Goto https://kite.trade/
- Click Sign up
- Enter the information and submit
STEP 2: APP CREATION
- Login into https://kite.trade/
- Click create new APP
- Enter any name in App name field
- Insert your Zerodha client id in “Client ID” Field
- Enter any url in Redirect URL Field. eg:-https://kite.zerodha.com/
- Click create to create the app.
Activate the APP by paying 2000 rs.
Page that looks like below one is displayed
Three things that we need to integrate our code to Zerodha
- API Key ( Found at the app page above)
- API secret ( Found at the app page above)
- Request Token ( We need to generate this separately)
Before generating request token we need to add TOTP in Zerodha
HOW TO ADD TOTP IN ZERODHA
- Go to play store download Authy App.
- Open the App add complete the mobile verification
- Go to Zerodha profile
- Click Password and Security
Next, click on Enable 2-step OTP
- Click Add Account in your APP
- Scan this QR Code and click Add Account.
So you have completed setting of totp in zerodha.
Please click here for more information about setting TOTP.
STEP 3: GENERATE REQUEST TOKEN
https://kite.zerodha.com/connect/login?api_key=dshjfsgdfgfd7852
In the above link replace yellow test by your API Key found at the app.
Copy the link into browser you will be redirected to an URL with request token.
Copy the request token from the above redirected URL.
Next we will see how to code in Java to connect to Zerodha.
STEP 4: CODING
Window users. You need to install few things before continuing our coding
Go to Command Prompt and type the following command to install kiteconnect API.
python -m pip install --upgrade kiteconnect
Next , update the setup tools.
python -m pip install -U pip setuptools
PROGRAM TO CONNECT TO ZERODHA
import logging
from kiteconnect import KiteConnect
logging.basicConfig(level=logging.DEBUG)
kite = KiteConnect(api_key="your_api_key")
data = kite.generate_session("request_token_here", api_secret="your_secret")
kite.set_access_token(data["access_token"])
Let’s Print the Profile Information:
Please insert the code below to print the profile information
kite.profile()
The above code display all the profile information. If you would like to get only the name, Please use the following code
profile=kite.profile()
print(profile["user_name"])
So we have learned how to integrate Python with Zerodha. If you have any queries please let me know in comments .
Thank you.
Mukesh Mohanan.
Comments
Post a Comment