NSEPython Documentation

First Initialize it -

from nsepython import *

Printing Indicies -

print(indices)

The Output will show -

['NIFTY', 'NIFTYIT', 'BANKNIFTY']

1 Like

Getting the FNO List -

print(fnolist())

The Output will show -

['BANKNIFTY', 'NIFTY', 'NIFTYIT', 'ADANIENT', 'ADANIPOWER', 'AMARAJABAT', 'ACC', 'PVR', 'RAMCOCEM', 'AMBUJACEM', 'APOLLOHOSP', 'ASIANPAINT', 'AUROPHARMA', 'AXISBANK', 'BAJAJ-AUTO', 'BAJAJFINSV', 'BAJFINANCE', 'ADANIPORTS', 'BALKRISIND', 'BHARTIARTL', 'BANDHANBNK', 'BATAINDIA', 'BEL', 'BERGEPAINT', 'BHARATFORG', 'BHEL', 'BOSCHLTD', 'BRITANNIA', 'CANBK', 'CIPLA', 'COALINDIA', 'COLPAL', 'CUMMINSIND', 'DABUR', 'BANKBARODA', 'DIVISLAB', 'DRREDDY', 'EICHERMOT', 'EXIDEIND', 'FEDERALBNK', 'GAIL', 'GLENMARK', 'GRASIM', 'HAVELLS', 'HCLTECH', 'HDFCLIFE', 'HEROMOTOCO', 'HINDALCO', 'HINDPETRO', 'HINDUNILVR', 'ICICIBANK', 'ICICIPRULI', 'INDIGO', 'INDUSINDBK', 'INFY', 'ITC', 'JUBLFOOD', 'JUSTDIAL', 'KOTAKBANK', 'LICHSGFIN', 'LUPIN', 'MANAPPURAM', 'MARICO', 'MARUTI', 'BIOCON', 'CADILAHC', 'MCDOWELL-N', 'MFSL', 'MGL', 'MINDTREE', 'MOTHERSUMI', 'MRF', 'MUTHOOTFIN', 'NATIONALUM', 'NCC', 'NIITTECH', 'NMDC', 'NTPC', 'PEL', 'PETRONET', 'PFC', 'PIDILITIND', 'RBLBANK', 'RECLTD', 'SAIL', 'SBIN', 'SIEMENS', 'SRF', 'SRTRANSFIN', 'SUNTV', 'TATAPOWER', 'TECHM', 'TITAN', 'TORNTPHARM', 'TORNTPOWER', 'TVSMOTOR', 'UJJIVAN', 'ULTRACEMCO', 'UPL', 'VOLTAS', 'ASHOKLEY', 'CONCOR', 'INFRATEL', 'BPCL', 'CHOLAFIN', 'DLF', 'EQUITAS', 'ESCORTS', 'IDEA', 'JSWSTEEL', 'LT', 'GODREJCP', 'GODREJPROP', 'SBILIFE', 'HDFC', 'HDFCBANK', 'IDFCFIRSTB', 'JINDALSTEL', 'M&M', 'M&MFIN', 'UBL', 'NAUKRI', 'NESTLEIND', 'ONGC', 'PAGEIND', 'POWERGRID', 'RELIANCE', 'SHREECEM', 'SUNPHARMA', 'TATAMOTORS', 'TATASTEEL', 'CENTURYTEX', 'VEDL', 'APOLLOTYRE', 'PNB', 'TATACHEM', 'IGL', 'IOC', 'TATACONSUM', 'TCS', 'WIPRO', 'ZEEL', 'L&TFH', 'IBULHSGFIN', 'GMRINFRA']

Getting Option Chain Data -

print(nse_optionchain_scrapper('PVR'))

The Output will show a huge JSON data. You can use https://jsonformatter.org/json-viewer to navigate through the data schema.

The oi_chain_builder Function

Usage:
oi_data,ltp,crontime=oi_chain_builder(symbol,expiry,oi_mode,mode)

Inputs:

  • symbol = FNO Symbol
  • expiry = “latest” (By default) or, You can choose next expiry by typing the expiry dates like “30-Jul-2020”
  • oi_mode = “full” (By default) or “compact” (It will fetch all options info).
  • mode = “fetch” (By default) or “local” (It will not fetch the lastest data but will use the last used data stored in the system.)

Output:

  • oi_data = It will be a Pandas Dataframe.
  • ltp = LTP of the symbol
  • crontime = Data’s Updation Time as per NSE Server when fetched

Example:
oi_data, ltp, crontime = oi_chain_builder("PVR","latest","full","fetch")
or,
oi_data, ltp, crontime = oi_chain_builder("NIFTY")

it only shows “{}” when executed in powershell. Does powershell not show json?

The latter one makes a dictionary I suppose. Shows error that no such file or directory: oi_data/TATASTEEL.pickle.

Pickle is a module installed by python by default, so idk why the error.

Sometimes NSE site get crapped and genuinely give {}. That might be one reason.
Regarding Powershell, I never tried it.