fyers-api integration with python

Anoob Paul
3 min readJan 23, 2024

--

Fyers API is a set of rest apis which help us to integrate with our code to build our own trading system. Here in this blog we are integrating the fyers v3 api to our code in python. The documentation and sample codes are available in the fyers documentation page. https://myapi.fyers.in/docsv3

As a prerequisite, we need an active fyers trading account to use the API. we will be able to proceed if we dont have a fyers account.

Once logged into Fyers account, select the Fyers API from the set of products and go to the dashboard

Step1 : Create an app in the dashboard

As mentioned in the above image, click on the create app. we need to enter the app name , redirect url details and give app permissions in the below screen.
Example — App Name : MyAlgoApp, Redirect url : www.google.com (or any url )

On click of create app, the app will be created , the appId, secret id are important and these two values will be used in our python code

lets install the python package pip install fyers-apiv3

now we need to set up the authorization part. The request and response details are available in the Fyers APi documentation. Sample code given below. the client id should be app id and secret key should be the same values in our app we recently created.

this code will print the redirect_uri like below and on click , we will get the authcode embeded in the url.

Also at the same time, the app will request for permission and we have to give the required permissions and accept the terms and conditions.

copy the auth_code value from the url and set the auth_code to the session which has function to generate token. exmaple below

this will make the app as active. and the authentication is successful

We can test our connectivity using below function which will print the profile details of the user. similary we can print the fund details as well .

Hope this will help us to login to fyers using python. Please feel free to let me know if any queries.

--

--

Anoob Paul
Anoob Paul

Written by Anoob Paul

scribbles from my learning. interested in java, python and financial markets