FETCH_OPTIONAL = True in run_full_pipeline.py.
Overview
| Script | Output File | Records | Purpose |
|---|---|---|---|
fetch_all_indices.py | all_indices_list.json | ~194 indices | NSE market indices with live OHLCV + volume |
fetch_etf_data.py | etf_data_response.json | ~361 ETFs | Exchange-traded funds with fundamentals |
fetch_all_indices.py
What It Does
Fetches all NSE indices (sectoral, thematic, and benchmark) with live intraday data including today’s volume, OHLC, and 52-week high/low.API Endpoint
Inst = IDX: Instrument type is IndexExch = IDX: Exchange is Index segment (excludes equity stocks)
Output Format
File:all_indices_list.json (Array of ~194 indices)
Volume Data Behavior
Index Categories
Benchmark Indices (5)
Benchmark Indices (5)
- NIFTY 50: Top 50 large-cap stocks
- NIFTY 500: Broad market representation
- NIFTY Midcap 150: Mid-cap universe
- NIFTY Smallcap 250: Small-cap universe
- NIFTY Next 50: Stocks next in line for NIFTY 50
Sectoral Indices (11)
Sectoral Indices (11)
- NIFTY Bank: Banking sector
- NIFTY IT: Information Technology
- NIFTY Pharma: Pharmaceuticals
- NIFTY Auto: Automobile sector
- NIFTY FMCG: Fast-Moving Consumer Goods
- NIFTY Metal: Metals & Mining
- NIFTY Realty: Real Estate
- NIFTY Energy: Oil & Gas
- NIFTY Financial Services: Broad financial sector
- NIFTY PSU Bank: Public Sector Banks
- NIFTY Media: Media & Entertainment
Thematic Indices (30+)
Thematic Indices (30+)
- NIFTY Dividend Opportunities 50: High dividend yield stocks
- NIFTY Alpha 50: High alpha stocks
- NIFTY100 Quality 30: Quality factor index
- NIFTY200 Momentum 30: Momentum strategy
- NIFTY100 Low Volatility 30: Low volatility stocks
- And 25+ other thematic/strategy indices
Custom & Sectoral Sub-Indices (148+)
Custom & Sectoral Sub-Indices (148+)
Specialized indices like NIFTY Commodities, NIFTY Infrastructure, NIFTY MNC, etc.
Usage
Use Cases
Market Breadth
Track sectoral rotation by comparing index performances
Index Screeners
Build watchlists based on index membership
Benchmark Comparison
Compare stock returns against relevant sectoral indices
Correlation Analysis
Identify inter-sector correlations for portfolio diversification
fetch_etf_data.py
What It Does
Fetches all NSE-listed Exchange Traded Funds (ETFs) with live pricing, fundamentals, and performance metrics.API Endpoint
OgInst = ETF: Original Instrument type is ETFExch = NSE: Only NSE-listed ETFs (excludes BSE)
Output Format
File:etf_data_response.json (Array of ~361 ETFs)
ETF Categories
- Index ETFs (170+)
- Gold & Silver ETFs (45+)
- International ETFs (30+)
- Debt & Liquid ETFs (50+)
- Thematic & Strategy ETFs (66+)
Track major NSE indices:
- NIFTY 50 ETFs: Largest cap-weighted index
- NIFTY Next 50: Mid-cap index ETFs
- NIFTY Bank: Banking sector ETFs
- Sectoral ETFs: IT, Pharma, Auto, PSU, Infrastructure
Expense Ratio Insights
Usage
Use Cases
ETF Screener
Filter ETFs by expense ratio, tracking error, and liquidity
Passive Portfolio Construction
Build diversified portfolios using low-cost index ETFs
Sector Rotation
Identify outperforming sectoral ETFs for tactical allocation
Benchmark Comparison
Compare ETF performance vs underlying index (tracking error)
Running Optional Scripts in Pipeline
By default, these scripts are excluded from the main pipeline. To include them:Step 1: Enable Optional Fetch
Editrun_full_pipeline.py (lines 66-67):
Step 2: Run Pipeline
These files are NOT merged into
all_stocks_fundamental_analysis.json. They remain as standalone reference datasets.Data Freshness
Both scripts fetch live data from Dhan’s ScanX API:| Field | Update Frequency |
|---|---|
Ltp, Open, High, Low | Real-time (15-second delay) |
Volume | Cumulative intraday |
52W High/Low | Daily (post-market) |
| Technical Indicators (SMA, RSI) | End-of-day |
Comparison: Indices vs ETFs
| Feature | Indices (fetch_all_indices.py) | ETFs (fetch_etf_data.py) |
|---|---|---|
| Nature | Calculated benchmark (non-tradable) | Tradable securities |
| Volume | Not applicable (0) | Real trading volume |
| Expense Ratio | N/A | 0.05% - 1.00% |
| Dividends | Not applicable | Distributed to ETF holders |
| Tracking Error | N/A | Deviation from underlying index |
| Use Case | Benchmarking, market analysis | Direct investment, trading |
Error Handling
Both scripts include robust error handling:Next Steps
F&O Data Scripts
Fetch Futures & Options data
OHLCV History
Download lifetime price history
Pipeline Flags
Configure FETCH_OHLCV and FETCH_OPTIONAL
Output Reference
Explore all 86 fields in master JSON