nsefin


Namensefin JSON
Version 0.1.5 PyPI version JSON
download
home_pagehttps://github.com/vbhadala/nsefin
SummaryA Python library to download publicly available historical candlestick data from NSE India
upload_time2025-09-08 02:10:25
maintainerNone
docs_urlNone
authorVinod Bhadala
requires_python>=3.9
licenseNone
keywords nse stock market financial data india trading candlestick data
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# NSE Finance - Python Library for NSE India Data

A lightweight Python package to fetch commonly used market data from NSE India and shape it as pandas DataFrames for analysis and trading research.


## ✨ Features

* End‑of‑day (EOD) **bhavcopy** for equities & F\&O
* **Pre‑market** snapshots (All, FO, NIFTY categories)
* **Index details** for multiple market lists (e.g., *NIFTY 50*, *NIFTY AUTO*)
* **Option chain** + optional **Greeks** computation
* Convenience lists: equities, F\&O, ETFs
* **FII/DII** cash/derivatives activity
* **Corporate** actions & announcements, insider trades, upcoming results
* **Most active** (by value/volume, options & futures, OI, etc.)
* Historical data helpers for **equities** (and indices; see notes)

All functions are designed to return clean **`pandas.DataFrame`** objects (unless noted), ready for further transformation and visualization.

---

## 📦 Installation

```bash
pip install nsefin
```

**Requirements:** Python 3.9+, `pandas`, `requests` (and optionally `numpy`).

---

## 🚀 Quick Start

```python
import datetime as dt
import pandas as pd
import nsefin

nse = nsefin.NSEClient()

# Example: EOD Equity Bhavcopy
bhav = nse.get_equity_bhav_copy(dt.datetime(2025, 8, 14))
print(bhav.head())

# Example: Pre‑market (All)
pm_all = nse.get_pre_market_info(category="All")

# Example: Index details (see available market lists below)
ix = nse.get_index_details(category="NIFTY 50")

# Example: Option Chain + Greeks for NIFTY
oc = nse.get_option_chain("NIFTY")
og = nse.compute_greek(oc, strike_diff=50)
```

---

## 🔌 API Overview & Examples

### 1) EOD files

```python
# Equity bhavcopy (EOD)
nse.get_equity_bhav_copy(dt.datetime(2025, 8, 14))

# F&O bhavcopy (EOD)
nse.get_fno_bhav_copy(dt.datetime(2025, 8, 14))

# Optional post‑processing
nse.format_fo_data(df)
```

**Returns:** DataFrames with symbol, series, OHLC, volume/turnover, OI (for F\&O), etc.

---

### 2) Pre‑Market data

```python
nse.get_pre_market_info(category="All")
nse.get_pre_market_info(category="FO")
nse.get_pre_market_info(category="NIFTY")
```

**Tip:** Pre‑market snapshots are most useful before 9:15 IST and during early ticks.

---

### 3) Market Lists & Index Details

```python
# See all supported markets for index details
nse.endpoints.equity_market_list  # -> iterable of valid market names

# Fetch index details
nse.get_index_details(category="NIFTY 50")
nse.get_index_details(category="NIFTY AUTO")
```

**Output:** Index‑level stats (LTP, % change, PE/PB/DY, breadth, time‑window returns where available).

---

### 4) Option Chain & Greeks

```python
# Option chain for an index/stock (near‑dated by default; check function signature)
oc = nse.get_option_chain("NIFTY")

# Compute Greeks on a normalized OC DataFrame (requires columns like LTP, strike, etc.)
og = nse.compute_greek(oc, strike_diff=50)
```

**Note:** Greeks rely on implied vols/assumptions; read function docstring for parameters and expected columns.

---

### 5) Universe Helpers

```python
nse.get_equity_list()
nse.get_fno_list()
nse.get_etf_list()
```

**Use cases:** Screen eligible symbols, build watchlists, or validate tickers.

---

### 6) FII/DII Activity

```python
nse.get_fii_dii_activity()
```

**Common usage:** Market breadth and flows dashboard; daily net buy/sell across segments.

---

### 7) Corporate Data

```python
nse.get_corporate_actions()
nse.get_corporate_actions(subject_filter="dividend")  # filter examples: dividend, split, bonus
nse.get_corporate_announcements()
nse.get_insider_trading()
nse.get_upcoming_results()
```

---

### 8) Most Active & Derivatives Scans

