Python β’ Selenium β’ REST APIs
A Python-based REST API service that uses Selenium automation to fetch live market data from NSE India and expose it as HTTP APIs.
This project is designed for personal, research, and internal trading tools, where NSE data is required programmatically.
- Live NSE data using Selenium
- REST APIs using Python
http.server - Centralized browser management
- Supports Index & Equity data
- JSON-based responses
- Clean modular architecture
NseIndia/
β
βββ .venv/ # Virtual environment
β
βββ utils/ # Selenium scraping logic
β βββ browser_manager.py
β βββ get_option_chain.py
β βββ get_option_chain_v1.py
β βββ get_option_chain_v2.py
β βββ get_oi_spurts.py
β βββ get_MACEquityTable.py
β βββ get_top_20_gainers_losers.py
β βββ get_index_performance.py
β βββ get_volume_gainers.py
β βββ get_52_week_high_low.py
β βββ get_advances_or_declines.py
β βββ get_large_deals.py
β βββ ...
β
βββ main.py # API Server Entry Point
βββ test.py
βββ setup.txt
βββ Readme.md
- Python 3.9+
- Google Chrome (latest)
- ChromeDriver (matching Chrome version)
pip install selenium beautifulsoup4(Optional β Recommended)
pip install webdriver-manager-
Download ChromeDriver https://chromedriver.chromium.org/downloads
-
Add to system PATH or place in:
C:\Windows\System32
Use webdriver-manager inside browser_manager.py.
D:\TMSS\Project\StockPredict\Python\src\NseIndia> venv\Scripts\activatepython main.pyServer starts at:
http://localhost:8000
http://localhost:8000
GET /
GET /top-20-gainers-losers?index=NIFTY
index values
NIFTY, BANKNIFTY, NIFTYNEXT50, SecGtr20, SecLwr20, FOSec, all
GET /option-chain?index=NIFTY
GET /option-chain?stock=RELIANCE
Optional
expiry-date-index=0
GET /index-performance?page=broadMarket
Values:
broadMarket | sectoralIndices | otherIndices | fixedIncomeIndices | all
GET /volume-gainers
GET /oi-spurts
GET /most-active-contracts
GET /52-week-high-low
GET /advances-or-declines?page_type=advance
GET /large-deals
GET /version
- Missing parameters β
400 - Invalid values β
400 - Unknown endpoint β
404
Example:
{
"detail": "Wrong parameter. Available values are NIFTY, BANKNIFTY"
}- Selenium β Live NSE data
- BrowserManager β Single shared Chrome instance
- Utils Modules β One module per NSE page
- main.py β Lightweight REST server
Path
utils/get_option_chain.py
Fetches NSE Option Chain data for indices or stocks, parses CALL / STRIKE / PUT data, and returns structured JSON-ready output.
def get_option_chain(
dropdown_id,
index_name,
dropdown_id_expiry_date,
expiry_date_idx=0
)| Name | Description |
|---|---|
dropdown_id |
Dropdown ID for index/stock |
index_name |
Index or equity symbol |
dropdown_id_expiry_date |
Expiry dropdown ID |
expiry_date_idx |
Expiry index (0 = nearest) |
get_option_chain(
"equity_optionchain_select",
"NIFTY",
"expirySelect",
0
){
"STRIKE": 22000,
"CALLS": [...],
"PUTS": [...]
}"-"values converted to0.0- Data aligned exactly with NSE table layout
https://www.nseindia.com/option-chain
- Invalid expiry index β returns empty list
- NSE layout change β safe exit
- NSE blocks aggressive scraping
- Avoid high-frequency API calls
- Intended for educational / personal use
- Not affiliated with NSE India
- FastAPI migration
- Async scraping
- Redis caching
- Docker support
- Swagger / OpenAPI docs
NSE India Selenium API Project Built with Python & Selenium β€οΈ
If you want next:
- π¦ Dockerfile
- π FastAPI version
- π Swagger UI
- π§ͺ Unit tests
Just say the word π