Overview
| Script | Output File | Records | Purpose |
|---|---|---|---|
fetch_fno_data.py | fno_stocks_response.json | ~207 stocks | F&O-enabled stocks with live metrics |
fetch_fno_lot_sizes.py | fno_lot_sizes_cleaned.json | ~207 instruments | Contract lot sizes per expiry month |
fetch_fno_expiry.py | fno_expiry_calendar.json | ~2,000+ entries | Expiry dates for all derivatives |
fetch_fno_data.py
What It Does
Fetches the complete list of F&O-eligible stocks from NSE with real-time market data, fundamental ratios, and technical indicators.API Endpoint
FnoFlag = 1: Only stocks where derivatives trading is enabledOgInst = ES: Equity Segment instruments
Output Format
File:fno_stocks_response.json (Array of ~207 stocks)
Fields Captured
Identity & Pricing (6 fields)
Identity & Pricing (6 fields)
Isin,DispSym,SymLtp(Last Traded Price)Open,BcClose(Previous Close)
Fundamentals (10 fields)
Fundamentals (10 fields)
Mcap,Pe,Pb,DivYeildRevenue,Year1RevenueGrowthNetProfitMargin,EBIDTAMarginROCE,Roe
Technical Indicators (8 fields)
Technical Indicators (8 fields)
DaySMA50CurrentCandle,DaySMA200CurrentCandleDayRSI14CurrentCandleHigh1Yr,High3Yr,High5yr,High1WkRtAwayFrom5YearHigh,RtAwayFrom1MonthHigh
Performance Metrics (9 fields)
Performance Metrics (9 fields)
PricePerchng1week,PricePerchng2week,PricePerchng1monPricePerchng3mon,PricePerchng1year,PricePerchng3year,PricePerchng5yearVolumeYear1CAGREPSGrowth,YearlyEarningPerShare
Usage
Use Cases
Derivatives Screener
Identify high-liquidity F&O stocks for options strategies
Volatility Analysis
Track RSI, SMA crossovers in derivative-eligible universe
F&O Watchlists
Build custom scanners for stocks with active derivative contracts
Risk Management
Monitor margin requirements for F&O portfolio positions
fetch_fno_lot_sizes.py
What It Does
Extracts lot sizes for all F&O contracts by parsing Dhan’s Next.js data API. Each instrument has different lot sizes per expiry month.API Endpoint
Output Format
File:fno_lot_sizes_cleaned.json
Lot Size Calculation
Lot sizes are set by NSE to maintain contract value around ₹5-7 lakhs:Lot sizes are adjusted quarterly by NSE. Always fetch fresh data before trading.
Usage
Use Cases
- Position Sizing: Calculate exact capital required for options strategies
- Margin Computation: Estimate SPAN + Exposure margins for F&O trades
- Risk Budgeting: Determine maximum loss per lot for defined-risk strategies
fetch_fno_expiry.py
What It Does
Fetches the complete F&O expiry calendar covering Stock Futures, Index Futures, Options, and Currency Derivatives.API Endpoint
Output Format
File:fno_expiry_calendar.json (~2,000+ entries)
Instrument Types
| Code | Instrument | Expiry Pattern |
|---|---|---|
OPTIDX | Index Options (NIFTY, BANKNIFTY) | Weekly (Thursday) |
FUTIDX | Index Futures | Monthly (Last Thursday) |
OPTSTK | Stock Options | Monthly (Last Thursday) |
FUTSTK | Stock Futures | Monthly (Last Thursday) |
Expiry Rules
Weekly Expiries (Index Options)
NIFTY & BANKNIFTY expire every Thursday. If Thursday is a holiday, expiry moves to the preceding trading day.
Monthly Expiries (All Others)
Stock Futures/Options and Index Futures expire on the last Thursday of the month.
Usage
Use Cases
Calendar Spreads
Identify expiry gaps for multi-leg strategies
Rollover Planning
Schedule position rollovers before contract expiry
Theta Decay
Track days to expiry for options time decay calculations
Settlement Alerts
Avoid physical settlement by closing positions before expiry
Comparison with Pipeline Integration
While these scripts are standalone, the pipeline includes F&O enrichment viaenrich_fno_data.py:
| Standalone Scripts | Pipeline Integration (enrich_fno_data.py) |
|---|---|
| Fetches all F&O instruments | Enriches only F&O-flagged stocks in master JSON |
| Outputs separate JSON files | Adds F&O Flag, Lot Size, Next Expiry fields |
| Run manually on-demand | Auto-runs in Phase 4 of pipeline |
| Use for reference/analysis | Use for live stock screener |
Error Handling
All three scripts include fallback mechanisms:Next Steps
Indices & ETF Scripts
Fetch market indices and ETF data
OHLCV History
Download lifetime price history
Pipeline Flags
Configure FETCH_OHLCV and FETCH_OPTIONAL
Cleanup Options
Manage intermediate file cleanup