Today we will discuss, how to connect Zerodha kite connect API with Python. For that, you need few things, which I mentioned below.
Don’t forget to create Kite connect API account with the same Zerodha account.
Creating a Zerodha account is a big process, I think you all know that required docs. Here I will show how to create Kite connect account.
Click this link, it will redirect to the API interface. Click the signup button and fill in the required details.
Click the Create new app tap to create an app, you need to pay Rs.2000 to access the Kite API data. It will allow us to manage orders and access real-time data. you can also create Free App but there is no use for it.
While creating the APP account, you need to mention a redirect URL, it will help to get the request token. In this case, I used this https://devpyjp.com/.
Once you create the APP, you will get an API KEY and API SECRET.
Here we will use API KEY and API SECRET to getting REQUEST TOKEN and ACCESS TOKEN. We use REQUEST TOKEN to generate ACCESS TOKEN.
Once we got the access token then only we will manage to place the orders. Every day you must generate a request token and access token.
Request token will change every time and it will expire in a few minutes, but access token will change once a day.
Here I am placing the code to get the request token and access token.
Connecting Kite API with Python
from kiteconnect import KiteConnect api_key="xd06lwur0qe8" # your api_key secret_key="ipghg8f4v2rm1mv93xkxz" # your secret_key kite = KiteConnect(api_key,secret_key) kite.login_url()
If you run this script, it will generate a redirect URL, like below.
You need to copy the URL and paste it into the browser, it will redirect to your redirect URL and generate a request token.
request_token = '2cwSaJ52S5eWPawyipzSb3Re1hjgDeqE' data = kite.generate_session(request_token, api_secret=secret_key) print(data['access_token']) kite.set_access_token(data["access_token"]) kite.orders()
if you executed the above lines then you will get an access token that helps to manage the orders and account.
kite. orders() – It will give all the details of your orders like buy, sell prices if you executed the orders on that day. if didn’t execute any orders it will show you an empty list.
You can also check the official docs of Kite Connect API with Python.
Kite Connect API Official DOC: https://kite.trade/docs/pykiteconnect/v3/