Bank Nifty Algo Trading: Zerodha API, Python Setup & SEBI Legal Framework
Manual Bank Nifty trading has two enemies: speed (you cannot react in milliseconds) and emotion (you override your own rules). Algorithmic trading eliminates both. This guide shows you how to set up a Bank Nifty options algo using Zerodha's Kite Connect API and Python — from zero to running your first automated trade.
SEBI Legal Framework for Algo Trading
SEBI's circular dated 16 March 2023 established rules for algo trading by retail investors:
- API-based orders are permitted: Retail traders can use broker APIs to place automated orders. This is explicitly legal.
- No exchange approval needed: Unlike institutional algos, retail API-based trading does not require NSE/BSE approval.
- Broker must provide API: Brokers like Zerodha (Kite Connect), Fyers (Fyers API), and Angel One (Smart API) offer official APIs.
- Rate limits apply: Zerodha allows 3 orders per second per user. Exceeding this triggers a temporary block.
- No co-location: Retail algo traders cannot use exchange co-location servers. Your latency will be 50-200ms — fine for strategies that are not latency-sensitive.
Zerodha Kite Connect API Setup
- Subscribe to Kite Connect: Go to developers.kite.trade → Sign up → ₹2,000/month subscription. This gives you API access.
- Create an app: In the Kite Connect dashboard, create a new app. Note your api_key and api_secret.
- Generate access token: The login flow requires manual authentication once per day (Kite uses TOTP for security). After login, you receive an access_token valid for the entire trading session.
- Install Python library: pip install kiteconnect
Python Environment
Required libraries: kiteconnect (Zerodha API), pandas (data manipulation), numpy (calculations), schedule (time-based triggers), logging (trade logging). Optional: scipy (Black-Scholes calculations), telegram-send (notifications).
The basic flow: authenticate → fetch Bank Nifty spot and option chain → apply strategy logic → place order → manage position → log everything.
Automating a Short Straddle Strategy
Example: automated short straddle with adjustment rules.
- At 9:20 AM: Fetch Bank Nifty spot. Find ATM strike (nearest 100). Sell ATM CE + ATM PE. Log entry premiums.
- Every 5 minutes: Check combined premium. If combined P&L exceeds -30% of collected premium, trigger SL exit.
- If one leg doubles: Close both legs, re-sell straddle at new ATM. Maximum 2 adjustments.
- At 3:15 PM: Close all positions regardless of P&L. No overnight hold.
- Log: Entry prices, exit prices, adjustments, P&L, VIX at entry, PCR at entry. Save to CSV for backtesting.
Critical Risk Controls
- Daily loss limit: If total day P&L exceeds -₹10,000 (for ₹5L capital), stop all trading for the day. Hard-coded, not overridable.
- Position limit: Maximum 2 lots per strategy. Hard-coded.
- Kill switch: A manual kill switch (Telegram command or keyboard shortcut) that instantly closes all positions and stops the algo.
- Network monitoring: If the API connection drops for more than 30 seconds, close all positions via a backup manual order.
- No overnight positions: The algo must close all positions before 3:25 PM. Hard-coded deadline.
- Paper test first: Run the algo on Sensibull virtual trading for minimum 2 weeks before deploying real capital.
Alternative Platforms
| Platform | Cost | Language | Bank Nifty Support |
|---|---|---|---|
| Kite Connect (Zerodha) | ₹2,000/mo | Python, Java, JS | Full F&O |
| Smart API (Angel One) | Free | Python, Java | Full F&O |
| Fyers API | Free | Python | Full F&O |
| Streak (no-code) | ₹500/mo | Visual builder | Limited |
| Jugaad Trader | Free | Python | Full F&O |
Best free option: Angel One Smart API — no monthly charge, full F&O access, Python support. The trade-off is slightly slower execution compared to Zerodha.
Frequently Asked Questions
Is algo trading legal for Bank Nifty in India?
Yes. SEBI permits retail traders to use broker APIs for automated trading. No exchange approval is needed for API-based orders. Brokers like Zerodha, Angel One, and Fyers provide official APIs. Rate limits apply (3 orders/second on Zerodha). Co-location access is not available for retail.
How much does Zerodha API cost?
Kite Connect subscription costs Rs 2,000 per month. This provides API access for automated trading. Standard brokerage of Rs 20 per order still applies on each trade. Historical data APIs have additional charges. Angel One and Fyers offer free API access.
Can I algo trade Bank Nifty options without coding?
Yes. Streak (by Zerodha) provides a visual strategy builder for no-code algo trading. You create conditions using dropdown menus, and Streak executes them automatically. However, Streak has limited options strategy support compared to custom Python code.
What is the minimum capital for Bank Nifty algo trading?
For option buying algos: Rs 50,000 is sufficient. For option selling algos: Rs 3,00,000 minimum (margin for 2 lots + buffer). Add Rs 2,000/month for Zerodha API subscription. Total first-month cost: Rs 3,02,000 minimum for selling-based algos.
Start Trading Bank Nifty Today
Open a trading account and put these strategies into practice. Get $30 free credit to start.
Claim $30 Free Credit → 18+ | Trading involves risk. Capital at risk.Options trading carries a high level of risk and is not suitable for all investors. Bank Nifty options are highly volatile instruments. Past performance is not indicative of future results. Content on BankNiftyOptions.com is for educational purposes only. Consult a SEBI-registered advisor before trading. Only trade with capital you can afford to lose. 18+ only.