Download historical OHLC (Open, High, Low, Close) data for NSE stocks, indices, and ETFs. Timeframes supported: Daily (1d), Weekly (1w), Monthly (1m), Quarterly (1q), Yearly (1y)
Try the application on: https://nse-data-downloader.streamlit.app/
Fixed: Data download issues on Streamlit Cloud deployment
- Updated NSE API requests to properly maintain session cookies
- Enhanced User-Agent headers for better compatibility
- Added Referer header to prevent blocking
- Improved error handling with diagnostic messages
- All bhav copy methods now use session object for consistent authentication
- Download data for stocks, indices, and ETFs from NSE India
- Multiple timeframes: Daily (1d), Weekly (1w), Monthly (1m), Quarterly (1q), Yearly (1y)
- Web-based UI (Streamlit) or Command-line interface
- Auto-normalization of index names for NSE format
- Progress tracking during downloads
- CSV export functionality
- Python 3.8 or higher
- Virtual environment (recommended)
- Clone the repository:
git clone https://github.com/kython220282/NSE-Data-Downloader.git
cd NSE-Data-Downloader
- Create and activate virtual environment:
python -m venv .venv
.venv\Scripts\activate
- Install required packages:
uv pip install -r requirements.txt
Or install manually:
uv pip install streamlit pandas requests
Run the following command in your terminal:
streamlit run app.py
The application will open in your browser at http://localhost:8501
-
Select Instrument Type:
- Choose "Index" for market indices
- Choose "Stock/ETF" for individual stocks or ETFs
-
Enter Symbol/Index Name:
- For Indices: NIFTY 50, Nifty Bank, Nifty Midcap 150, etc.
- For Stocks: RELIANCE, TCS, INFY, etc.
- For ETFs: NIFTYBEES, BANKBEES, etc.
-
Select Date Range:
- From Date: Start date for data download
- To Date: End date for data download
-
Choose Timeframe:
- 1d (Daily): Raw daily data
- 1w (Weekly): Aggregated weekly data
- 1m (Monthly): Aggregated monthly data
- 1q (Quarterly): Aggregated calendar quarter data
- 1y (Yearly): Aggregated calendar year data
-
Click "Download Data" button
-
View Results:
- Data preview table shows downloaded records
- Summary statistics displayed
- Download CSV button to save data locally
- Index names are automatically normalized (e.g., "nifty 50" becomes "NIFTY 50")
- Stock symbols should be entered in uppercase
- Data is downloaded from NSE bhav copy files
- Progress bar shows download status
Execute the following command:
python nse_data_downloader.py
The script will ask for the following inputs:
-
Instrument Type:
- Enter "1" for Index
- Enter "2" for Stock/ETF
-
Symbol/Index Name:
- Enter the exact name (e.g., NIFTY 50, RELIANCE, NIFTYBEES)
-
From Date:
- Enter date in DD-MM-YYYY format (e.g., 01-01-2024)
-
To Date:
- Enter date in DD-MM-YYYY format (e.g., 31-12-2024)
-
Timeframe:
- Enter "1" for daily data (1d)
- Enter "2" for weekly data (1w)
- Enter "3" for monthly data (1m)
- Enter "4" for quarterly data (1q)
- Enter "5" for yearly data (1y)
NSE Historical Data Downloader
Select instrument type:
1. Index
2. Stock/ETF
Enter choice (1 or 2): 1
Enter index name (e.g., NIFTY 50): NIFTY 50
Enter FROM date (DD-MM-YYYY): 01-01-2024
Enter TO date (DD-MM-YYYY): 31-01-2024
Select timeframe:
1. Daily (1d)
2. Weekly (1w)
3. Monthly (1m)
4. Quarterly (1q)
5. Yearly (1y)
Enter choice (1/2/3/4/5): 1
Downloading data for NIFTY 50...
Progress: 100%
Successfully downloaded 20 records
Data saved to: NIFTY_50_1d_20240101_to_20240131.csv
Downloaded data is saved as CSV files with the naming format:
SymbolName_Timeframe_FromDate_to_ToDate.csv
Example: NIFTY_50_1d_20240101_to_20240131.csv
All downloaded CSV files contain the following columns:
- Symbol: Stock/Index name
- Date: Trading date (DD-MM-YYYY format)
- Open: Opening price/value
- High: Highest price/value
- Low: Lowest price/value
- Close: Closing price/value
- Volume: Trading volume
- NIFTY 50
- NIFTY Bank
- NIFTY IT
- NIFTY Midcap 150
- NIFTY Midcap 100
- NIFTY Smallcap 250
- NIFTY Next 50
- NIFTY Alpha 50
All NSE-listed stocks using their trading symbols (e.g., RELIANCE, TCS, INFY, HDFC)
NSE-listed ETFs using their trading symbols (e.g., NIFTYBEES, BANKBEES, JUNIORBEES)
Weekly Data (1w):
- Aggregated to Friday close
- Open: First day's open
- High: Highest of the week
- Low: Lowest of the week
- Close: Last day's close
- Volume: Sum of daily volumes
Monthly Data (1m):
- Aggregated to month end
- Open: First day's open
- High: Highest of the month
- Low: Lowest of the month
- Close: Last day's close
- Volume: Sum of daily volumes
Quarterly Data (1q):
- Aggregated to calendar quarter end (Mar/Jun/Sep/Dec)
- Open: First day's open in the quarter
- High: Highest of the quarter
- Low: Lowest of the quarter
- Close: Last day's close in the quarter
- Volume: Sum of daily volumes
Yearly Data (1y):
- Aggregated to calendar year end (Dec)
- Open: First day's open in the year
- High: Highest of the year
- Low: Lowest of the year
- Close: Last day's close in the year
- Volume: Sum of daily volumes
If you receive "No data found" error:
- Verify the symbol/index name is correct
- Ensure date range includes trading days (not only weekends/holidays)
- Check if NSE website is accessible
- For indices, try exact name matching (case-sensitive)
If downloads are slow or failing:
- Check internet connection
- NSE website may have rate limits
- Try smaller date ranges
- Run during non-peak hours
Index names are case-sensitive in NSE data:
- Correct: "NIFTY 50", "NIFTY Bank", "NIFTY Midcap 100"
- Incorrect: "nifty 50", "Nifty BANK", "NIFTY MIDCAP 100"
The Streamlit app auto-corrects common naming patterns.
NseUtility/
├── app.py # Streamlit web application
├── nse_data_downloader.py # Command-line interface script
├── NseUtility.py # Core NSE API wrapper library
├── NSE Download.py # API documentation and examples
├── requirements.txt # Python package dependencies
└── README.md # This file
- streamlit: Web application framework
- pandas: Data manipulation and analysis
- requests: HTTP library for API calls
All other packages are automatically installed as dependencies.
Data is downloaded from NSE India's official bhav copy files, which are publicly available market data files published daily by the National Stock Exchange of India.
This tool is for educational and personal use. Please ensure compliance with NSE's terms of service when using this data.
For issues or questions:
- Verify all prerequisites are installed
- Check that symbol/index names are correct
- Ensure date formats match DD-MM-YYYY
- Review error messages for specific issues