```python
nse.get_most_active_by_volume()
nse.get_most_active_by_value()

nse.get_most_active_index_calls()
nse.get_most_active_index_puts()

nse.get_most_active_stock_calls()
nse.get_most_active_stock_puts()

nse.get_most_active_contracts_by_oi()
nse.get_most_active_contracts_by_volume()

nse.get_most_active_futures_by_volume()
nse.get_most_active_options_by_volume()
```

**Great for:** Intraday scanners, dispersion/volatility screens, liquidity checks for strategy filters.

---

### 9) Historical Data

```python
# Equities
nse.get_equity_historical_data("TCS", "15-08-2024", "31-12-2024")  # ~70 rows limit (API cap)

# Convenience wrapper (day_count based)
nse.history("TCS", day_count=200)

# Indices — currently not working (see Known Limitations below)
# nse.get_index_historical_data("NIFTY 50", "15-08-2024", "31-12-2024")
```


---

## ⚠️ Known Limitations & Notes

* **Index historical data**: `get_index_historical_data(...)` is currently **not working** (NSE endpoints may have changed / rate‑limited). Use alternate data sources or your own cached series.
* **52‑week high/low**: `get_52_week_high_low()` currently errors; pending fix.
* **Daily row caps**: NSE may cap history responses (e.g., \~70 rows). Prefer rolling downloads with local caching.
* **Stability**: NSE’s public endpoints can change without notice. Handle **HTTP 301/403/429**, add **retry with backoff**, and include a realistic **User‑Agent** header.
* **Compliance**: Respect NSE terms of use. This library is for **educational/research** purposes; not endorsed by or affiliated with NSE.

---

## 🛠️ Troubleshooting

* **Empty/blocked responses** → rotate/retry with polite backoff; verify cookies and headers.
* **Schema changes** → use `df.columns` introspection and normalize keys defensively.
* **Timezones** → NSE trading hours are IST; align your schedulers & timestamps accordingly.
* **Option Greeks** → Ensure required columns (spot, strike, rate, expiry, iv) are present/derived before calling `compute_greek`.

---

## 🗺️ Roadmap

* Stable index history with fallbacks
* Robust 52‑week high/low endpoint
* Built‑in caching & sqlite/duckdb persistence helpers
* Async client implementation
* Expanded Greeks/IV calculators + RND utilities

---

## 🤝 Contributing

PRs and issues welcome! Please:

1. Open an issue describing the bug/feature with sample payloads.
2. Add tests where possible.
3. Follow standard formatting (`black`, `ruff`) and type hints.

---

## 📄 License

MIT (or your preferred license). Update `LICENSE` accordingly.

---

## 🙏 Acknowledgements

* NSE India public website and documentation.
* Community packages & references that inspired certain endpoints and data normalizations.

