Metadata-Version: 2.4
Name: indiaopt
Version: 0.1.1
Summary: Enterprise-grade Python library for NSE & BSE option chain and market data
Project-URL: Homepage, https://github.com/indiaopt/indiaopt
Project-URL: Documentation, https://indiaopt.readthedocs.io
Project-URL: Repository, https://github.com/indiaopt/indiaopt
Project-URL: Bug Tracker, https://github.com/indiaopt/indiaopt/issues
Project-URL: Changelog, https://github.com/indiaopt/indiaopt/blob/main/CHANGELOG.md
Author: indiaopt contributors
License: MIT
Keywords: bse,fintech,india,nse,option-chain,options,stock-market
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: cachetools>=5.0
Requires-Dist: curl-cffi>=0.7
Requires-Dist: pydantic-settings>=2.0
Requires-Dist: pydantic>=2.0
Requires-Dist: python-dotenv>=1.0
Provides-Extra: all
Requires-Dist: build>=1.2; extra == 'all'
Requires-Dist: hatchling>=1.21; extra == 'all'
Requires-Dist: mypy>=1.10; extra == 'all'
Requires-Dist: pytest-asyncio>=0.23; extra == 'all'
Requires-Dist: pytest-cov>=5.0; extra == 'all'
Requires-Dist: pytest>=8.0; extra == 'all'
Requires-Dist: redis>=5.0; extra == 'all'
Requires-Dist: respx>=0.21; extra == 'all'
Requires-Dist: ruff>=0.4; extra == 'all'
Requires-Dist: twine>=5.0; extra == 'all'
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: hatchling>=1.21; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: respx>=0.21; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Requires-Dist: twine>=5.0; extra == 'dev'
Provides-Extra: redis
Requires-Dist: redis>=5.0; extra == 'redis'
Description-Content-Type: text/markdown

# indiaopt

> Enterprise-grade Python library for Indian stock market (NSE & BSE) data.

[![PyPI version](https://badge.fury.io/py/indiaopt.svg)](https://badge.fury.io/py/indiaopt)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

`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_cffi` to 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, `.env` files, or code.

## Installation

```bash
pip install indiaopt
```

*Requires Python 3.10+*

## Quick Start

```python
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:

```ini
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:

```python
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`:

```python
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](https://indiaopt.readthedocs.io).

## License

MIT License. See `LICENSE` for details.
