### Install nsepythonserver Package Source: https://github.com/aeron7/nsepythonserver/blob/main/examples/nse_quote_ltp()_upgrade.ipynb Install the nsepythonserver library using pip. This is a prerequisite for using the NSE data fetching functionalities. ```python !pip install nsepythonserver ``` -------------------------------- ### Install NSEPython Local Edition Source: https://github.com/aeron7/nsepythonserver/blob/main/README.md Use pip to install the Local Edition of NSEPython, suitable for Windows laptops. ```bash pip install nsepython ``` -------------------------------- ### Install NSEPython Server Edition Source: https://github.com/aeron7/nsepythonserver/blob/main/README.md Use pip to install the Server Edition of NSEPython, designed for server environments like AWS and Google Colab. ```bash pip install nsepythonserver ``` -------------------------------- ### Example Output for BANKNIFTY Future LTP Source: https://github.com/aeron7/nsepythonserver/blob/main/examples/nse_quote_ltp()_upgrade.ipynb This is an example of the output structure when fetching BANKNIFTY future LTP, showing detailed market data including bid/ask prices, trade information, and open interest. ```json { "info": { "symbol": "BANKNIFTY", "companyName": "BANKNIFTY", "identifier": "none", "activeSeries": [], "debtSeries": [], "isFNOSec": true, "isCASec": false, "isSLBSec": false, "isDebtSec": false, "isSuspended": false }, "filter": { "expiryDate": "Invalid date", "strikePrice": "" }, "underlyingValue": 45374.6, "vfq": 901, "fut_timestamp": "20-Sep-2023 13:13:28", "opt_timestamp": "20-Sep-2023 13:13:58", "stocks": [ { "metadata": { "instrumentType": "Index Options", "expiryDate": "20-Sep-2023", "optionType": "Put", "strikePrice": 45300, "identifier": "OPTIDXBANKNIFTY20-09-2023PE45300.00", "openPrice": 52.65, "highPrice": 76.5, "lowPrice": 12.8, "closePrice": 0, "prevClose": 9.4, "lastPrice": 38.55, "change": 29.15, "pChange": 310.1063829787234, "numberOfContractsTraded": 19420000, "totalTurnover": 120831.24 }, "underlyingValue": 45374.6, "volumeFreezeQuantity": 901, "marketDeptOrderBook": { "totalBuyQuantity": 11927010, "totalSellQuantity": 1344870, "bid": [ { "price": 38.4, "quantity": 570 }, { "price": 38.35, "quantity": 1365 }, { "price": 38.3, "quantity": 795 }, { "price": 38.25, "quantity": 1605 }, { "price": 38.2, "quantity": 570 } ], "ask": [ { "price": 38.5, "quantity": 30 }, { "price": 38.55, "quantity": 1455 }, { "price": 38.6, "quantity": 3645 }, { "price": 38.65, "quantity": 2055 }, { "price": 38.7, "quantity": 2355 } ], "carryOfCost": { "price": { "bestBuy": 38.4, "bestSell": 38.5, "lastPrice": 38.55 }, "carry": { "bestBuy": -128.91898942712334, "bestSell": 0, "lastPrice": 0 } }, "tradeInfo": { "tradedVolume": 19420000, "value": 120831.24, "vmap": 41.48, "premiumTurnover": 132079731.24, "openInterest": 660022, "changeinOpenInterest": 539604, "pchangeinOpenInterest": 448.10908668139314, "marketLot": 15 }, "otherInfo": { "settlementPrice": 0, "dailyvolatility": 1.04, "annualisedVolatility": 19.94, "impliedVolatility": 8.02, "clientWisePositionLimits": 0, "marketWidePositionLimits": 0 } } }, { "metadata": { "instrumentType": "Index Options", "expiryDate": "20-Sep-2023", "optionType": "Put", "strikePrice": 45400, "identifier": "OPTIDXBANKNIFTY20-09-2023PE45400.00", "openPrice": 76.5, "highPrice": 138.8, "lowPrice": 22.75, "closePrice": 0, "prevClose": 13.95, "lastPrice": 87.6, "change": 73.64999999999999, "pChange": 527.9569892473118, "numberOfContractsTraded": 17737445, "totalTurnover": 204495 }, "underlyingValue": 45374.6, "volumeFreezeQuantity": 901, "marketDeptOrderBook": { "totalBuyQuantity": 12968400, "totalSellQuantity": 950700, "bid": [ { "price": 87.5, "quantity": 30 }, { "price": 87.45, "quantity": 255 }, { "price": 87.4, "quantity": 420 }, { "price": 87.35, "quantity": 375 }, { "price": 87.3, "quantity": 780 } ], "ask": [ { "price": 87.65, "quantity": 75 }, { "price": 87.7, "quantity": 765 }, { "price": 87.75, "quantity": 945 }, { "price": 87.8, "quantity": 375 }, { "price": 87.85, "quantity": 795 } ], "carryOfCost": { "price": { "bestBuy": 87.5, "bestSell": 87.65, "lastPrice": 87.6 }, "carry": { "bestBuy": 0, "bestSell": 0, "lastPrice": 0 } }, "tradeInfo": { "tradedVolume": 17737445, "value": 204495, "vmap": 76.86, "premiumTurnover": 120996495.453405, "openInterest": 454917, "changeinOpenInterest": 363783, "pchangeinOpenInterest": 399.1737441569557, "marketLot": 15 }, "otherInfo": { "settlementPrice": 0, "dailyvolatility": 1.04, "annualisedVolatility": 19.94, "impliedVolatility": 8.46, "clientWisePositionLimits": 0, "marketWidePositionLimits": 0 } } }, { "metadata": { "instrumentType": "Index Options", "expiryDate": "20-Sep-2023", "optionType": "Put", "strikePrice": 45200, "identifier": "OPTIDXBANKNIFTY20-09-2023PE45200.00", "openPrice": 32.8, "highPrice": 42.8, "lowPrice": 7.4, "closePrice": 0, "prevClose": 7.05, "lastPrice": 17.45, "change": 10.399999999999999, "pChange": 147.51773049645388, "numberOfContractsTraded": 16192398, "totalTurnover": 53216.32 }, "underlyingValue": 45358.55, "volumeFreezeQuantity": 901, "marketDeptOrderBook": { "totalBuyQuantity": 9307575, "totalSellQuantity": 1159830, "bid": [ { "pric ``` -------------------------------- ### Get Security Price-Volume Archive Source: https://context7.com/aeron7/nsepythonserver/llms.txt Fetches historical price, volume, and delivery data for a specific security within a date range from NSE archives. Requires start date, end date, symbol, and optionally series. ```python from nsepythonserver import security_wise_archive df = security_wise_archive("01-01-2025", "30-06-2025", "RELIANCE", series="EQ") print(df.columns.tolist()) print(df.head()) ``` -------------------------------- ### Get List of All Index Names Source: https://context7.com/aeron7/nsepythonserver/llms.txt Returns a list of all available NIFTY index names. ```python from nsepythonserver import nse_get_index_list indices = nse_get_index_list() print(indices[:5]) # ['NIFTY 50', 'NIFTY NEXT 50', 'NIFTY 100', 'NIFTY 200', 'NIFTY 500'] ``` -------------------------------- ### Get Live Quote for a Specific Index Source: https://context7.com/aeron7/nsepythonserver/llms.txt Returns a dictionary containing the live quote for a specific NIFTY index by its name. ```python from nsepythonserver import nse_get_index_quote quote = nse_get_index_quote("NIFTY 50") print(quote['last']) # e.g. 24350.5 print(quote['percentChange']) # e.g. 0.35 ``` -------------------------------- ### Get Pre-Open Gainers and Losers with nse_preopen_movers Source: https://context7.com/aeron7/nsepythonserver/llms.txt Fetches pre-open market gainers and losers based on a specified percentage change filter. Returns two separate DataFrames. ```python from nsepythonserver import nse_preopen_movers gainers, losers = nse_preopen_movers(key="FO", filter=2.0) print("Top Gainers:") print(gainers[['symbol', 'pChange']].head()) print("Top Losers:") print(losers[['symbol', 'pChange']].head()) ``` -------------------------------- ### Get Top Gainers and Losers with nse_get_top_gainers/nse_get_top_losers Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves the top 5 gainers or losers from the F&O securities list. Returns DataFrames containing symbol, last price, and percentage change. ```python from nsepythonserver import nse_get_top_gainers, nse_get_top_losers gainers = nse_get_top_gainers() print(gainers[['symbol', 'lastPrice', 'pChange']]) losers = nse_get_top_losers() print(losers[['symbol', 'lastPrice', 'pChange']]) ``` -------------------------------- ### Get Current Block Deals Source: https://context7.com/aeron7/nsepythonserver/llms.txt Fetches the current day's block deal data. This function provides real-time block deal information. ```python from nsepythonserver import nse_blockdeal data = nse_blockdeal() print(data) ``` -------------------------------- ### Get F&O Lot Sizes Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves lot sizes for F&O contracts. Can fetch all lot sizes as a dictionary or pandas DataFrame, or for a specific symbol. ```python from nsepythonserver import nse_get_fno_lot_sizes # All lot sizes as dict lots = nse_get_fno_lot_sizes() print(lots['RELIANCE']) # e.g. 250 print(lots['NIFTY']) # e.g. 75 # Specific symbol reliance_lot = nse_get_fno_lot_sizes("RELIANCE") print(reliance_lot) # 250 # All as pandas DataFrame df = nse_get_fno_lot_sizes(mode="pandas") print(df.head()) ``` -------------------------------- ### Get All NSE Equity Symbols Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves a list of all equity symbols listed on the NSE. Useful for validating symbols or getting a complete list for further processing. ```python from nsepythonserver import nse_eq_symbols symbols = nse_eq_symbols() print(len(symbols)) # e.g. 1800+ print(symbols[:5]) # ['20MICRONS', '21STCENMGM', '3IINFOLTD', ...] ``` -------------------------------- ### Get FII/DII Trading Activity with nse_fiidii Source: https://context7.com/aeron7/nsepythonserver/llms.txt Returns the latest trading activity data for Foreign Institutional Investors (FII) and Domestic Institutional Investors (DII). Includes buy, sell, and net values. ```python from nsepythonserver import nse_fiidii df = nse_fiidii() print(df[['date', 'buyValue', 'sellValue', 'netValue']].head()) ``` -------------------------------- ### Get List of All F&O Eligible Symbols Source: https://context7.com/aeron7/nsepythonserver/llms.txt Returns a list of all symbols that are eligible for Futures & Options trading on the NSE, including index names. ```python from nsepythonserver import fnolist symbols = fnolist() print(symbols[:5]) ``` -------------------------------- ### Get Detailed Info for an NSE Index Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves the full data dictionary for a given NSE index using the all-indices API. ```python from nsepythonserver import index_info info = index_info("INDIA VIX") print(info['last'], info['change'], info['percentChange']) nifty_info = index_info("NIFTY 50") print(nifty_info) ``` -------------------------------- ### Get Expiry by Symbol and Type Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves the expiry date and DTE for a given symbol, filtering by instrument type ('Futures' or 'Options') and index. ```python from nsepythonserver import nse_expirydetails_by_symbol # Nearest futures expiry for RELIANCE exp_dt, dte = nse_expirydetails_by_symbol("RELIANCE", meta="Futures", i=0) print(f"Futures expiry: {exp_dt}, DTE: {dte}") # Next options expiry for NIFTY exp_dt2, dte2 = nse_expirydetails_by_symbol("NIFTY", meta="Options", i=1) print(f"Options next expiry: {exp_dt2}, DTE: {dte2}") ``` -------------------------------- ### Get Live Market Status Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves the current live market status across all NSE segments. Access specific segment details using the 'marketState' list. ```python from nsepythonserver import nse_marketStatus status = nse_marketStatus() print(status['marketState'][0]['market']) # e.g. "Capital Market" print(status['marketState'][0]['marketStatus']) # e.g. "Open" ``` -------------------------------- ### Get Past Financial Results for a Company Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves historical financial results comparison data for a specified stock symbol. Ensure the symbol is valid. ```python from nsepythonserver import nse_past_results data = nse_past_results("HDFCBANK") print(data) ``` -------------------------------- ### Get NseTools-compatible Quote using nsetools_get_quote Source: https://context7.com/aeron7/nsepythonserver/llms.txt Returns the F&O securities quote for a symbol in a format compatible with the legacy NseTools package. Requires 'nsepythonserver' to be imported. ```python from nsepythonserver import nsetools_get_quote quote = nsetools_get_quote("WIPRO") print(quote['symbol'], quote['lastPrice'], quote['pChange']) ``` -------------------------------- ### nse_eq_symbols() Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves a list of all equity symbols currently listed on the National Stock Exchange (NSE). Useful for validating symbols or getting a complete list for analysis. ```APIDOC ## nse_eq_symbols() ### Description Returns a list of all equity symbols listed on NSE. ### Usage ```python from nsepythonserver import nse_eq_symbols symbols = nse_eq_symbols() print(len(symbols)) # e.g. 1800+ print(symbols[:5]) # ['20MICRONS', '21STCENMGM', '3IINFOLTD', ...] ``` ``` -------------------------------- ### Get full contract metadata with nse_quote_meta Source: https://context7.com/aeron7/nsepythonserver/llms.txt Obtain the full contract metadata dictionary for equities or specific option contracts, using the same signature as nse_quote_ltp. Useful for retrieving details beyond just the LTP. ```python from nsepythonserver import nse_quote_meta # Full equity metadata meta = nse_quote_meta("HDFCBANK") print(meta.get('symbol'), meta.get('series')) # Full metadata for a specific option contract opt_meta = nse_quote_meta("NIFTY", "latest", "CE", 24000) print(opt_meta.get('openInterest')) print(opt_meta.get('impliedVolatility')) # Output: # HDFCBANK EQ # 1234567 # 12.45 ``` -------------------------------- ### Get universal quote with nse_quote Source: https://context7.com/aeron7/nsepythonserver/llms.txt Automatically detect and fetch the appropriate quote for either an equity or an index symbol. Optionally retrieve a specific data section like 'trade_info'. ```python from nsepythonserver import nse_quote # Equity eq_data = nse_quote("INFY") print(eq_data['priceInfo']['lastPrice']) # Index (uses derivatives endpoint) idx_data = nse_quote("NIFTY") print(idx_data['underlyingValue']) # Specific section trade_info = nse_quote("WIPRO", section="trade_info") print(trade_info) ``` -------------------------------- ### Get full equity quote with nse_eq Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieve the complete equity quote payload for a given stock symbol, including price, trade, delivery data, and metadata. This function is a direct replacement for legacy packages. ```python from nsepythonserver import nse_eq payload = nse_eq("RELIANCE") print(payload['priceInfo']['lastPrice']) # Last traded price print(payload['priceInfo']['change']) # Price change print(payload['priceInfo']['pChange']) # Percent change # Output: # 2943.5 # 12.3 # 0.42 ``` -------------------------------- ### Get Last Traded Price (LTP) with nse_quote_ltp Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieve the Last Traded Price (LTP) for equities, futures, or specific option contracts. Supports 'latest' and 'next' expiry shorthands, as well as exact date strings for options. ```python from nsepythonserver import nse_quote_ltp # Equity LTP print(nse_quote_ltp("RELIANCE")) # e.g. 2943.5 # Nearest futures LTP print(nse_quote_ltp("RELIANCE", "latest", "Fut")) # Next-expiry futures LTP print(nse_quote_ltp("RELIANCE", "next", "Fut")) # Put option LTP at specific strike, nearest expiry print(nse_quote_ltp("BANKNIFTY", "latest", "PE", 45000)) # Call option LTP at specific strike and specific expiry date print(nse_quote_ltp("BANKNIFTY", "26-Jun-2025", "CE", 45000)) # Output examples: # 2943.5 # 2951.0 # 2962.0 # 125.3 # 88.6 ``` -------------------------------- ### Download Bulk and Block Deal Archives Source: https://context7.com/aeron7/nsepythonserver/llms.txt Downloads historical bulk deals or block deals data as pandas DataFrames. Use 'get_bulkdeals()' for bulk deals and 'get_blockdeals()' for block deals. ```python from nsepythonserver import get_bulkdeals, get_blockdeals bulk = get_bulkdeals() print(bulk.head()) block = get_blockdeals() print(block.head()) ``` -------------------------------- ### get_bulkdeals() / get_blockdeals() Source: https://context7.com/aeron7/nsepythonserver/llms.txt Downloads the full bulk deals or block deals archive as a DataFrame. ```APIDOC ## get_bulkdeals() / get_blockdeals() — Bulk and block deal archives ### Description Downloads the full bulk deals or block deals archive CSV as a DataFrame. ### Request Example ```python from nsepythonserver import get_bulkdeals, get_blockdeals bulk = get_bulkdeals() print(bulk.head()) block = get_blockdeals() print(block.head()) ``` ``` -------------------------------- ### Import nsepythonserver library Source: https://context7.com/aeron7/nsepythonserver/llms.txt Import all functions from the nsepythonserver library for use in your Python scripts. ```python from nsepythonserver import * ``` -------------------------------- ### index_pe_pb_div Source: https://context7.com/aeron7/nsepythonserver/llms.txt Fetches historical Price-to-Earnings, Price-to-Book, and Dividend Yield for a NIFTY index. ```APIDOC ## index_pe_pb_div(symbol, start_date, end_date) ### Description Fetches historical Price-to-Earnings, Price-to-Book, and Dividend Yield for a NIFTY index. ### Parameters #### Path Parameters - **symbol** (string) - Required - The NIFTY index symbol (e.g., 'NIFTY 50'). - **start_date** (string) - Required - The start date for the data. - **end_date** (string) - Required - The end date for the data. ``` -------------------------------- ### Get Current India VIX Value Source: https://context7.com/aeron7/nsepythonserver/llms.txt Returns the current India VIX (volatility index) as a floating-point number. ```python from nsepythonserver import indiavix vix = indiavix() print(f"India VIX: {vix}") # Output: India VIX: 13.45 ``` -------------------------------- ### Fetch Historical Index PE, PB, Dividend Ratio Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves historical Price-to-Earnings (PE), Price-to-Book (PB), and Dividend Yield for a NIFTY index. ```python from nsepythonserver import index_pe_pb_div df = index_pe_pb_div("NIFTY 50", "01-Jan-2024", "30-Jun-2024") print(df[['Index Date', 'P/E', 'P/B', 'Div Yield']].head()) ``` -------------------------------- ### Fetch Advances and Declines Data with nse_get_advances_declines Source: https://context7.com/aeron7/nsepythonserver/llms.txt Returns advance/decline data for all F&O securities. The output includes symbol, open, last price, and various percentage change metrics. ```python from nsepythonserver import nse_get_advances_declines df = nse_get_advances_declines() print(df[['symbol', 'open', 'lastPrice', 'pChange', 'perChange365d']].head()) ``` -------------------------------- ### Download Daily Bhavcopy Source: https://context7.com/aeron7/nsepythonserver/llms.txt Downloads the end-of-day price and volume data (bhavcopy) for a specific date as a pandas DataFrame. Requires a valid date string. ```python from nsepythonserver import get_bhavcopy df = get_bhavcopy("19-06-2025") print(df[['SYMBOL', 'SERIES', 'OPEN_PRICE', 'HIGH_PRICE', 'LOW_PRICE', 'CLOSE_PRICE', 'TTL_TRD_QNTY']].head()) ``` -------------------------------- ### nse_preopen Source: https://context7.com/aeron7/nsepythonserver/llms.txt Fetches the pre-open session data for a given market segment. Can return data as a pandas DataFrame or a raw dictionary. ```APIDOC ## nse_preopen(key="NIFTY", type="pandas") — Pre-open market data Fetches the pre-open session data for a given market segment. ### Parameters - **key** (str) - The market segment key (e.g., "NIFTY", "FO"). Defaults to "NIFTY". - **type** (str) - The desired output format ("pandas" for DataFrame, "raw" for dictionary). Defaults to "pandas". ### Request Example ```python from nsepythonserver import nse_preopen # NIFTY pre-open as DataFrame df = nse_preopen(key="NIFTY", type="pandas") print(df[['symbol', 'finalPrice', 'pChange']].head()) # F&O pre-open as raw dict raw = nse_preopen(key="FO", type="raw") print(raw['data'][0]) ``` ``` -------------------------------- ### Get derivative quote with nse_fno Source: https://context7.com/aeron7/nsepythonserver/llms.txt Fetch the full derivatives quote, including futures and options data, for an F&O-eligible stock symbol. ```python from nsepythonserver import nse_fno payload = nse_fno("TATASTEEL") print(payload['stocks'][0]['metadata']['lastPrice']) # Futures last price ``` -------------------------------- ### get_beta Source: https://context7.com/aeron7/nsepythonserver/llms.txt Calculates the beta of a stock relative to a benchmark index using historical daily returns. ```APIDOC ## get_beta(symbol, days=365, symbol2="NIFTY 50") ### Description Calculates the beta of a stock relative to a benchmark index using historical daily returns. ### Parameters #### Path Parameters - **symbol** (string) - Required - The stock symbol. - **days** (integer) - Optional - The number of days for historical data. Defaults to 365. - **symbol2** (string) - Optional - The benchmark index symbol. Defaults to 'NIFTY 50'. ``` -------------------------------- ### Fetch Live Index Quotes Source: https://context7.com/aeron7/nsepythonserver/llms.txt Returns a DataFrame containing live quotes for all NIFTY indices from niftyindices.com. Includes index name, last traded price, and percentage change. ```python from nsepythonserver import nse_index df = nse_index() print(df[['indexName', 'last', 'percentChange']].head()) # Output: # indexName last percentChange # 0 NIFTY 50 24350.50 0.35 # 1 NIFTY NEXT 50 70123.00 0.21 ``` -------------------------------- ### Get NSE Holiday List Source: https://context7.com/aeron7/nsepythonserver/llms.txt Fetches the NSE holiday master for trading or clearing segments. Use the 'type' parameter to specify 'trading' or 'clearing'. ```python from nsepythonserver import nse_holidays holidays = nse_holidays(type="trading") # Iterate segment holidays for h in holidays.get("FO", [])[:3]: print(h['tradingDate'], h['description']) ``` -------------------------------- ### get_bhavcopy(date) Source: https://context7.com/aeron7/nsepythonserver/llms.txt Downloads the daily bhavcopy (end-of-day data) for a specified date. ```APIDOC ## get_bhavcopy(date) — Daily bhavcopy (end-of-day data) ### Description Downloads the full end-of-day price/volume bhavcopy for a given date as a DataFrame. ### Parameters #### Path Parameters - **date** (string) - Required - The date for which to download the bhavcopy, in DD-MM-YYYY format. ### Request Example ```python from nsepythonserver import get_bhavcopy df = get_bhavcopy("19-06-2025") print(df[['SYMBOL', 'SERIES', 'OPEN_PRICE', 'HIGH_PRICE', 'LOW_PRICE', 'CLOSE_PRICE', 'TTL_TRD_QNTY']].head()) ``` ``` -------------------------------- ### Get Expiry Date and DTE from Payload Source: https://context7.com/aeron7/nsepythonserver/llms.txt Extracts a specific expiry date and its Days To Expiry (DTE) from an option chain payload using an index. ```python from nsepythonserver import nse_optionchain_scrapper, nse_expirydetails payload = nse_optionchain_scrapper("NIFTY") expiry_date, dte = nse_expirydetails(payload, i=0) print(f"Nearest expiry: {expiry_date}, DTE: {dte}") # Output: Nearest expiry: 2025-06-26, DTE: 7 next_expiry, next_dte = nse_expirydetails(payload, i=1) print(f"Next expiry: {next_expiry}, DTE: {next_dte}") ``` -------------------------------- ### Fetch Pre-Open Market Data with nse_preopen Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves pre-open session data for a specified market segment. Supports both pandas DataFrame and raw dictionary output types. ```python from nsepythonserver import nse_preopen # NIFTY pre-open as DataFrame df = nse_preopen(key="NIFTY", type="pandas") print(df[['symbol', 'finalPrice', 'pChange']].head()) ``` ```python # F&O pre-open as raw dict raw = nse_preopen(key="FO", type="raw") print(raw['data'][0]) ``` -------------------------------- ### Get F&O Security Attribute using nse_custom_function_secfno Source: https://context7.com/aeron7/nsepythonserver/llms.txt Extracts any attribute for a given symbol from the F&O securities index list. Ensure the 'nsepythonserver' library is imported. ```python from nsepythonserver import nse_custom_function_secfno ltp = nse_custom_function_secfno("RELIANCE", attribute="lastPrice") pchange = nse_custom_function_secfno("TCS", attribute="pChange") volume = nse_custom_function_secfno("INFY", attribute="totalTradedVolume") print(ltp, pchange, volume) ``` -------------------------------- ### Get full derivatives payload with nse_quote_derivatives Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieve the complete raw NSE derivatives payload for an F&O symbol, which includes all associated futures and options contracts. ```python from nsepythonserver import nse_quote_derivatives payload = nse_quote_derivatives("NIFTY") print(payload['underlyingValue']) # Spot value of NIFTY print(len(payload['data'])) # Number of F&O contracts ``` -------------------------------- ### security_wise_archive(from_date, to_date, symbol, series) Source: https://context7.com/aeron7/nsepythonserver/llms.txt Fetches historical price, volume, and delivery data for a security from NSE archives. ```APIDOC ## security_wise_archive(from_date, to_date, symbol, series="ALL") — Security price-volume-delivery archive ### Description Fetches historical price, volume, and delivery data for a security from the NSE archives API. ### Parameters #### Path Parameters - **from_date** (string) - Required - The start date for the archive data in DD-MM-YYYY format. - **to_date** (string) - Required - The end date for the archive data in DD-MM-YYYY format. - **symbol** (string) - Required - The stock symbol for which to retrieve data. #### Query Parameters - **series** (string) - Optional - The series of the security. Defaults to "ALL". Common values include "EQ" (Equity). ### Request Example ```python from nsepythonserver import security_wise_archive df = security_wise_archive("01-01-2025", "30-06-2025", "RELIANCE", series="EQ") print(df.columns.tolist()) print(df.head()) ``` ``` -------------------------------- ### oi_chain_builder(symbol, expiry, oi_mode) Source: https://context7.com/aeron7/nsepythonserver/llms.txt Constructs a structured pandas DataFrame representing the option chain for a specified expiry date. Supports two modes: 'full' (includes bid/ask details) and 'compact' (omits bid/ask). ```APIDOC ## oi_chain_builder(symbol, expiry="latest", oi_mode="full") ### Description Builds a structured pandas DataFrame of the option chain for a given expiry. `oi_mode` can be `"full"` (with bid/ask) or `"compact"`. ### Parameters #### Path Parameters - **symbol** (string) - Required - The stock symbol for which to build the option chain. - **expiry** (string) - Optional - The expiry date for the option chain. Defaults to the latest expiry. - **oi_mode** (string) - Optional - The mode for fetching OI data. Can be `"full"` or `"compact"`. Defaults to `"full"`. ### Usage ```python from nsepythonserver import oi_chain_builder # Full OI chain for nearest expiry df, spot, timestamp = oi_chain_builder("NIFTY") print(f"Spot: {spot}, Timestamp: {timestamp}") print(df[['Strike Price', 'CALLS_OI', 'CALLS_LTP', 'PUTS_OI', 'PUTS_LTP']].head()) # Compact mode for a specific expiry df2, spot2, ts2 = oi_chain_builder("BANKNIFTY", expiry="26-Jun-2025", oi_mode="compact") print(df2.head()) # Output: # Spot: 24350.5, Timestamp: 19-Jun-2025 15:30:00 # Strike Price CALLS_OI CALLS_LTP PUTS_OI PUTS_LTP # 0 22000 123456 4.50 987654 2200.10 ``` ``` -------------------------------- ### Fetch raw NSE API data with nsefetch Source: https://context7.com/aeron7/nsepythonserver/llms.txt Use nsefetch for low-level NSE API requests with automatic cookie management. It handles session expiration and refreshes cookies as needed. The cookies are stored in cookies.txt. ```python from nsepythonserver import nsefetch # Fetch raw equity data for RELIANCE data = nsefetch('https://www.nseindia.com/api/quote-equity?symbol=RELIANCE') print(data['priceInfo']['lastPrice']) # Output: 2943.5 (live price) # Cookies are auto-managed in cookies.txt; no manual session handling needed # On first call, cookies.txt is created automatically ``` -------------------------------- ### Fetch Live Stock Quote LTP Source: https://github.com/aeron7/nsepythonserver/blob/main/examples/nse_quote_ltp()_upgrade.ipynb Use this function to get the Last Traded Price (LTP) for a given stock symbol. Ensure the symbol and type are correctly specified. ```python nse_quote_ltp("INFY", "latest", "EQ", 0) ``` -------------------------------- ### Build Option Chain DataFrame Source: https://context7.com/aeron7/nsepythonserver/llms.txt Constructs a pandas DataFrame from the option chain data for a specified expiry. Supports 'full' mode with bid/ask details or 'compact' mode. ```python from nsepythonserver import oi_chain_builder # Full OI chain for nearest expiry df, spot, timestamp = oi_chain_builder("NIFTY") print(f"Spot: {spot}, Timestamp: {timestamp}") print(df[['Strike Price', 'CALLS_OI', 'CALLS_LTP', 'PUTS_OI', 'PUTS_LTP']].head()) # Compact mode for a specific expiry df2, spot2, ts2 = oi_chain_builder("BANKNIFTY", expiry="26-Jun-2025", oi_mode="compact") print(df2.head()) # Output: # Spot: 24350.5, Timestamp: 19-Jun-2025 15:30:00 # Strike Price CALLS_OI CALLS_LTP PUTS_OI PUTS_LTP # 0 22000 123456 4.50 987654 2200.10 ``` -------------------------------- ### Calculate Stock Beta Source: https://context7.com/aeron7/nsepythonserver/llms.txt Calculates the beta of a stock relative to a benchmark index (defaulting to NIFTY 50) using historical daily returns over a specified number of days. ```python from nsepythonserver import get_beta beta = get_beta("RELIANCE", days=365, symbol2="NIFTY 50") print(f"RELIANCE Beta (1Y vs NIFTY 50): {beta}") # Output: RELIANCE Beta (1Y vs NIFTY 50): 0.823 # Alias from nsepythonserver import getbeta print(getbeta("HDFCBANK", days=252)) ``` -------------------------------- ### index_total_returns Source: https://context7.com/aeron7/nsepythonserver/llms.txt Fetches the Total Return Index (TRI) for a NIFTY index, accounting for dividends. ```APIDOC ## index_total_returns(symbol, start_date, end_date) ### Description Fetches the Total Return Index (TRI) for a NIFTY index, accounting for dividends. ### Parameters #### Path Parameters - **symbol** (string) - Required - The NIFTY index symbol (e.g., 'NIFTY 50'). - **start_date** (string) - Required - The start date for the data. - **end_date** (string) - Required - The end date for the data. ``` -------------------------------- ### Retrieve Live Large Deals with nse_largedeals Source: https://context7.com/aeron7/nsepythonserver/llms.txt Fetches today's large deals, including bulk, block, or short deals, as a pandas DataFrame. Specify the deal type using the 'mode' parameter. ```python from nsepythonserver import nse_largedeals bulk = nse_largedeals(mode="bulk_deals") print(bulk.head()) ``` ```python block = nse_largedeals(mode="block_deals") print(block.head()) ``` ```python short = nse_largedeals(mode="short_deals") print(short.head()) ``` -------------------------------- ### Get Upcoming Corporate Events with nse_events Source: https://context7.com/aeron7/nsepythonserver/llms.txt Returns a DataFrame of upcoming corporate events, including board meetings, dividends, and results dates. Displays symbol, company, purpose, and meeting date. ```python from nsepythonserver import nse_events df = nse_events() print(df[['symbol', 'company', 'purpose', 'bm_date']].head()) # Output: # symbol company purpose bm_date # 0 INFY Infosys Limited Quarterly Results 18-Jul-2025 ``` -------------------------------- ### nse_blockdeal() Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves current day's block deal data. ```APIDOC ## nse_blockdeal() — Current block deals ### Description Returns the current day's block deal data. ### Request Example ```python from nsepythonserver import nse_blockdeal data = nse_blockdeal() print(data) ``` ``` -------------------------------- ### Fetch FAO Participant Open Interest with get_fao_participant_oi Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves participant-wise open interest data for the derivatives segment on a specific date. Requires a date string in 'DD-MM-YYYY' format. ```python from nsepythonserver import get_fao_participant_oi df = get_fao_participant_oi("04-06-2025") print(df.head()) ``` -------------------------------- ### fnolist Source: https://context7.com/aeron7/nsepythonserver/llms.txt Returns a list of all symbols eligible for Futures & Options trading, including index names. ```APIDOC ## fnolist() ### Description Returns a list of all symbols eligible for Futures & Options trading, including index names. ``` -------------------------------- ### Fetch Historical Total Return Index (TRI) Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves the Total Return Index (TRI) for a NIFTY index, which accounts for reinvested dividends. ```python from nsepythonserver import index_total_returns df = index_total_returns("NIFTY 50", "01-Jan-2024", "30-Jun-2024") print(df.head()) ``` -------------------------------- ### nsefetch(payload) Source: https://context7.com/aeron7/nsepythonserver/llms.txt Low-level NSE API request with automatic cookie management for persistent session handling. ```APIDOC ## nsefetch(payload) — Low-level NSE API request with cookie management Fetches any NSE API endpoint using `curl` with persistent cookie management. Automatically refreshes cookies by visiting the NSE homepage and option-chain page when the session expires or returns invalid JSON. ### Method ```python from nsepythonserver import nsefetch # Fetch raw equity data for RELIANCE data = nsefetch('https://www.nseindia.com/api/quote-equity?symbol=RELIANCE') print(data['priceInfo']['lastPrice']) # Output: 2943.5 (live price) # Cookies are auto-managed in cookies.txt; no manual session handling needed # On first call, cookies.txt is created automatically ``` ``` -------------------------------- ### nse_marketStatus() Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves the current live market status for all segments. ```APIDOC ## nse_marketStatus() — Live market status ### Description Returns the current live market status for all segments. ### Request Example ```python from nsepythonserver import nse_marketStatus status = nse_marketStatus() print(status['marketState'][0]['market']) print(status['marketState'][0]['marketStatus']) ``` ``` -------------------------------- ### nse_preopen_movers Source: https://context7.com/aeron7/nsepythonserver/llms.txt Returns two DataFrames: pre-open gainers (pChange > filter) and losers (pChange < -filter). ```APIDOC ## nse_preopen_movers(key="FO", filter=1.5) — Pre-open gainers and losers Returns two DataFrames: pre-open gainers (pChange > filter) and losers (pChange < -filter). ### Parameters - **key** (str) - The market segment key (e.g., "FO"). Defaults to "FO". - **filter** (float) - The percentage change threshold for gainers and losers. Defaults to 1.5. ### Request Example ```python from nsepythonserver import nse_preopen_movers gainers, losers = nse_preopen_movers(key="FO", filter=2.0) print("Top Gainers:") print(gainers[['symbol', 'pChange']].head()) print("Top Losers:") print(losers[['symbol', 'pChange']].head()) ``` ``` -------------------------------- ### Calculate Put-Call Ratio (PCR) Source: https://context7.com/aeron7/nsepythonserver/llms.txt Calculates the Put-Call Ratio from an option chain payload. Requires the payload obtained from `nse_optionchain_scrapper` and an expiry index. ```python from nsepythonserver import nse_optionchain_scrapper, pcr payload = nse_optionchain_scrapper("NIFTY") ratio_0 = pcr(payload, 0) # Nearest expiry PCR ratio_1 = pcr(payload, 1) # Next expiry PCR print(f"PCR (nearest): {ratio_0:.4f}") print(f"PCR (next): {ratio_1:.4f}") # Output: # PCR (nearest): 1.2345 # PCR (next): 0.9876 ``` -------------------------------- ### Fetch Raw Option Chain Payload Source: https://context7.com/aeron7/nsepythonserver/llms.txt Fetches the complete option chain data for a given symbol. The output is a dictionary containing strike prices, expiry dates, and call/put option details. ```python from nsepythonserver import nse_optionchain_scrapper payload = nse_optionchain_scrapper("NIFTY") print(payload['underlyingValue']) # Current NIFTY spot print(payload['data'][0]) # First strike entry # Output: # 24350.5 # {'strikePrice': 22000, 'expiryDate': '26-Jun-2025', 'CE': {...}, 'PE': {...}} ``` -------------------------------- ### Fetch Corporate Financial Results with nse_results Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves corporate financial results, supporting both 'Quarterly' and 'Annual' periods for 'equities' and 'sme' segments. Returns a DataFrame of results. ```python from nsepythonserver import nse_results # Quarterly results for equities df = nse_results(index="equities", period="Quarterly") print(df.columns.tolist()) print(df.head()) ``` ```python # Annual results for SME segment sme = nse_results(index="sme", period="Annual") print(sme.head()) ``` -------------------------------- ### Calculate Black-Scholes Option Greeks and Premiums Source: https://context7.com/aeron7/nsepythonserver/llms.txt Calculates option greeks and theoretical premiums using the Black-Scholes model. If volatility (σ) is not provided, India VIX is used. Requires underlying price (S0), strike price (X), and time to expiration (t). ```python from nsepythonserver import black_scholes_dexter # NIFTY 24000 CE, 7 DTE, using live India VIX as volatility call_theta, put_theta, call_premium, put_premium, \ call_delta, put_delta, gamma, vega, call_rho, put_rho = \ black_scholes_dexter(S0=24350, X=24000, t=7) print(f"Call Premium : {call_premium:.2f}") print(f"Put Premium : {put_premium:.2f}") print(f"Call Delta : {call_delta:.4f}") print(f"Put Delta : {put_delta:.4f}") print(f"Gamma : {gamma:.6f}") print(f"Vega : {vega:.4f}") print(f"Call Theta : {call_theta:.4f}") print(f"Put Theta : {put_theta:.4f}") # With explicit volatility (20%), risk-free rate 7%, dividend yield 0% result = black_scholes_dexter(S0=24350, X=24000, t=30, σ=20, r=7, q=0) print(result) ``` -------------------------------- ### equity_history(symbol, series, start_date, end_date) Source: https://context7.com/aeron7/nsepythonserver/llms.txt Fetches historical Open, High, Low, Close, and Volume (OHLCV) data for a specified equity symbol and series. Data is retrieved in 40-day chunks to comply with NSE API limits and returned as a concatenated DataFrame, sorted with the most recent data first. ```APIDOC ## equity_history(symbol, series, start_date, end_date) ### Description Fetches historical OHLCV data for an equity in 40-day chunks (to respect NSE API limits) and returns a concatenated DataFrame sorted newest-first. ### Parameters #### Path Parameters - **symbol** (string) - Required - The equity symbol (e.g., "RELIANCE"). - **series** (string) - Required - The series type, typically "EQ" for equity. - **start_date** (string) - Required - The start date for the historical data in DD-MM-YYYY format. - **end_date** (string) - Required - The end date for the historical data in DD-MM-YYYY format. ### Usage ```python from nsepythonserver import equity_history df = equity_history("RELIANCE", "EQ", "01-01-2024", "30-06-2024") print(df.columns.tolist()) # ['CH_SYMBOL', 'CH_SERIES', 'CH_TIMESTAMP', 'CH_OPENING_PRICE', ``` ``` -------------------------------- ### Fetch Historical Options Data Source: https://context7.com/aeron7/nsepythonserver/llms.txt Retrieves historical options data, including strike price and option type. Requires specifying instrument type and expiry date. ```python # Historical options data opt_df = derivative_history( "BANKNIFTY", "01-01-2024", "31-01-2024", instrumentType="options", expiry_date="25-Jan-2024", strikePrice=46000, optionType="CE" ) print(opt_df[['FH_TIMESTAMP', 'FH_CLOSING_PRICE']].head()) ```