Guide to secure your SmartAPI Account with two factor authentication
-
-
Nse circular does not say that you have to use TOTP. This process will make things complicated and orders may fail. Because before placing the orders, the bot/server will have to check if the TOTP is valid or not and then wait/refresh for the latest TOTP. And with 30 second hash
-
Simple solution is to have a one time otp for logging everyday.
-
-
@admin Should User Add OTP every day? if yes then I think it is the End of Trading using APIs because no one wants to do the Same Process Again and Again.
I think SEBI Circular is not Telling the OTP required for API Trading. it is only required to Login Account on a Web or Mobile App or Broker.
-
@admin One Solution is to Provide the TOTP Via API by Sending the Username & Password of User.
-
@gautamnaik1994 I Agree, need something to Automate the Process.
-
How to enable TOTP
-
-
@gautamnaik1994 If you are using python, you can use totp module to generate totp automatically
-
Using smart api-Angel Broker plugin, include following js file
<script src="https://smartapi.angelbroking.com/common/v1.js"></script>
then passing api key; <smartapi-login href="#" data-smartapi="<api-key>">Login</smartapi-login>
How to solve with this integration?
-
@admin not open link
-
@labeebta what should be the Secret Key to Generate TOTP?
-
@admin It already 13:00 and the link still does not work. How can I access the API ?
-
The link http://smartapi.angelbroking.com/enable-totp is not working @admin @administrators . Please help. already last 2 days your APIs never worked with all changes you did without proper testing.
Resolve this please.
-
-
@admin The site is working but OTP is not working or sent to the email.
-
Hi folks
If anyone looking for automating totp part , you can use the following python sample for the same. The secret here comes after validating on enable-totp url .
from smartapi import SmartConnect # or from smartapi.smartConnect import SmartConnect
import pyotpimport smartapi.smartExceptions(for smartExceptions)
create object of call
obj = SmartConnect(api_key="your api key here ")
login api call
totp = pyotp.TOTP(s='secret key in qr uri after qr generation')
attempts = 5
while attempts > 0:
attempts = attempts-1
data = obj.generateSession("Your client id ", "your password ", totp.now())
if not data['message'].contains('Invalid totp'):
break
time.sleep(2) ###rate limiting might block if we try immediatelyrefreshToken = data['data']['refreshToken']
-
@gautamnaik1994 I have provided a sample code below. You can give it a shot. Worked for me .
-
-
@anil_patel I generated it here - http://smartapi.angelbroking.com/enable-totp . It is printed below QR code
-
-
@ivar
You are not required to pass the TOTP with every order. It needs to be passed only with LoginbyPassword API call to generate the session and fetch the jwtToken, refreshToken and feedToken. These tokens are valid till 5 am of the subsequent day.