Angel One SmartAPI allows developers and algo traders to access live market data, place orders, and automate strategies with ease. In this guide, you’ll learn how to integrate SmartAPI using Python, generate your API keys, authenticate securely, and fetch real-time Nifty 50 LTP (Last Traded Price).
This tutorial is perfect for beginners starting algo trading and for developers who want to build automated systems, scalping bots, dashboards, or custom trading tools.

📌 Step-by-Step Code: Angel One SmartAPI Integration + Nifty 50 LTP

Below is a clean, structured, copy-ready code block for your blog.

1. Install Angel One SmartAPI Python Package
pip install smartapi-python

#2. Import Libraries and Enter Your Credentials
from smartapi import SmartConnect

# Replace these with your login details
API_KEY = "YOUR_API_KEY"
CLIENT_ID = "YOUR_CLIENT_ID"        # Angel One Client ID (e.g. ABC123)
PASSWORD = "YOUR_PASSWORD"          # Angel One Login PIN (4 Digit)
TOTP_SECRET = "YOUR_TOTP_SECRET"    # Secret key to generate TOTP

3. Generate TOTP for Login
from smartapi.smartExceptions import SmartAPIException
import pyotp

totp = pyotp.TOTP(TOTP_SECRET).now()

# 4. Authenticate with Angel One SmartAPI
# Create connection object
smart_api = SmartConnect(api_key=API_KEY)

try:
    session_data = smart_api.generateSession(CLIENT_ID, PASSWORD, totp)
    print("Login Successful!")
except SmartAPIException as e:
    print("Login Failed:", e)

# 5. Get Nifty 50 Token ID

NIFTY 50 Index token for NSE:

NIFTY 50 Token: 26000

# 6. Fetch Live LTP of NIFTY 50
# Fetch LTP
ltp_data = smart_api.ltpData(
    exchange="NSE",
    tradingsymbol="NIFTY",
    symboltoken="26000"
)

print("Nifty 50 LTP:", ltp_data['data']['ltp'])

# 7. Wrap Everything Into a Reusable Function

def get_nifty_ltp():
    totp = pyotp.TOTP(TOTP_SECRET).now()
    smart_api = SmartConnect(API_KEY)

    smart_api.generateSession(CLIENT_ID, PASSWORD, totp)

    data = smart_api.ltpData("NSE", "NIFTY", "26000")
    return data["data"]["ltp"]

print("Live NIFTY 50 Price:", get_nifty_ltp())

# Remove Below Instruction will running the code

🎯 What Readers Will Learn

Your blog post will teach users:

• How to set up Angel One SmartAPI
• How to generate and use API keys
• How to log in using TOTP
• How to fetch Nifty 50 live LTP
• How to build a base structure for algo trading bots