Enterprise-grade Python library for NSE & BSE option chain and market data
Project description
indiaopt
Enterprise-grade Python library for Indian stock market (NSE & BSE) data.
indiaopt provides a robust, highly-performant, and production-ready interface to fetch Option Chain and Market Data from both the National Stock Exchange (NSE) and Bombay Stock Exchange (BSE) of India.
It includes built-in circuit breakers, exponential backoff, browser impersonation (via curl_cffi), automatic retry logic, and zero-overhead data models.
Features
- Multi-Exchange: Unified API for both NSE and BSE.
- Resilience: Built-in circuit breakers, automatic retries with exponential backoff and jitter.
- Evasion: Uses
curl_cffito impersonate browsers and avoid NSE rate-limiting/bot-protection. - Performance: Asynchronous via thread-pools, memory-efficient dataclasses (
slots=True), and connection pooling. - Type-Safe: Fully typed with PEP 561 compliance (
py.typed). - Configuration: Flexible configuration via environment variables,
.envfiles, or code.
Installation
pip install indiaopt
Requires Python 3.10+
Quick Start
import asyncio
from indiaopt import NSEClient
async def main():
# Context manager automatically handles session lifecycle
async with NSEClient() as nse:
# Fetch the option chain for NIFTY
result = await nse.fetch_option_chain("NIFTY")
print(f"Spot Price: {result.spot_price}")
print(f"ATM Strike: {result.atm_strike}")
print(f"Total Call OI: {result.total_call_oi}")
print(f"Total Put OI: {result.total_put_oi}")
print(f"PCR: {result.pcr:.2f}")
# Iterate over the 5 strikes above and below ATM
for row in result.atm_window(n=5):
print(f"Strike: {row.strike} | CE OI: {row.call_oi} | PE OI: {row.put_oi}")
if __name__ == "__main__":
asyncio.run(main())
Advanced Configuration
You can configure indiaopt via a .env file or environment variables:
INDIAOPT_MAX_RETRIES=5
INDIAOPT_FETCH_TIMEOUT=15.0
INDIAOPT_PROXY_URLS=http://proxy1:8080,http://proxy2:8080
INDIAOPT_LOG_LEVEL=INFO
Or configure it in code:
from indiaopt import NSEClient, Settings
settings = Settings(
max_retries=3,
fetch_timeout=10.0,
circuit_failure_threshold=5,
)
async with NSEClient(settings=settings) as nse:
result = await nse.fetch_option_chain("BANKNIFTY")
Exception Handling
The library provides a detailed exception hierarchy under IndiaOptError:
from indiaopt import RateLimitError, CircuitOpenError, NSEClient
try:
async with NSEClient() as nse:
await nse.fetch_option_chain("NIFTY")
except RateLimitError as e:
print(f"Rate limited by exchange! Try again in {e.retry_after} seconds.")
except CircuitOpenError as e:
print(f"Circuit breaker is open. Fails fast without hitting network.")
Documentation
Full documentation is available at https://indiaopt.readthedocs.io.
License
MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file indiaopt-0.1.1.tar.gz.
File metadata
- Download URL: indiaopt-0.1.1.tar.gz
- Upload date:
- Size: 30.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02a15d6b99e8eabab0f6081f23454de3c77655f7a3183450a235e7977fe209f7
|
|
| MD5 |
0d4b4bf7dae3b2b659d9f83ba6ed1314
|
|
| BLAKE2b-256 |
699587e72c51add2c90981ef81ed7dc003ff5b3c5c328de267a5bb5a3026293c
|
File details
Details for the file indiaopt-0.1.1-py3-none-any.whl.
File metadata
- Download URL: indiaopt-0.1.1-py3-none-any.whl
- Upload date:
- Size: 37.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3878e5af70a968439175c1451648ed24523caf1c9f533b9eab5d4e01ce3a6b73
|
|
| MD5 |
fb8acf03f46757bf0a48822782b98031
|
|
| BLAKE2b-256 |
5c8b2584162b250bd5fbf34b180af834aa84e322b0a5bd6a31d9f1b76163f51f
|