Market Data & Web Scraping
Intermediate
Angel One SmartAPI TOTP Auto-Login & Intraday Option Order Placement in Python
Authenticate with Angel One SmartAPI using pyotp in Python, fetch live LTP, and place intraday MIS/CARRYFORWARD market and stop-loss orders.
#smartapi-python#pyotp#logzero
Problem Statement
Retail algo traders prefer zero-subscription broker APIs like Angel One SmartAPI, but struggle with the v2 TOTP authentication payload and symbol token formatting for Nifty options.
Formula / Core Logic
Authenticates via SmartConnect.generateSession(client_id, pin, totp) and submits order params to placeOrder().
Installation
pip install smartapi-python pyotp logzero
angel-one-smartapi-totp-login-order-placement-python.py
import pyotp
from SmartApi import SmartConnect
def smartapi_login_and_order(api_key, client_id, password_pin, totp_secret, tradingsymbol='NIFTY05NOV2624500CE', symboltoken='43210', qty=75, side='BUY'):
obj = SmartConnect(api_key=api_key)
totp = pyotp.TOTP(totp_secret).now()
session = obj.generateSession(client_id, password_pin, totp)
if not session.get('status'):
raise ConnectionError(f"Login Failed: {session}")
order_params = {
'variety': 'NORMAL',
'tradingsymbol': tradingsymbol,
'symboltoken': symboltoken,
'transactiontype': side,
'exchange': 'NFO',
'ordertype': 'MARKET',
'producttype': 'INTRADAY',
'duration': 'DAY',
'price': '0',
'squareoff': '0',
'stoploss': '0',
'quantity': str(qty)
}
order_id = obj.placeOrder(order_params)
return {'Order_ID': order_id, 'JWT_Token_Active': True}
Get the Complete 100+ Python Quant & Automation Bundle
Instant lifetime access to all production-ready scripts, valuation models, and trading bots ($19).
Buy Full Bundle on Gumroad ($19) →Frequently Asked Questions
Q: How do I find the `symboltoken` for weekly Nifty options on Angel One?
Download the daily `OpenAPIScripMaster.json` file from Angel One's public URL and filter by `name == 'NIFTY'`, `expiry`, and strike.