---

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vbhadala/nsefin",
    "name": "nsefin",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "nse, stock market, financial data, india, trading, candlestick data",
    "author": "Vinod Bhadala",
    "author_email": "vinodbhadala@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f4/a9/c69323ad6bf1b65efdd580cbf4437d5b1a64bee9102747541dd40b03fece/nsefin-0.1.5.tar.gz",
    "platform": null,
    "description": "\n# NSE Finance - Python Library for NSE India Data\n\nA lightweight Python package to fetch commonly used market data from NSE India and shape it as pandas DataFrames for analysis and trading research.\n\n\n## \u2728 Features\n\n* End\u2011of\u2011day (EOD) **bhavcopy** for equities & F\\&O\n* **Pre\u2011market** snapshots (All, FO, NIFTY categories)\n* **Index details** for multiple market lists (e.g., *NIFTY 50*, *NIFTY AUTO*)\n* **Option chain** + optional **Greeks** computation\n* Convenience lists: equities, F\\&O, ETFs\n* **FII/DII** cash/derivatives activity\n* **Corporate** actions & announcements, insider trades, upcoming results\n* **Most active** (by value/volume, options & futures, OI, etc.)\n* Historical data helpers for **equities** (and indices; see notes)\n\nAll functions are designed to return clean **`pandas.DataFrame`** objects (unless noted), ready for further transformation and visualization.\n\n---\n\n## \ud83d\udce6 Installation\n\n```bash\npip install nsefin\n```\n\n**Requirements:** Python 3.9+, `pandas`, `requests` (and optionally `numpy`).\n\n---\n\n## \ud83d\ude80 Quick Start\n\n```python\nimport datetime as dt\nimport pandas as pd\nimport nsefin\n\nnse = nsefin.NSEClient()\n\n# Example: EOD Equity Bhavcopy\nbhav = nse.get_equity_bhav_copy(dt.datetime(2025, 8, 14))\nprint(bhav.head())\n\n# Example: Pre\u2011market (All)\npm_all = nse.get_pre_market_info(category=\"All\")\n\n# Example: Index details (see available market lists below)\nix = nse.get_index_details(category=\"NIFTY 50\")\n\n# Example: Option Chain + Greeks for NIFTY\noc = nse.get_option_chain(\"NIFTY\")\nog = nse.compute_greek(oc, strike_diff=50)\n```\n\n---\n\n## \ud83d\udd0c API Overview & Examples\n\n### 1) EOD files\n\n```python\n# Equity bhavcopy (EOD)\nnse.get_equity_bhav_copy(dt.datetime(2025, 8, 14))\n\n# F&O bhavcopy (EOD)\nnse.get_fno_bhav_copy(dt.datetime(2025, 8, 14))\n\n# Optional post\u2011processing\nnse.format_fo_data(df)\n```\n\n**Returns:** DataFrames with symbol, series, OHLC, volume/turnover, OI (for F\\&O), etc.\n\n---\n\n### 2) Pre\u2011Market data\n\n```python\nnse.get_pre_market_info(category=\"All\")\nnse.get_pre_market_info(category=\"FO\")\nnse.get_pre_market_info(category=\"NIFTY\")\n```\n\n**Tip:** Pre\u2011market snapshots are most useful before 9:15 IST and during early ticks.\n\n---\n\n### 3) Market Lists & Index Details\n\n```python\n# See all supported markets for index details\nnse.endpoints.equity_market_list  # -> iterable of valid market names\n\n# Fetch index details\nnse.get_index_details(category=\"NIFTY 50\")\nnse.get_index_details(category=\"NIFTY AUTO\")\n```\n\n**Output:** Index\u2011level stats (LTP, % change, PE/PB/DY, breadth, time\u2011window returns where available).\n\n---\n\n### 4) Option Chain & Greeks\n\n```python\n# Option chain for an index/stock (near\u2011dated by default; check function signature)\noc = nse.get_option_chain(\"NIFTY\")\n\n# Compute Greeks on a normalized OC DataFrame (requires columns like LTP, strike, etc.)\nog = nse.compute_greek(oc, strike_diff=50)\n```\n\n**Note:** Greeks rely on implied vols/assumptions; read function docstring for parameters and expected columns.\n\n---\n\n### 5) Universe Helpers\n\n```python\nnse.get_equity_list()\nnse.get_fno_list()\nnse.get_etf_list()\n```\n\n**Use cases:** Screen eligible symbols, build watchlists, or validate tickers.\n\n---\n\n### 6) FII/DII Activity\n\n```python\nnse.get_fii_dii_activity()\n```\n\n**Common usage:** Market breadth and flows dashboard; daily net buy/sell across segments.\n\n---\n\n### 7) Corporate Data\n\n```python\nnse.get_corporate_actions()\nnse.get_corporate_actions(subject_filter=\"dividend\")  # filter examples: dividend, split, bonus\nnse.get_corporate_announcements()\nnse.get_insider_trading()\nnse.get_upcoming_results()\n```\n\n---\n\n### 8) Most Active & Derivatives Scans\n\n```python\nnse.get_most_active_by_volume()\nnse.get_most_active_by_value()\n\nnse.get_most_active_index_calls()\nnse.get_most_active_index_puts()\n\nnse.get_most_active_stock_calls()\nnse.get_most_active_stock_puts()\n\nnse.get_most_active_contracts_by_oi()\nnse.get_most_active_contracts_by_volume()\n\nnse.get_most_active_futures_by_volume()\nnse.get_most_active_options_by_volume()\n```\n\n**Great for:** Intraday scanners, dispersion/volatility screens, liquidity checks for strategy filters.\n\n---\n\n### 9) Historical Data\n\n```python\n# Equities\nnse.get_equity_historical_data(\"TCS\", \"15-08-2024\", \"31-12-2024\")  # ~70 rows limit (API cap)\n\n# Convenience wrapper (day_count based)\nnse.history(\"TCS\", day_count=200)\n\n# Indices \u2014 currently not working (see Known Limitations below)\n# nse.get_index_historical_data(\"NIFTY 50\", \"15-08-2024\", \"31-12-2024\")\n```\n\n\n---\n\n## \u26a0\ufe0f Known Limitations & Notes\n\n* **Index historical data**: `get_index_historical_data(...)` is currently **not working** (NSE endpoints may have changed / rate\u2011limited). Use alternate data sources or your own cached series.\n* **52\u2011week high/low**: `get_52_week_high_low()` currently errors; pending fix.\n* **Daily row caps**: NSE may cap history responses (e.g., \\~70 rows). Prefer rolling downloads with local caching.\n* **Stability**: NSE\u2019s public endpoints can change without notice. Handle **HTTP 301/403/429**, add **retry with backoff**, and include a realistic **User\u2011Agent** header.\n* **Compliance**: Respect NSE terms of use. This library is for **educational/research** purposes; not endorsed by or affiliated with NSE.\n\n---\n\n## \ud83d\udee0\ufe0f Troubleshooting\n\n* **Empty/blocked responses** \u2192 rotate/retry with polite backoff; verify cookies and headers.\n* **Schema changes** \u2192 use `df.columns` introspection and normalize keys defensively.\n* **Timezones** \u2192 NSE trading hours are IST; align your schedulers & timestamps accordingly.\n* **Option Greeks** \u2192 Ensure required columns (spot, strike, rate, expiry, iv) are present/derived before calling `compute_greek`.\n\n---\n\n## \ud83d\uddfa\ufe0f Roadmap\n\n* Stable index history with fallbacks\n* Robust 52\u2011week high/low endpoint\n* Built\u2011in caching & sqlite/duckdb persistence helpers\n* Async client implementation\n* Expanded Greeks/IV calculators + RND utilities\n\n---\n\n## \ud83e\udd1d Contributing\n\nPRs and issues welcome! Please:\n\n1. Open an issue describing the bug/feature with sample payloads.\n2. Add tests where possible.\n3. Follow standard formatting (`black`, `ruff`) and type hints.\n\n---\n\n## \ud83d\udcc4 License\n\nMIT (or your preferred license). Update `LICENSE` accordingly.\n\n---\n\n## \ud83d\ude4f Acknowledgements\n\n* NSE India public website and documentation.\n* Community packages & references that inspired certain endpoints and data normalizations.\n\n---\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python library to download publicly available historical candlestick data from NSE India",
    "version": "0.1.5",
    "project_urls": {
        "Homepage": "https://github.com/vbhadala/nsefin"
    },
    "split_keywords": [
        "nse",
        " stock market",
        " financial data",
        " india",
        " trading",
        " candlestick data"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "71ee78e0db384aaca0d0ebccf60418caed638432c6e58c14ee64e44d24ea458a",
                "md5": "c91d5323e51d4edcac36b9f955836da9",
                "sha256": "098da4b2de2d76a0f54f16e9c2bcc9b61c323198267df402ed134d3f30953429"
            },
            "downloads": -1,
            "filename": "nsefin-0.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c91d5323e51d4edcac36b9f955836da9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 18607,
            "upload_time": "2025-09-08T02:10:24",
            "upload_time_iso_8601": "2025-09-08T02:10:24.047483Z",
            "url": "https://files.pythonhosted.org/packages/71/ee/78e0db384aaca0d0ebccf60418caed638432c6e58c14ee64e44d24ea458a/nsefin-0.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f4a9c69323ad6bf1b65efdd580cbf4437d5b1a64bee9102747541dd40b03fece",
                "md5": "7809686f33244a779b398b7c3e322f6d",
                "sha256": "aacc50d32f173574361b5025d9a9e5170ea2dcb83db7de7f3b1c33a303ec06ab"
            },
            "downloads": -1,
            "filename": "nsefin-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "7809686f33244a779b398b7c3e322f6d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 20994,
            "upload_time": "2025-09-08T02:10:25",
            "upload_time_iso_8601": "2025-09-08T02:10:25.600882Z",
            "url": "https://files.pythonhosted.org/packages/f4/a9/c69323ad6bf1b65efdd580cbf4437d5b1a64bee9102747541dd40b03fece/nsefin-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-08 02:10:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vbhadala",
    "github_project": "nsefin",
    "github_not_found": true,
    "lcname": "nsefin"
}
        
Elapsed time: 1.82166s