/fyers-api-access-token-v3

Automatically generate an access token for Fyers API V3.

Primary LanguagePython

Fyers APIs official documentation: https://myapi.fyers.in/docs/
You can create Fyers API APPs at https://myapi.fyers.in/dashboard/

If not already, enable login via External 2FA TOTP at https://myaccount.fyers.in/ManageAccount. While enabling External 2FA TOTP, copy the TOTP KEY and scan the QR code using Google or Microsoft Authenticator, as shown below.
If you don't want to use Authenticator app, you can generate TOTP using the code in the repo https://github.com/tkanhe/totp-generator with TOTP KEY.

alt text

Note:

If you have just created the app and using it first time, then go to the URL (generated by running the following code) manually in the browser and give permissions to access the app. It is a one-time process. After that, you can use the script.

from fyers_apiv3 import fyersModel

client_id = "******"  # App ID of the created app (ex., "L9NY305RTW-100")
secret_key = "******"  # Secret ID of the created app
redirect_uri = "******"  # Redircet URL you entered while creating the app (ex., "https://trade.fyers.in/api-login/redirect-uri/index.html")

session = fyersModel.SessionModel(client_id=client_id, secret_key=secret_key, redirect_uri=redirect_uri, response_type="code", state="sample_state")

url = session.generate_authcode()
print(url)

Input parameters:

totp_key = "******"  # totp_key (ex., "OMKRABCDCDVDFGECLWXK6OVB7T4DTKU5")
username = "******"  # Fyers Client ID (ex., "TK01248")
pin = 1246  # four-digit PIN
client_id = "******"  # App ID of the created app (ex., "L9NY305RTW-100")
secret_key = "******"  # Secret ID of the created app
redirect_uri = "******"  # Redircet URL you entered while creating the app

Requirements:

  • Python 3.6+
  • Requests pip install requests
  • Fyers API V3 pip install fyers-apiv3