### Install nselib Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Use pip to install the nselib library. For an upgrade, use the --upgrade flag. ```bash pip install nselib ``` ```bash pip install nselib --upgrade ``` -------------------------------- ### Get Top Gainers in Live Market Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Fetches a list of top gainers in the live market. Accepts 'gainers' or 'losers' as an argument. ```python df = capital_market.top_gainers_or_losers('gainers') ``` -------------------------------- ### Get FII/DII Trading Activity Source: https://context7.com/ruchitanmay/nselib/llms.txt Returns the current-day or last available FII and DII buy/sell activity summary. No parameters are required. ```python from nselib import capital_market df = capital_market.fii_dii_trading_activity() print(df) # Columns: category, buyValue, sellValue, netValue ``` -------------------------------- ### Fetch SME Bhav Copy and Band Complete Data Source: https://context7.com/ruchitanmay/nselib/llms.txt Get SME bhav copy and SME price band complete data for a specific trading date. Requires the 'nselib.capital_market' module. ```python from nselib import capital_market sme_bhav = capital_market.sme_bhav_copy(trade_date='20-06-2024') sme_band = capital_market.sme_band_complete(trade_date='20-06-2024') print(sme_bhav.head()) print(sme_band.head()) ``` -------------------------------- ### Get Option Expiry Dates by Index Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieves a dictionary mapping index names to their respective option expiry dates. Use specific index keys like 'NIFTY' or 'BANKNIFTY' to get their expiry lists. ```python from nselib import derivatives index_expiry_map = derivatives.expiry_dates_option_index() print(index_expiry_map['NIFTY']) print(index_expiry_map['BANKNIFTY']) ``` -------------------------------- ### Get Deliverable Quantity Data (Capital Market) Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetch only the deliverable quantity related columns for an equity symbol. Supports period shorthands or explicit date ranges. ```python from nselib import capital_market df = capital_market.deliverable_position_data(symbol='HDFCBANK', period='1M') print(df) # Expected columns: Symbol, Series, Date, TotalTradedQuantity, DeliverableQty, % Dly Qt to Traded Qty ``` -------------------------------- ### Get Live Snapshot of All Indices Source: https://context7.com/ruchitanmay/nselib/llms.txt Provides a live intraday snapshot, or an end-of-day snapshot after market hours, for all NSE indices. Useful for a quick overview of market performance across different indices. ```python from nselib import capital_market df = capital_market.market_watch_all_indices() print(df[['index', 'last', 'percentChange', 'yearHigh', 'yearLow']].head(10)) ``` -------------------------------- ### Get Live Index Performances Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Retrieves the live performance data for all indices. This function does not require any parameters. ```python df = indices.live_index_performances() ``` -------------------------------- ### Get Bhav Copy with Delivery Data Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Retrieve the daily bhav copy including delivery data for a specific trade date. ```python df = capital_market.bhav_copy_with_delivery(trade_date='20-06-2024') ``` -------------------------------- ### Get Available Debt Securities Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Retrieves a list of debt securities available for trading on a specific date. Requires the `debt` module from nselib. ```python from nselib import debt df = debt.securities_available_for_trading(trade_date='20-12-2025') ``` -------------------------------- ### Get Total Traded Stocks Summary Source: https://context7.com/ruchitanmay/nselib/llms.txt Returns a summary dictionary of live market statistics and a DataFrame of all traded stocks. No parameters are required. ```python from nselib import capital_market summary, detail_df = capital_market.total_traded_stocks() print(f"Summary: {summary}") # dict with advances, declines, unchanged counts print(detail_df.head()) ``` -------------------------------- ### Get Live Index Performances Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieves live or last-traded performance data for all NSE indices. Displays key metrics like last traded price, percentage change, and yearly high/low. ```python from nselib import indices df = indices.live_index_performances() print(df[['indexSymbol', 'last', 'percentChange', 'yearHigh', 'yearLow']].head(10)) ``` -------------------------------- ### Get Live Option Chain Data Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Fetches the live option chain for a specific symbol and expiry date. The expiry date is optional; if omitted, the nearest expiry is used. `oi_mode` can be set to 'compact' for fewer columns. ```python df = derivatives.nse_live_option_chain(symbol='BANKNIFTY', expiry_date='27-03-2025') ``` ```python df = derivatives.nse_live_option_chain(symbol='NIFTY', oi_mode='compact') ``` -------------------------------- ### Fetch Options Price and Volume Data Source: https://context7.com/ruchitanmay/nselib/llms.txt Get contract-wise options price and volume data for a symbol, instrument type, and optional option type. Iterates over both CE and PE if `option_type` is omitted. Use 'OPTIDX' for index options and 'OPTSTK' for stock options. ```python from nselib import derivatives # NIFTY index call options for last 1 week df_ce = derivatives.option_price_volume_data( symbol='NIFTY', instrument='OPTIDX', # OPTIDX = index options, OPTSTK = stock options option_type='CE', period='1W' ) print(df_ce.head()) ``` ```python # All SBIN stock option contracts (CE + PE) for a date range df_all = derivatives.option_price_volume_data( symbol='SBIN', instrument='OPTSTK', from_date='01-12-2024', to_date='31-12-2024' ) print(df_all.groupby('OPTION_TYP').size()) ``` -------------------------------- ### Get Future Expiry Dates Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieves a list of future expiry dates for derivatives. The output is a list of strings representing dates. ```python from nselib import derivatives future_expiries = derivatives.expiry_dates_future() print(future_expiries) # ['27-Mar-2025', '24-Apr-2025', ...] ``` -------------------------------- ### Get Volume by Participant Category Source: https://context7.com/ruchitanmay/nselib/llms.txt Returns the trading volume breakdown by participant category for a specific trading date. ```python from nselib import derivatives df = derivatives.participant_wise_trading_volume(trade_date='16-09-2024') print(df) ``` -------------------------------- ### Get FII Derivatives Statistics Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Retrieves Foreign Institutional Investor (FII) derivatives statistics for a specific trade date. ```python df = derivatives.fii_derivatives_statistics(trade_date='20-12-2025') ``` -------------------------------- ### Get F&O-eligible index list with lot sizes Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches a list of all F&O-eligible index underlyings, such as NIFTY and BANKNIFTY, including their respective lot sizes. This is essential for F&O index trading analysis. ```python from nselib import capital_market df = capital_market.fno_index_list() print(df) ``` -------------------------------- ### Get VaR Margin Data for Trading Day Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches Value-at-Risk (VaR) margin data at different intraday snapshots for a given trading date. This includes data from the beginning of the day, multiple intraday updates, and the end of the day. ```python from nselib import capital_market # VaR at beginning of day df_begin = capital_market.var_begin_day(trade_date='20-06-2024') # VaR at 1st intraday update df_intra1 = capital_market.var_1st_intra_day(trade_date='20-06-2024') # VaR at end of day df_eod = capital_market.var_end_of_day(trade_date='20-06-2024') print(df_eod.columns.tolist()) # var_columns from constants ``` -------------------------------- ### Get Constituent Stocks for an Index Source: https://context7.com/ruchitanmay/nselib/llms.txt Downloads the current constituent stock list for a given NSE index. Provides company details and a link to the index's fact sheet for more information. ```python from nselib import indices df = indices.constituent_stock_list( index_category='BroadMarketIndices', index_name='Nifty 50' ) print(df.head()) # Also prints: "Note: For more detail information related to Nifty 50. Please check the Fact Sheet - " ``` ```python sectoral_df = indices.constituent_stock_list( index_category='SectoralIndices', index_name='Nifty Bank' ) print(sectoral_df[['Company Name', 'Symbol', 'Industry']]) ``` -------------------------------- ### Get F&O-eligible equity list with lot sizes Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieves a list of all F&O-eligible equity underlyings along with their current lot sizes. Useful for understanding the universe of F&O tradable equities. ```python from nselib import capital_market df = capital_market.fno_equity_list() print(df.columns.tolist()) # includes symbol, lotSize, etc. print(df.head()) ``` -------------------------------- ### Get OHLCV + Deliverable Position Data (Capital Market) Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetch Open, High, Low, Close, Volume, and Deliverable Quantity data for a given equity symbol. Supports period shorthands or explicit date ranges. Handles long date ranges by auto-chunking. ```python from nselib import capital_market # Using a period shorthand df = capital_market.price_volume_and_deliverable_position_data(symbol='SBIN', period='1M') print(df.columns.tolist()) # ['Symbol', 'Series', 'Date', 'Prev Close', 'Open Price', 'High Price', 'Low Price', # 'Last Price', 'Close Price', 'Average Price', 'TotalTradedQuantity', 'TurnoverInRs', # 'No.ofTrades', 'DeliverableQty', '% Dly Qt to Traded Qty'] ``` ```python from nselib import capital_market # Using an explicit date range df = capital_market.price_volume_and_deliverable_position_data( symbol='RELIANCE', from_date='01-01-2024', to_date='31-03-2024' ) print(df.shape) # (num_rows, 15) print(df.head(3)) ``` -------------------------------- ### Get OHLCV Price and Volume Data (Capital Market) Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetch Open, High, Low, Close, and Volume data for an equity symbol without deliverable quantity details. Supports period shorthands or explicit date ranges. Handles multi-year ranges by auto-chunking. ```python from nselib import capital_market df = capital_market.price_volume_data(symbol='INFY', period='6M') print(df[['Date', 'Open Price', 'High Price', 'Low Price', 'Close Price', 'TotalTradedQuantity']]) ``` ```python from nselib import capital_market # Multi-year range (auto-chunked into 365-day windows) df = capital_market.price_volume_data( symbol='TCS', from_date='01-01-2022', to_date='31-12-2023' ) print(df.shape) ``` -------------------------------- ### Fetch Stock Price Volume Data Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Get price volume data for a stock using the capital_market module. You can specify a period like '1M' for one month, or provide custom date ranges. ```python from nselib import capital_market # Get price volume data for a stock (last 1 month) df = capital_market.price_volume_data(symbol='SBIN', period='1M') print(df.head()) ``` ```python # Or specify a custom date range df = capital_market.price_volume_and_deliverable_position_data( symbol='SBIN', from_date='01-01-2024', to_date='31-01-2024' ) print(df) ``` -------------------------------- ### Get Equity Financial Results Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches quarterly or annual financial results for equities. Can filter by F&O securities and specify a period or date range. ```python from nselib import capital_market # Quarterly results for F&O securities over the last 6 months df = capital_market.financial_results_for_equity( period='6M', fo_sec=True, fin_period='Quarterly' ) print(df.head()) # Annual results for all equities in a date range df_annual = capital_market.financial_results_for_equity( from_date='01-01-2024', to_date='31-03-2024', fo_sec=False, fin_period='Annual' ) ``` -------------------------------- ### Fetch AMFI Monthly Data with File Type Priority Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieves AMFI monthly data, prioritizing XLS and XLSX files over PDF. Use this to get specific monthly financial reports. ```python from nselib import cash_market df_xls = cash_market.amfi_monthly_data( report_month='01-01-2026', file_type_priority=('xls', 'xlsx', 'pdf') ) print(df_xls.head()) ``` -------------------------------- ### Get Futures Price and Volume Data Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Retrieves futures price and volume data for a given symbol and instrument type over a specified period. Valid instrument types include FUTIDX and FUTSTK. ```python df = derivatives.future_price_volume_data( symbol='SBIN', instrument='FUTSTK', period='1M' ) ``` -------------------------------- ### Get List of All NSE-Listed Equities Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieve a DataFrame containing all equity instruments listed on the NSE. Includes details like symbol, company name, series, listing date, and face value. ```python from nselib import capital_market df = capital_market.equity_list() print(df.shape) # (total_listed_equities, 5) print(df.head()) # SYMBOL | NAME OF COMPANY | SERIES | DATE OF LISTING | FACE VALUE # 20MICRONS | 20 Microns Limited | EQ | 06-10-2008 | 5 ``` -------------------------------- ### Get Capital Market Daily Volatility Report Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches the daily volatility report for the capital market (NSCCL CMVOLT file) for a specific trading date. The function automatically attempts to use multiple URL sources if one fails. ```python from nselib import capital_market df = capital_market.daily_volatility(trade_date='17-04-2026') print(df.head()) # Columns typically include Symbol, Series, VaR%, ELM%, Adhoc Margin%, Applicable Margin% try: df = capital_market.daily_volatility(trade_date='01-01-2026') # holiday except FileNotFoundError as e: print(f"Not found: {e}") ``` -------------------------------- ### Get CM Segment Business Growth Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches historical business growth statistics for the NSE capital market segment at yearly, monthly, or daily granularity. Use `data_type='yearly'`, `'monthly'`, or `'daily'`. ```python from nselib import capital_market # Yearly data (all available years) df_yearly = capital_market.business_growth_cm_segment(data_type='yearly') print(df_yearly.head()) ``` -------------------------------- ### Get 52-Week High/Low Report Source: https://context7.com/ruchitanmay/nselib/llms.txt Downloads the 52-week high and low report for all NSE Capital Market (CM) securities for a specified trading date. This report is useful for identifying stocks reaching significant price levels. ```python from nselib import capital_market df = capital_market.week_52_high_low_report(trade_date='20-06-2024') print(df.head()) ``` -------------------------------- ### Download Daily Bhav Copy with Delivery Data (Capital Market) Source: https://context7.com/ruchitanmay/nselib/llms.txt Download the end-of-day bhav copy for all traded securities on a specific date, including delivery quantities. Raises FileNotFoundError if data is unavailable for the given date (e.g., holidays). ```python from nselib import capital_market df = capital_market.bhav_copy_with_delivery(trade_date='20-06-2024') print(df.head()) # Columns: SYMBOL, SERIES, OPEN, HIGH, LOW, CLOSE, LAST, # PREVCLOSE, # TOTTRDQTY, TOTTRDVAL, TIMESTAMP, TOTALTRADES, ISIN, DeliverableQty, ... ``` ```python from nselib import capital_market try: df = capital_market.bhav_copy_with_delivery(trade_date='01-01-2024') # holiday except FileNotFoundError as e: print(f"No data: {e}") ``` -------------------------------- ### var_begin_day Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Retrieves VaR (Value at Risk) data for the beginning of the day for a specific trade date. ```APIDOC ## var_begin_day() ### Description Retrieves VaR data for the beginning of the day. ### Method `capital_market.var_begin_day()` ### Parameters #### Path Parameters - **trade_date** (string) - Required - The date in 'DD-MM-YYYY' format. ``` -------------------------------- ### Get NSDL FPI Investment Activity Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Retrieves NSDL Foreign Portfolio Investor (FPI) investment activity for a specific reporting date. Use the latest function to get the most recent data without a date. ```python df = cash_market.nsdl_fpi_investment_activity(trade_date='30-10-2025') ``` ```python df = cash_market.nsdl_fpi_latest_derivative_activity() ``` -------------------------------- ### Get Most Active Equities Source: https://context7.com/ruchitanmay/nselib/llms.txt Returns the most actively traded equities, sortable by traded value or volume. Use `fetch_by='value'` or `fetch_by='volume'`. ```python from nselib import capital_market # Most active by value df_val = capital_market.most_active_equities(fetch_by='value') print(df_val[['symbol', 'lastPrice', 'totalTradedVolume', 'totalTradedValue']].head()) # Most active by volume df_vol = capital_market.most_active_equities(fetch_by='volume') print(df_vol.head()) ``` -------------------------------- ### sme_bhav_copy() / sme_band_complete() Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches the SME bhav copy and SME price band complete data for a trading date. ```APIDOC ## sme_bhav_copy() / sme_band_complete() ### Description Fetches the SME bhav copy and SME price band complete data for a trading date. ### Method ```python capital_market.sme_bhav_copy(trade_date: str) capital_market.sme_band_complete(trade_date: str) ``` ### Parameters #### Path Parameters - **trade_date** (str) - Required - The trading date in DD-MM-YYYY format. ``` -------------------------------- ### bhav_copy_with_delivery() Source: https://context7.com/ruchitanmay/nselib/llms.txt Downloads the full NSE equity bhav copy for a specific trading date, including delivery quantities. ```APIDOC ## bhav_copy_with_delivery() ### Description Downloads the full NSE equity bhav copy (end-of-day snapshot for all traded securities) for a specific trading date, including delivery quantities. ### Method `capital_market.bhav_copy_with_delivery(trade_date: str)` ### Parameters #### Path Parameters None #### Query Parameters - **trade_date** (str) - Required - The trading date in 'dd-mm-YYYY' format (e.g., '20-06-2024'). ### Request Example ```python from nselib import capital_market df = capital_market.bhav_copy_with_delivery(trade_date='20-06-2024') print(df.head()) try: df = capital_market.bhav_copy_with_delivery(trade_date='01-01-2024') # holiday except FileNotFoundError as e: print(f"No data: {e}") ``` ### Response #### Success Response (pandas.DataFrame) DataFrame containing columns such as 'SYMBOL', 'SERIES', 'OPEN', 'HIGH', 'LOW', 'CLOSE', 'LAST', 'PREVCLOSE', 'TOTTRDQTY', 'TOTTRDVAL', 'TIMESTAMP', 'TOTALTRADES', 'ISIN', 'DeliverableQty'. #### Response Example ``` SYMBOL | SERIES | OPEN | HIGH | LOW | CLOSE | LAST | PREVCLOSE | TOTTRDQTY | TOTTRDVAL | TIMESTAMP | TOTALTRADES | ISIN | DeliverableQty | ... ``` ``` -------------------------------- ### Get Financial Results for Equity Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Retrieves financial results for F&O securities, specifying the period and financial reporting frequency. ```python df = capital_market.financial_results_for_equity(period='6M', fo_sec=True, fin_period='Quarterly') ``` -------------------------------- ### var_begin_day(), var_1st_intra_day(), ..., var_end_of_day() Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieves Value-at-Risk (VaR) margin data at different intraday snapshots for a trading date, including beginning of day, multiple intraday updates, and end of day. ```APIDOC ## var_begin_day(), var_1st_intra_day(), ..., var_end_of_day() ### Description Fetches Value-at-Risk (VaR) margin data at different intraday snapshots for a trading date: beginning of day, 1st–4th intraday updates, and end of day. ### Method `capital_market.var_begin_day(trade_date='YYYY-MM-DD')` `capital_market.var_1st_intra_day(trade_date='YYYY-MM-DD')` `capital_market.var_end_of_day(trade_date='YYYY-MM-DD')` (Other intraday functions available: `var_2nd_intra_day`, `var_3rd_intra_day`, `var_4th_intra_day`) ### Parameters #### Query Parameters - **trade_date** (string) - Required - The trading date for which to fetch VaR data in 'DD-MM-YYYY' format. ### Response Example ```json { "Symbol": "INFY", "Margin": 15000.00 } ``` ``` -------------------------------- ### nse_live_option_chain() Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches the real-time option chain for any F&O symbol. Supports `full` mode (includes bid/ask) or `compact` mode (fewer columns). ```APIDOC ## nse_live_option_chain() ### Description Fetches the real-time option chain for any F&O symbol. Supports `full` mode (includes bid/ask) or `compact` mode (fewer columns). ### Method ```python derivatives.nse_live_option_chain(symbol: str, expiry_date: str = None, oi_mode: str = 'full') ``` ### Parameters #### Query Parameters - **symbol** (str) - Required - The trading symbol (e.g., 'BANKNIFTY', 'NIFTY'). - **expiry_date** (str) - Optional - The expiry date in DD-MM-YYYY format. If omitted, the nearest expiry is used. - **oi_mode** (str) - Optional - The mode for fetching option chain data. Options are 'full' (default) or 'compact'. ``` -------------------------------- ### Get India VIX Data for a Period Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Fetch historical India VIX data for a specified period, such as the last week. ```python df = capital_market.india_vix_data(period='1W') ``` -------------------------------- ### Get Top Gainers or Losers Source: https://context7.com/ruchitanmay/nselib/llms.txt Returns the top gaining or losing equities based on index category. Use `to_get='gainers'` or `to_get='loosers'`. ```python from nselib import capital_market # Top gainers gainers = capital_market.top_gainers_or_losers(to_get='gainers') print(gainers[['symbol', 'lastPrice', 'pChange']].head()) # Top losers losers = capital_market.top_gainers_or_losers(to_get='loosers') print(losers.head()) ``` -------------------------------- ### Download NSE PE Ratio Report Source: https://context7.com/ruchitanmay/nselib/llms.txt Downloads the NSE PE ratio report for all listed equities on a specific trading date. Requires the `trade_date` parameter. ```python from nselib import capital_market df = capital_market.pe_ratio(trade_date='20-06-2024') print(df.head()) ``` -------------------------------- ### Fetch Futures Price and Volume Data Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieve contract-wise futures price and volume data for a given symbol and instrument type. Automatically paginates in 90-day windows. Use 'FUTSTK' for stock futures and 'FUTIDX' for index futures. ```python from nselib import derivatives # SBIN stock futures for last 1 month df = derivatives.future_price_volume_data( symbol='SBIN', instrument='FUTSTK', # FUTSTK = stock futures, FUTIDX = index futures period='1M' ) print(df.head()) # Columns: INSTRUMENT, SYMBOL, EXPIRY_DT, OPEN, HIGH, LOW, CLOSE, # SETTLE_PR, CONTRACTS, VAL_INLAKH, OPEN_INT, CHG_IN_OI, TIMESTAMP ``` ```python # BANKNIFTY index futures with explicit date range df_idx = derivatives.future_price_volume_data( symbol='BANKNIFTY', instrument='FUTIDX', from_date='01-11-2025', to_date='08-12-2025' ) ``` -------------------------------- ### Get F&O Daily Volatility Report Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Fetches the daily volatility report for the Futures and Options segment for a given trade date. ```python df = derivatives.daily_volatility(trade_date='17-04-2026') ``` -------------------------------- ### Get Daily Volatility Report Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Retrieves the daily volatility report for a specific trade date. Ensure the date is in the correct format. ```python df = capital_market.daily_volatility(trade_date='17-04-2026') ``` -------------------------------- ### Import Capital Market Module Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Import the necessary module for accessing capital market data. ```python from nselib import capital_market ``` -------------------------------- ### pe_ratio() Source: https://context7.com/ruchitanmay/nselib/llms.txt Downloads the NSE PE ratio report for all listed equities for a specific trading date. ```APIDOC ## pe_ratio() ### Description Downloads the NSE PE ratio report for all listed equities for a specific trading date. ### Method `capital_market.pe_ratio(trade_date: str)` ### Parameters #### Path Parameters None #### Query Parameters - **trade_date** (str) - Required - The trading date for which to fetch the PE ratio report (e.g., '20-06-2024'). ### Request Example ```python from nselib import capital_market df = capital_market.pe_ratio(trade_date='20-06-2024') print(df.head()) ``` ### Response #### Success Response (200) Returns a pandas DataFrame containing the PE ratio for all NSE equities for the specified date. ``` -------------------------------- ### Download SME Segment Bhav Copy (Capital Market) Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetch the bhavcopy specifically for the NSE SME (Small and Medium Enterprises) segment for a given trading date. ```python from nselib import capital_market df = capital_market.bhav_copy_sme(trade_date='20-06-2024') print(df.head()) ``` -------------------------------- ### Get Index Constituent Stocks Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Fetches the list of stocks that constitute a given index. Requires both the index category and the specific index name. ```python df = indices.constituent_stock_list(index_category='BroadMarketIndices', index_name='Nifty 50') ``` -------------------------------- ### Get Historical Index Data Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Fetches historical data for a specified index between two dates. Requires index name and date range. ```python df = capital_market.index_data(index='NIFTY 50', from_date='01-01-2024', to_date='31-03-2024') ``` -------------------------------- ### market_watch_all_indices() Source: https://context7.com/ruchitanmay/nselib/llms.txt Provides a live intraday snapshot of all NSE indices, including current price, percentage change, and yearly high/low. ```APIDOC ## market_watch_all_indices() ### Description Returns a live intraday snapshot (or end-of-day snapshot after market hours) for all NSE indices. ### Method `capital_market.market_watch_all_indices()` ### Parameters None ### Response Example ```json { "index": "NIFTY 50", "last": 23500.00, "percentChange": 0.50, "yearHigh": 24000.00, "yearLow": 18000.00 } ``` ``` -------------------------------- ### Get OI by Participant Category Source: https://context7.com/ruchitanmay/nselib/llms.txt Returns the open interest breakdown by participant category (FII, DII, Pro, Client) for a specific trading date. ```python from nselib import derivatives df = derivatives.participant_wise_open_interest(trade_date='16-09-2024') print(df) # Columns: Client Type, Future Index Long, Future Index Short, # Option Index Call Long, Option Index Call Short, ... ``` -------------------------------- ### Import Cash Market Module Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Imports the cash_market module from the nselib library. This is necessary to access cash market data functions. ```python from nselib import cash_market ``` -------------------------------- ### Enable Logging Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Enables the built-in logger for nselib to output detailed trace logs for network requests and API responses. ```APIDOC ## nselib.enable_logging() ### Description Enables the nselib logger to output detailed network requests, API responses, or debug errors. ### Method `nselib.enable_logging` ### Parameters #### Query Parameters - **level** (logging level) - Required - The logging level to set (e.g., `logging.DEBUG`). ### Request Example ```python import nselib import logging nselib.enable_logging(level=logging.DEBUG) df = nselib.capital_market.price_volume_data('SBIN', period='1W') ``` ``` -------------------------------- ### Get NSE Trading Holiday Calendar Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Fetches the NSE trading holiday calendar for all segments. This utility function is part of the main nselib module. ```python import nselib df = nselib.trading_holiday_calendar() ``` -------------------------------- ### Fetch Live NSE Option Chain Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieves the real-time option chain for any F&O symbol. Supports 'full' mode (includes bid/ask) or 'compact' mode (fewer columns). ```python from nselib import derivatives # Full option chain for BANKNIFTY nearest expiry df_full = derivatives.nse_live_option_chain(symbol='BANKNIFTY') print(df_full[['Strike_Price', 'CALLS_OI', 'CALLS_LTP', 'PUTS_LTP', 'PUTS_OI']].head(10)) ``` ```python # Specific expiry with compact mode df_compact = derivatives.nse_live_option_chain( symbol='NIFTY', expiry_date='27-03-2025', oi_mode='compact' ) print(df_compact.columns.tolist()) # ['Fetch_Time', 'Symbol', 'Expiry_Date', 'CALLS_OI', 'CALLS_Chng_in_OI', # 'CALLS_Volume', 'CALLS_IV', 'CALLS_LTP', 'CALLS_Net_Chng', 'Strike_Price', ...] ``` -------------------------------- ### Get Equity Corporate Actions Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieves corporate action announcements (dividend, bonus, split) for equities. Can filter by F&O securities and specify a period or date range. ```python from nselib import capital_market # All corporate actions over the last 6 months df = capital_market.corporate_actions_for_equity(period='6M', fno_only=False) print(df.head()) # F&O securities only df_fno = capital_market.corporate_actions_for_equity( from_date='01-01-2024', to_date='31-03-2024', fno_only=True ) ``` -------------------------------- ### Get AMFI Monthly Report Links Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Lists available AMFI (Association of Mutual Funds in India) monthly archive report links. This function does not require any parameters. ```python links = cash_market.amfi_monthly_report_links() ``` -------------------------------- ### Get Securities in F&O Ban Period Source: https://context7.com/ruchitanmay/nselib/llms.txt Returns a list of securities currently banned from new F&O positions for a specified trading date. The output is a list of security symbols. ```python from nselib import derivatives banned = derivatives.fno_security_in_ban_period(trade_date='26-03-2025') print(f"Banned securities: {banned}") # e.g., ['BALRAMCHIN', 'GNFC', 'HINDCOPPER'] ``` -------------------------------- ### fno_index_list() Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches a list of all F&O-eligible index underlyings, including popular indices like NIFTY and BANKNIFTY, along with their respective lot sizes. ```APIDOC ## fno_index_list() ### Description Returns all F&O-eligible index underlyings (NIFTY, BANKNIFTY, etc.) with lot sizes. ### Method `capital_market.fno_index_list()` ### Parameters None ### Response Example ```json { "index": "NIFTY 50", "lotSize": 50 } ``` ``` -------------------------------- ### equity_list() Source: https://context7.com/ruchitanmay/nselib/llms.txt Returns a DataFrame of all equity instruments listed on NSE, including symbol, company name, series, listing date, and face value. ```APIDOC ## equity_list() ### Description Returns a DataFrame of all equity instruments listed on NSE with their symbol, company name, series, listing date, and face value. ### Method `capital_market.equity_list()` ### Parameters None ### Request Example ```python from nselib import capital_market df = capital_market.equity_list() print(df.shape) print(df.head()) ``` ### Response #### Success Response (pandas.DataFrame) DataFrame containing columns: 'SYMBOL', 'NAME OF COMPANY', 'SERIES', 'DATE OF LISTING', 'FACE VALUE'. #### Response Example ``` SYMBOL | NAME OF COMPANY | SERIES | DATE OF LISTING | FACE VALUE 20MICRONS | 20 Microns Limited | EQ | 06-10-2008 | 5 ``` ``` -------------------------------- ### Fetch Debt Securities Available for Trading Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches the list of debt securities available for trading on the NSE WDM segment for a specific date. Handles 'FileNotFoundError' for holidays. ```python from nselib import debt df = debt.securities_available_for_trading(trade_date='20-12-2025') print(df.head()) ``` ```python try: df = debt.securities_available_for_trading(trade_date='01-01-2026') # holiday except FileNotFoundError as e: print(f"No data: {e}") ``` -------------------------------- ### Enable and Use nselib Logging Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Enables detailed logging for nselib to help with debugging network requests and API responses. Set the logging level to DEBUG to see trace logs. ```python import nselib import logging # Enable the logger to output to the console nselib.enable_logging(level=logging.DEBUG) # Now, function calls will emit helpful trace logs df = nselib.capital_market.price_volume_data('SBIN', period='1W') ``` -------------------------------- ### Get Live Most Active F&O Underlyings Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieves the most actively traded underlying assets in the live derivatives market. The output is a DataFrame, and you can select specific columns like 'symbol', 'totalVal', 'totalVol', and 'noofContracts'. ```python from nselib import derivatives df = derivatives.live_most_active_underlying() print(df[['symbol', 'totalVal', 'totalVol', 'noofContracts']].head()) ``` -------------------------------- ### daily_volatility() Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches the NSCCL F&O daily volatility report (FOVOLT file) for a specific trading date. ```APIDOC ## daily_volatility() ### Description Fetches the NSCCL F&O daily volatility report (FOVOLT file) for a specific trading date. ### Method ```python derivatives.daily_volatility(trade_date: str) ``` ### Parameters #### Path Parameters - **trade_date** (str) - Required - The trading date in DD-MM-YYYY format. ``` -------------------------------- ### Import Derivatives Module Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Imports the derivatives module from the nselib library. This is a prerequisite for using derivative-related functions. ```python from nselib import derivatives ``` -------------------------------- ### Fetch Monthly and Daily Capital Market Data Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieve monthly or daily data for capital market segments by specifying the data type, year, and optionally month. ```python df_monthly = capital_market.business_growth_cm_segment( data_type='monthly', from_year='2025', to_year='2026' ) ``` ```python # Daily data for a specific month df_daily = capital_market.business_growth_cm_segment( data_type='daily', month='Mar', year='26' ) ``` -------------------------------- ### Get Historical Index OHLC Data Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches historical OHLC data for any NSE index, such as NIFTY 50 or NIFTY BANK, for a specified period. Allows fetching data by a predefined period or a custom date range. ```python from nselib import capital_market df = capital_market.index_data(index='NIFTY 50', from_date='01-01-2024', to_date='31-03-2024') print(df.head()) df_bank = capital_market.index_data(index='NIFTY BANK', period='6M') print(df_bank[['Date', 'Open', 'High', 'Low', 'Close']].tail()) ``` -------------------------------- ### Fetch F&O Daily Volatility Report Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches the NSCCL F&O daily volatility report (FOVOLT file) for a specific trading date. ```python from nselib import derivatives df = derivatives.daily_volatility(trade_date='17-04-2026') print(df.head()) ``` -------------------------------- ### fii_dii_trading_activity Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Retrieves FII/DII buy-sell activity data. ```APIDOC ## fii_dii_trading_activity() ### Description Retrieves FII/DII buy-sell activity data. ### Method `capital_market.fii_dii_trading_activity()` ### Parameters No parameters required. ``` -------------------------------- ### List AMFI Monthly Report Links Source: https://context7.com/ruchitanmay/nselib/llms.txt Scrapes the AMFI monthly archive page to get a DataFrame of all available report links, including month, year, file type, and URL. Useful for identifying and accessing historical reports. ```python from nselib import cash_market links_df = cash_market.amfi_monthly_report_links() print(links_df.columns.tolist()) # ['REPORT_MONTH', 'PERIOD_LABEL', 'REPORT_YEAR', 'REPORT_MONTH_NUM', 'FILE_TYPE', 'IS_REVISED', 'SOURCE_URL'] print(links_df.tail()) ``` -------------------------------- ### Get Block Deal Transactions Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches all block deal transactions for the requested period. Block deals are large negotiated trades executed on a dedicated block window. Supports fetching data by a predefined period like '1W'. ```python from nselib import capital_market df = capital_market.block_deals_data(period='1W') print(df) ``` -------------------------------- ### Import Indices Module Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Imports the indices module from the nselib library, enabling access to index-related data functions. ```python from nselib import indices ``` -------------------------------- ### short_selling_data() Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches the NSE short selling report for the given period, showing net short positions across securities. ```APIDOC ## short_selling_data() ### Description Fetches the NSE short selling report for the given period, showing net short positions across securities. ### Method `capital_market.short_selling_data(from_date: str, to_date: str)` ### Parameters #### Path Parameters None #### Query Parameters - **from_date** (str) - Required - The start date for the report (e.g., '01-06-2024'). - **to_date** (str) - Required - The end date for the report (e.g., '30-06-2024'). ### Request Example ```python from nselib import capital_market df = capital_market.short_selling_data(from_date='01-06-2024', to_date='30-06-2024') print(df) ``` ### Response #### Success Response (200) Returns a pandas DataFrame containing the short selling data. ``` -------------------------------- ### Get India VIX Historical Data Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieves historical OHLC data for India VIX (volatility index) for a specified period. Supports predefined periods like '1W' or custom date ranges using 'from_date' and 'to_date'. ```python from nselib import capital_market # Last 1 week df = capital_market.india_vix_data(period='1W') print(df.columns.tolist()) # ['Date', 'Open', 'High', 'Low', 'Close', 'PrevClose', 'Change', '%Change'] # Custom range df = capital_market.india_vix_data(from_date='01-01-2024', to_date='30-06-2024') print(df.tail()) ``` -------------------------------- ### market_watch_all_indices Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Retrieves a live snapshot of all indices. ```APIDOC ## market_watch_all_indices() ### Description Retrieves a live snapshot of all indices on the NSE. ### Method `capital_market.market_watch_all_indices()` ### Parameters No parameters required. ``` -------------------------------- ### securities_available_for_trading Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches the list of debt securities available for trading on the NSE WDM segment for a specific date. ```APIDOC ## securities_available_for_trading() ### Description Fetches the list of debt securities available for trading on the NSE WDM (Wholesale Debt Market) segment for a specific date. Raises `FileNotFoundError` if no data is available for the given date, which may occur on holidays. ### Parameters #### Query Parameters - **trade_date** (str) - Required - The date for which to fetch the securities list (e.g., '20-12-2025'). ### Request Example ```python from nselib import debt df = debt.securities_available_for_trading(trade_date='20-12-2025') print(df.head()) try: df = debt.securities_available_for_trading(trade_date='01-01-2026') # holiday except FileNotFoundError as e: print(f"No data: {e}") ``` ``` -------------------------------- ### Get Bulk Deal Transactions Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieves all reported bulk deal transactions for a specified period. Bulk deals involve trades exceeding 0.5% of total listed shares in a single transaction. Supports fetching data for a duration or a custom date range. ```python from nselib import capital_market df = capital_market.bulk_deal_data(period='1M') print(df.columns.tolist()) # ['Date', 'Symbol', 'Security Name', 'Client Name', 'Buy / Sell', 'Quantity Traded', 'Trade Price / Wt. Avg. Price'] df_range = capital_market.bulk_deal_data(from_date='01-01-2024', to_date='31-03-2024') print(df_range) ``` -------------------------------- ### fno_equity_list Source: https://github.com/ruchitanmay/nselib/blob/main/README.md Retrieves a list of F&O (Futures and Options) eligible equities along with their lot sizes. ```APIDOC ## fno_equity_list() ### Description Retrieves a list of F&O eligible equities with their lot sizes. ### Method `capital_market.fno_equity_list()` ### Parameters No parameters required. ``` -------------------------------- ### Fetch NSE Short Selling Report Source: https://context7.com/ruchitanmay/nselib/llms.txt Retrieves the NSE short selling report for a specified date range. Requires `from_date` and `to_date` parameters. ```python from nselib import capital_market df = capital_market.short_selling_data(from_date='01-06-2024', to_date='30-06-2024') print(df) ``` -------------------------------- ### Get Nifty Index Constituent Lists Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches the current constituents for major Nifty indices like NIFTY 50, NIFTY Next 50, NIFTY Midcap 150, and NIFTY Smallcap 250. Returns company name, industry, and symbol for each constituent. ```python from nselib import capital_market nifty50 = capital_market.nifty50_equity_list() print(nifty50[['Company Name', 'Industry', 'Symbol']].head()) next50 = capital_market.niftynext50_equity_list() midcap = capital_market.niftymidcap150_equity_list() smallcap = capital_market.niftysmallcap250_equity_list() ``` -------------------------------- ### nsdl_fpi_investment_activity Source: https://context7.com/ruchitanmay/nselib/llms.txt Fetches FPI (Foreign Portfolio Investor) equity and debt investment flow data for a specific reporting date from the NSDL portal. ```APIDOC ## `nsdl_fpi_investment_activity(trade_date: str)` ### Description Fetches FPI (Foreign Portfolio Investor) equity and debt investment flow data for a specific reporting date from the NSDL portal. ### Parameters #### Query Parameters - **trade_date** (str) - Required - The reporting date for which to fetch FPI investment activity (e.g., '30-10-2025'). ### Request Example ```python from nselib import cash_market df = cash_market.nsdl_fpi_investment_activity(trade_date='30-10-2025') print(df) ``` ### Response #### Success Response (200) - **fpi_investment_data** (DataFrame) - A DataFrame containing FPI investment flow data. - **REPORT_DATE** (str) - The reporting date. - **ASSET_CLASS** (str) - The asset class (Equity/Debt). - **INVESTMENT_ROUTE** (str) - The investment route. - **GROSS_PURCHASES_RS_CR** (float) - Gross purchases in Crores of Rupees. - **GROSS_SALES_RS_CR** (float) - Gross sales in Crores of Rupees. - **NET_INVESTMENT_RS_CR** (float) - Net investment in Crores of Rupees. - **NET_INVESTMENT_USD_MN** (float) - Net investment in Millions of USD. - **USD_INR_CONVERSION** (float) - USD to INR conversion rate. ```