NSEPython Documentation

The Holiday API

There are two types -
https://www.nseindia.com/api/?type=trading
https://www.nseindia.com/api/?type=clearing

Here is how to use the function

nse_holidays(type)
or, holiday_master(type)

type = trading or clearing. By default, trading will be selected.

Here is how to see the holidays of FNOs -

print(pd.json_normalize(nse_holidays()['FO']))

The Results API

nseindia.com/companies-listing/corporate-filings-financial-results

The API looks like this -

nseindia.com/api/corporates-financial-results?index=equities&period=Quarterly

index has three types:

  • equities
  • debt
  • sme

period has four types:

  • Quarterly
  • Annual
  • Half-Yearly
  • Others

Usage:

nse_results(index,period)

Default Value of index is equities and period is Quarterly in nse_results() function.

Example Usage:

nse_results()
nse_results("equities","Others")

The Event Calendar API

nseindia.com/companies-listing/corporate-filings-event-calendar

API Link: https://www.nseindia.com/api/event-calendar

Just type nse_events()

Pro Tip: You can do a cross search between FNO companies and the companies listed here.

==============

The Past Results API

nseindia.com/companies-listing/corporate-filings-financial-results-comparision
API Link: nseindia.com/api/results-comparision?symbol=JUSTDIAL

Usage print(nse_past_results('JUSTDIAL'))

2 Likes

A post was merged into an existing topic: NSEPython Discussion and Feature Request

expiry_list() Function:

Usage: print(expiry_list('RELIANCE'))

nse_optionchain_ltp() Function:

This is the best function.

def nse_optionchain_ltp(payload,strikePrice,optionType,inp=0,intent=""):
    expiryDate=payload['records']['expiryDates'][inp]
    for x in range(len(payload['records']['data'])):
      if((payload['records']['data'][x]['strikePrice']==strikePrice) & (payload['records']['data'][x]['expiryDate']==expiryDate)):
          if(intent==""): return payload['records']['data'][x][optionType]['lastPrice']
          if(intent=="sell"): return payload['records']['data'][x][optionType]['bidprice']
          if(intent=="buy"): return payload['records']['data'][x][optionType]['askPrice']

Originally created for Artemis.

Here is the usage:

payload=nse_optionchain_scrapper('BANKNIFTY')
print(nse_optionchain_ltp(payload,23000,"CE",0,"sell"))

inp -

  • inp = 0 means current expiry. It is the default.
  • inp = 1 means next expiry and so on.

intent -

  • If you write your intent as a sell. It will take the bid price.
  • If you write your intent as a buy. It will take the ask price.

LTP is quite deceptive when you trade using ITM right?

pcr() Function:

Here is the usage:

payload=nse_optionchain_scrapper('BANKNIFTY')
print(pcr(payload,1))

As inp is 1 here, It will show PCR of next expiry!

inp -

  • inp = 0 means current expiry. It is the default.
  • inp = 1 means next expiry and so on.

nse_expirydetails() Function:

Originally created for Artemis, it shows the date of the expiry and number of days to expiry (DTE)

Usage:

payload=nse_optionchain_scrapper('BANKNIFTY')
print(nse_expirydetails(payload,1))

Output:
(datetime.date(2020, 9, 17), 10)

As inp is 1 here, It is showing PCR of next expiry!

The nsefetch() function is quite powerful -

Here is a usage showing for loop to display the LTP and various of a symbol using this another URL -

Input

from nsepython import *

def nse_custom_function_secfno(symbol,attribute="lastPrice"):
    positions = nsefetch('https://www.nseindia.com/api/equity-stockIndices?index=SECURITIES%20IN%20F%26O')
    endp = len(positions['data'])
    for x in range(0, endp):
        if(positions['data'][x]['symbol']==symbol.upper()):
            return positions['data'][x][attribute]

print(nse_custom_function_secfno("Reliance"))
print(nse_custom_function_secfno("Reliance","pChange"))

Output

2094.45
5.99

So, You can see that the same LTP can be fetched in multiple ways. You can also design Python beautifully to get other attributes like pChange which shows how much percentage it is up or down that day.

The rest of the attributes can be seen from putting the output JSON in the JSON Formatter easily -

Few More Special APIs as per request -

The Block Deals API

https://www.nseindia.com/market-data/block-deal-watch

API Link: https://nseindia.com/api/block-deal

Example Usage:

print(nse_blockdeal())

The Market Status API

Although We have a function that merely checks if we are in market time but this API Endpoint comes from NSE.

API Link: https://nseindia.com/api/marketStatus

Example Usage:

print(nse_marketStatus())

The NSE Circular API

There are two APIs that fetch NSE Circular. One that truncates to the latest data and another that shows all the circulars.

Example Usage:

print(nse_circular("latest"))

This will show the NSE’s latest circulars.

API Link: https://www.nseindia.com/api/latest-circular

print(nse_circular("all"))

This will show the NSE’s all circulars.

API Link: https://www.nseindia.com/api/circulars

The FII/DII API

It fetches data of FII/DII in both Pandas and raw mode. By “raw”, it means You get the usual List format.

https://www.nseindia.com/reports/fii-dii

Example Usage:

print(nse_fiidii())

Output:

category         date buyValue sellValue netValue
0     DII **  28-May-2021  6440.88   5165.66  1275.22
1  FII/FPI *  28-May-2021  5917.71   5004.12   913.59

If You want the output in List mode directly. Use -

print(nse_fiidii("list"))

Output:

[{'category': 'DII **', 'date': '28-May-2021', 'buyValue': '6440.88', 'sellValue': '5165.66', 'netValue': '1275.22'}, {'category': 'FII/FPI *', 'date': '28-May-2021', 'buyValue': '5917.71', 'sellValue': '5004.12', 'netValue': '913.59'}]

In case Pandas throws error, It will come as output default.

NSETools Functions

The Functions are the newest/better adaptaions of the functionality of another wrapper named NSETools that is depreciated (No longer actively maintained).

Getting a Stock Quote

NSEPython already has various ways of getting Stock Quotes. However, this function is designed specifically to give output similar/same like NSETools’ nse.get_quote() function.

It only work for stocks and index that are in derivatives segement.

Before going though other fundamental APIs. We will first see how to get a quote. Assume that we want to fetch current price of Reliance Industries. The only thing we need is NSE Code for this company. The NSE stock code for Infosys is RELIANCE.

Example Usage:

print(nsetools_get_quote("reliance"))

Output:

{
   "symbol":"RELIANCE",
   "identifier":"",
   "series":"EQ",
   "open":"1990",
   "dayHigh":"2105",
   "dayLow":"1990",
   "lastPrice":"2094.45",
   "previousClose":"1976.1",
   "change":118.35,
   "pChange":5.99,
   "totalTradedVolume":26060864,
   "totalTradedValue":53878751450.88,
   "lastUpdateTime":"31-DEC-2999",
   "yearHigh":"2369.35",
   "yearLow":"1412",
   "nearWKH":11.60233819401946,
   "nearWKL":-48.33215297450424,
   "perChange365d":43.05,
   "date365dAgo":"29-May-2020",
   "chart365dPath":"https://static.nseindia.com/sparklines/365d/RELIANCE-EQ.jpg",
   "date30dAgo":"29-Apr-2021",
   "perChange30d":3.5,
   "chart30dPath":"https://static.nseindia.com/sparklines/30d/RELIANCE-EQ.jpg",
   "chartTodayPath":"https://static.nseindia.com/sparklines/today/RELIANCEEQN.jpg",
   "meta":{
      "symbol":"RELIANCE",
      "companyName":"Reliance Industries Limited",
      "industry":"REFINERIES",
      "activeSeries":[
         "EQ"
      ],
      "debtSeries":[

      ],
      "tempSuspendedSeries":[

      ],
      "isFNOSec":true,
      "isCASec":false,
      "isSLBSec":true,
      "isDebtSec":false,
      "isSuspended":false,
      "isETFSec":false,
      "isDelisted":false,
      "isin":"INE002A01018"
   }
}

And the Index Quote

You don’t always need a stock quote. At times it is just enough to know the index status. A market in general is home to many indices, in other words there are more that on index which are traded in a market.

This is true with NSE as well. This is how we will get quote for CNX NIFTY and BANK NIFTY

The Index API

It will give you output in Pandas dataframe.

Example Usage:

print(nse_index())

Output:

yearLow       last      indexName  ... indexOrder       open indexSubType
0   9,544.35  15,435.65       NIFTY 50  ...       0.00  15,421.20           bm
1  23,907.35  37,394.45  NIFTY NEXT 50  ...       1.00  37,533.00           bm
2  14,123.55  27,122.80       NIFTY IT  ...       2.00  27,238.10           sc
3  19,507.05  35,141.45     NIFTY BANK  ...       3.00  35,345.65           sc
4    14.0525    17.4025      INDIA VIX  ...     4.0000    19.9100           bm

The output is truncated because of its massive size. But You can check the name of the columns here by doing -

print(nse_index().columns.values)

The output will be -

['yearLow' 'last' 'indexName' 'yearHigh' 'previousClose' 'high'
 'indexType' 'low' 'timeVal' 'percChange' 'indexOrder' 'open'
 'indexSubType']

So, You can use all of these attributes and play with the Dataframe to make your way out.

The Index List

Updated version of get_index_list() from NSETools.

Example Usage:

print(nse_get_index_list())

Output:

['NIFTY 50', 'NIFTY NEXT 50', 'NIFTY IT', 'NIFTY BANK', 'INDIA VIX', 'NIFTY 100', 'NIFTY 500', 'NIFTY MIDCAP 100', 'NIFTY MIDCAP 50', 'NIFTY INFRA', 'NIFTY REALTY', 'NIFTY50 TR 2X LEV', 'NIFTY CONSUMPTION', 'NIFTY MNC', 'NIFTY PVT BANK', 'NIFTY100 LOWVOL30', 'NIFTY100 QUALTY30', 'NIFTY GS 11 15YR', 'NIFTY PHARMA', 'NIFTY50 PR 1X INV', 'NIFTY COMMODITIES', 'NIFTY GS COMPSITE', 'NIFTY MID LIQ 15', 'NIFTY200MOMENTM30', 'NIFTY CPSE', 'NIFTY FMCG', 'NIFTY GROWSECT 15', 'NIFTY GS 15YRPLUS', 'NIFTY MIDCAP 150', 'NIFTY SERV SECTOR', 'NIFTY100 EQL WGT', 'NIFTY50 PR 2X LEV', 'NIFTY50 VALUE 20', 'NIFTY ALPHA 50', 'NIFTY AUTO', 'NIFTY DIV OPPS 50', 'NIFTY MEDIA', 'NIFTY PSE', 'NIFTY PSU BANK', 'NIFTY50 TR 1X INV', 'NIFTY 200', 'NIFTY ALPHALOWVOL', 'NIFTY ENERGY', 'NIFTY GS 4 8YR', 'NIFTY GS 8 13YR', 'NIFTY MIDSML 400', 'NIFTY100 LIQ 15', 'NIFTY50 EQL WGT', 'NIFTY50 DIV POINT', 'NIFTY200 QUALTY30', 'NIFTY SMLCAP 50', 'NIFTY SMLCAP 100', 'NIFTY METAL', 'NIFTY FIN SERVICE', 'NIFTY SMLCAP 250', 'NIFTY GS 10YR CLN', 'NIFTY100ESGSECLDR', 'NIFTY FINSRV25 50', 'NIFTY GS 10YR', 'NIFTY500 SHARIAH', 'NIFTY50 SHARIAH', 'NIFTY LOW VOLATILITY 50', 'NIFTY HIGH BETA 50', 'NIFTY SHARIAH 25', 'NIFTY MAHINDRA GROUP', 'NIFTY TATA GROUP', 'NIFTY TATA GROUP 25% CAP', 'NIFTY ADITYA BIRLA GROUP', 'NIFTY 50 FUTURES INDEX', 'NIFTY 50 FUTURES TR INDEX', 'NIFTY 50 ARBITRAGE', 'NIFTY QUALITY LOW-VOLATILITY 30', 'NIFTY ALPHA QUALITY LOW-VOLATILITY 30', 'NIFTY ALPHA QUALITY VALUE LOW-VOLATILITY 30', 'NIFTY LARGEMIDCAP 250', 'NIFTY SME EMERGE', 'NIFTY100 ESG', 'NIFTY100 ENHANCED ESG', 'NIFTY500 VALUE 50', 'NIFTY100 ALPHA 30', 'NIFTY MIDCAP150 QUALITY 50', 'NIFTY OIL & GAS', 'NIFTY CONSUMER DURABLES', 'NIFTY HEALTHCARE INDEX', 'NIFTY500 MULTICAP 50:25:25', 'NIFTY50 USD', 'NIFTY 1D RATE INDEX', 'NIFTY 10 YEAR SDL INDEX', 'NIFTY BHARAT BOND INDEX - APRIL 2023', 'NIFTY BHARAT BOND INDEX - APRIL 2030', 'NIFTY BHARAT BOND INDEX - APRIL 2025', 'NIFTY BHARAT BOND INDEX - APRIL 2031']

The Index Quote API

Updated version of get_index_quote() from NSETools.

Pick one of the index codes from the above list and use it as follows. For example let’s find index quote for “Nifty Bank”.

Example Usage:

print(get_index_quote("nifty bank"))

Output:

{
   "yearLow":"19,507.05",
   "last":"35,141.45",
   "indexName":"NIFTY BANK",
   "yearHigh":"37,708.75",
   "previousClose":"35,095.05",
   "high":"35,436.65",
   "indexType":"eq",
   "low":"34,977.20",
   "timeVal":"May 28, 2021 15:33:36",
   "percChange":"0.13",
   "indexOrder":"3.00",
   "open":"35,345.65",
   "indexSubType":"sc"
}

Advances Declines

Updated version of get_advances_declines() from NSETools.

Advances Declines is a very important feature which, in a brief snapshot, tells you the story of a trading day for the given index.

It containes the number of rising stocks, falling stocks and unchanged stocks in a given trading day, per index.

The following API would return the list of dictionaries containing stats for every index.

Usage:

nse_get_advances_declines(mode)

mode has two values.

  • The default value is pandas. It will return in Pandas DataFrame.
  • Other one is list. It will return in List.

If in any case, The Pandas Output ends in error, It will automagically give you output in List.

Example Usage:

print(nse_get_advances_declines())

Output:

symbol  ...                                               meta
0     RELIANCE  ...  {'symbol': 'RELIANCE', 'companyName': 'Relianc...
1        L&TFH  ...  {'symbol': 'L&TFH', 'companyName': 'L&T Financ...
2        CANBK  ...  {'symbol': 'CANBK', 'companyName': 'Canara Ban...
3      HDFCAMC  ...  {'symbol': 'HDFCAMC', 'companyName': 'HDFC Ass...
4       M&MFIN  ...  {'symbol': 'M&MFIN', 'companyName': 'Mahindra ...
..         ...  ...                                                ...
151        BEL  ...  {'symbol': 'BEL', 'companyName': 'Bharat Elect...
152        UBL  ...  {'symbol': 'UBL', 'companyName': 'United Brewe...
153        MGL  ...  {'symbol': 'MGL', 'companyName': 'Mahanagar Ga...
154  SUNPHARMA  ...  {'symbol': 'SUNPHARMA', 'companyName': 'Sun Ph...
155   TVSMOTOR  ...  {'symbol': 'TVSMOTOR', 'companyName': 'TVS Mot...

The output is truncated because of its massive size.

Top Losers & Gainers

Updated version of get_top_gainers() and get_top_losers() from NSETools.

The following two APIs provides list of top losing and gaining stocks for the last trading session.

Example Usage:

print(nse_get_top_gainers())

Similarly, For the Top Losers, the function is -

print(mse_get_top_losers())

The output will be on Pandas Dataframe with 5 stocks.

Getting Lot Sizes

Updated version of get_fno_lot_sizes() from NSETools. This is where it gets interesting. Few more functionalities are added here.

Example 1

print(nse_get_fno_lot_sizes("adaniports"))

or,

print(nse_get_fno_lot_sizes("adaniports","list"))

Output:

1250

It will output the lot size of AdaniPorts in the current month.

This function works perfectly with stocks but can break with indexes because NSE often change their Data Structure.

Definition

This function works in two methods. One is using List and Another one is usuing Pandas. You can see the definition here -

def nse_get_fno_lot_sizes(symbol="all",mode="list"):
  • Symbol can be all (that’s default) or any symbol name.
  • Mode can be list (that’s default) or pandas.

::: warning
all, list, pandas are case sensitive. The Symbol names are not case sensitive.
:::

Here are example outputs of other variations -

Example 2

print(nse_get_fno_lot_sizes("adaniports","pandas"))

Output:

UNDERLYING                            SYMBOL      ...  JUN-25       DEC-25     
5  ADANI PORT & SEZ LTD                  ADANIPORTS  ...                          

The output is truncated because of its massive size. It is actually Pandas DataFrame with all expiries as it’s column name in a sorted manner.

You can follow this tutorial to work with the Pandas Column Names.

Example 3

print(nse_get_fno_lot_sizes())

Output:

{'BANKNIFTY': 25, 'FINNIFTY': 40, 'NIFTY': 75, 'AUROPHARMA': 650, 'ADANIPORTS': 1250, 'AARTIIND': 425, 'ALKEM': 200, 'AMARAJABAT': 1000, 'APLLTD': 550, 'APOLLOHOSP': 250, 'APOLLOTYRE': 2500, 'ASHOKLEY': 4500, 'ASIANPAINT': 300, 'AUBANK': 500, 'CADILAHC': 2200, 'AXISBANK': 1200, 'BAJAJ-AUTO': 250, 'BAJAJFINSV': 125, 'BERGEPAINT': 1100, 'BAJFINANCE': 125, 'BALKRISIND': 400, 'BANDHANBNK': 1800, 'BEL': 3800, 'BIOCON': 2300, 'BHARATFORG': 1500, 'BHARTIARTL': 1851, 'BHEL': 10500, 'DEEPAKNTR': 500, 'BRITANNIA': 200, 'CHOLAFIN': 1250, 'COALINDIA': 4200, 'COFORGE': 375, 'DIVISLAB': 200, 'CONCOR': 1563, 'FEDERALBNK': 10000, 'DABUR': 1250, 'HCLTECH': 700, 'DLF': 3300, 'EICHERMOT': 350, 'ESCORTS': 550, 'EXIDEIND': 3600, 'GAIL': 6100, 'GLENMARK': 1150, 'GODREJCP': 1000, 'GODREJPROP': 650, 'GRANULES': 1550, 'GRASIM': 475, 'GUJGASLTD': 1250, 'M&MFIN': 4000, 'HAVELLS': 500, 'HDFC': 300, 'HDFCAMC': 200, 'HDFCBANK': 550, 'HINDALCO': 2150, 'HINDPETRO': 2700, 'HINDUNILVR': 300, 'IBULHSGFIN': 3100, 'ICICIBANK': 1375, 'ICICIGI': 425, 'IDFCFIRSTB': 9500, 'INDIGO': 500, 'IRCTC': 325, 'ITC': 3200, 'JINDALSTEL': 2500, 'SAIL': 9500, 'JSWSTEEL': 1350, 'JUBLFOOD': 250, 'KOTAKBANK': 400, 'LALPATHLAB': 250, 'LICHSGFIN': 2000, 'LT': 575, 'LTI': 150, 'LTTS': 200, 'SUNTV': 1500, 'LUPIN': 850, 'M&M': 700, 'MANAPPURAM': 6000, 'WIPRO': 1600, 'MCDOWELL-N': 1250, 'MFSL': 650, 'MINDTREE': 400, 'MOTHERSUMI': 3500, 'MPHASIS': 325, 'MUTHOOTFIN': 750, 'NAM-INDIA': 1600, 'NATIONALUM': 17000, 'NAUKRI': 125, 'NESTLEIND': 50, 'ADANIENT': 1000, 'NMDC': 6700, 'NTPC': 5700, 'PAGEIND': 30, 'PETRONET': 3000, 'PFC': 6200, 'PFIZER': 125, 'PIDILITIND': 500, 'PIIND': 250, 'POWERGRID': 4000, 'PVR': 407, 'RAMCOCEM': 850, 'RECLTD': 6000, 'SBILIFE': 750, 'SHREECEM': 25, 'SRTRANSFIN': 400, 'SUNPHARMA': 1400, 'TATACHEM': 1000, 'TATACONSUM': 1350, 'TATAMOTORS': 2850, 'CUB': 3100, 'TATAPOWER': 6750, 'TATASTEEL': 850, 'ICICIPRULI': 1500, 'TECHM': 600, 'TITAN': 375, 'TORNTPHARM': 250, 'TORNTPOWER': 1500, 'TVSMOTOR': 1400, 'UBL': 700, 'MARICO': 2000, 'CIPLA': 650, 'UPL': 1300, 'VOLTAS': 500, 'ZEEL': 3000, 'ACC': 500, 'NAVINFLUOR': 225, 'SRF': 125, 'AMBUJACEM': 3000, 'BOSCHLTD': 50, 'INFY': 600, 'L&TFH': 8924, 'BANKBARODA': 11700, 'BATAINDIA': 550, 'BPCL': 1800, 'ONGC': 7700, 'COLPAL': 350, 'VEDL': 3100, 'CUMMINSIND': 600, 'DRREDDY': 125, 'HDFCLIFE': 1100, 'IGL': 1375, 'INDUSTOWER': 2800, 'IOC': 6500, 'MARUTI': 100, 'TRENT': 725, 'MGL': 600, 'MRF': 10, 'PEL': 275, 'RELIANCE': 250, 'SBIN': 1500, 'SIEMENS': 275, 'TCS': 300, 'ULTRACEMCO': 100, 'CANBK': 5400, 'HEROMOTOCO': 300, 'PNB': 16000, 'GMRINFRA': 22500, 'IDEA': 70000, 'INDUSINDBK': 900, 'RBLBANK': 2900}

This gives all the lotsize of current month’s symbols in a Python List.

Example 4

print(nse_get_fno_lot_sizes("all","pandas"))

Output:

UNDERLYING                            SYMBOL      ...  JUN-25       DEC-25     
0    NIFTY BANK                            BANKNIFTY   ...                          
1    NIFTY FINANCIAL SERVICES              FINNIFTY    ...                          
2    NIFTY 50                              NIFTY       ...  75           75         
3    Derivatives on Individual Securities  Symbol      ...                          
4    AUROBINDO PHARMA LTD                  AUROPHARMA  ...                          
..                                    ...         ...  ...          ...          ...
155  PUNJAB NATIONAL BANK                  PNB         ...                          
156  GMR INFRASTRUCTURE LTD.               GMRINFRA    ...                          
157  VODAFONE IDEA LIMITED                 IDEA        ...                          
158  INDUSIND BANK LIMITED                 INDUSINDBK  ...                          
159  RBL BANK LIMITED                      RBLBANK     ...                          

The output is truncated because of its massive size. It is actually Pandas DataFrame with all expiries as it’s column name in a sorted manner.

Please update it to its latest version using

pip install --upgrade nsepython

You can also see the Documentation in a new version at https://aeron7.github.io/nsepython/

Things have been made in a hurry, So if there is any problem or mistake, Please notify me.

Documentations -

The Documentations that are written here will be updated to the main site of NSEPython after a significant time.

Upgraded the nse_quote_ltp() function.

Extended the usage of “next” variable -

print(nse_quote_ltp("RELIANCE"))
print(nse_quote_ltp("RELIANCE","latest","Fut"))
print(nse_quote_ltp("RELIANCE","next","Fut"))
print(nse_quote_ltp("BANKNIFTY","latest","PE",32000))
print(nse_quote_ltp("BANKNIFTY","next","PE",32000))
print(nse_quote_ltp("BANKNIFTY","10-Jun-2021","PE",32000))
print(nse_quote_ltp("BANKNIFTY","17-Jun-2021","PE",32000))
print(nse_quote_ltp("RELIANCE","latest","PE",2300))
print(nse_quote_ltp("RELIANCE","next","PE",2300))

Extended the expiry_list() variable -

print(expiry_list("RELIANCE","list"))

It will output as List Format.

['24-Jun-2021', '29-Jul-2021', '26-Aug-2021']

Getting the value of India VIX Using Python

Command:

indiavix()

Output:

14.715

Getting the value of Index Info

Usage:

index_info(index)

Example:

print(index_info("INDIA VIX"))

Output:

{'key': 'BROAD MARKET INDICES', 'index': 'INDIA VIX', 'indexSymbol': 'INDIA VIX', 'last': 14.715, 'variation': 0.61, 'percentChange': 3.95, 'open': 14.1025, 'high': 15.3075, 'low': 13.74, 'previousClose': 14.1025, 'yearHigh': 35.3125, 'yearLow': 11.945, 'pe': '', 'pb': '', 'dy': '', 'perChange365d': -54.25, 'date365dAgo': '12-Jun-2020', 'chart365dPath': 'https://static.nseindia.com/sparklines/365d/INDIA-VIX.jpg', 'date30dAgo': '14-May-2021', 'perChange30d': -30.42, 'chart30dPath': 'https://static.nseindia.com/sparklines/30d/INDIA-VIX.jpg', 'chartTodayPath': 'https://static.nseindia.com/sparklines/today/INDIA-VIX.jpg', 'previousDay': 14.1025, 'oneWeekAgo': 15.225, 'oneMonthAgo': 20.2675, 'oneYearAgo': 30.8225}

Example:

print(index_info("NIFTY 50"))

Output:

{'key': 'BROAD MARKET INDICES', 'index': 'NIFTY 50', 'indexSymbol': 'NIFTY 50', 'last': 15811.85, 'variation': 12.5, 'percentChange': 0.08, 'open': 15791.4, 'high': 15823.05, 'low': 15606.5, 'previousClose': 15799.35, 'yearHigh': 15835.55, 'yearLow': 10072.65, 'pe': '29.32', 'pb': '4.46', 'dy': '1.2', 'declines': '25', 'advances': '25', 'unchanged': '0', 'perChange365d': 58.42, 'date365dAgo': '12-Jun-2020', 'chart365dPath': 'https://static.nseindia.com/sparklines/365d/NIFTY-50.jpg', 'date30dAgo': '14-May-2021', 'perChange30d': 7.64, 'chart30dPath': 'https://static.nseindia.com/sparklines/30d/NIFTY-50.jpg', 'chartTodayPath': 'https://static.nseindia.com/sparklines/today/NIFTY-50.jpg', 'previousDay': 15799.35, 'oneWeekAgo': 15740.1, 'oneMonthAgo': 14677.8, 'oneYearAgo': 9972.9}

Option Premium Calculator Using Black Scholes Model:

Inputs in Black-Scholes Option Pricing Model Formula

  • S0 = underlying price
  • X = strike price
  • σ = volatility
  • r = continuously compounded risk-free interest rate
  • q = continuously compounded dividend yield
  • t = time to expiration
  • td = number of trading days.

Usage:

black_scholes_dexter(S0,X,t,σ="",r=10,q=0.0,td=365)

Default Value:

For,

  • σ = Volatility = India VIX has been taken. Keep it blank and it will automatically use India Vix’s latest value.
  • r = 10% (As per NSE Website, it is fixed.)
  • q = 0.00% (Assumed No Dividend)
  • td = Zerodha uses 365 in their calculator. You can use anything you want.

Usage:

S0 = 34950.60
X = 35000.00
σ = 14.72
t = 3
call_theta,put_theta,call_premium,put_premium,call_delta,put_delta,gamma,vega,call_rho,put_rho=black_scholes_dexter(S0,X,t,σ="",r=10,q=0.0,td=365)
print(call_theta)
print(put_theta)
print(call_premium)
print(put_premium)
print(call_delta)
print(put_delta)
print(gamma)
print(vega)
print(call_rho)
print(put_rho)

Output:

-35.57594968706057
-25.994786756764814
175.92468507293597
196.56938065246504
0.4850057898780081
-0.514994210121992
0.0008543132102275919
12.621618527502404
1.378793315723619
-1.495555563365108

Equity History:

Syntax:
equity_history(symbol,series,start_date,end_date)

Example:

symbol = "SBIN"
series = "EQ"
start_date = "08-06-2021"
end_date ="14-06-2021"
print(equity_history(symbol,series,start_date,end_date))

Output:

                        _id CH_SYMBOL CH_SERIES CH_MARKET_TYPE  \
0  60c744e8fa749200099709a1      SBIN        EQ              N   
1  60c3505b99ad6d0008be9c68      SBIN        EQ              N   
2  60c1fefe81433a00081e9a8d      SBIN        EQ              N   
3  60c0ad631318bc0008009871      SBIN        EQ              N   
4  60bf5be2d2265400080d7d9b      SBIN        EQ              N   

   CH_TRADE_HIGH_PRICE  CH_TRADE_LOW_PRICE  CH_OPENING_PRICE  \
0               432.45              416.70            427.00   
1               435.50              425.25            434.85   
2               433.30              422.40            424.90   
3               432.30              418.20            427.50   
4               432.50              424.00            432.25   

   CH_CLOSING_PRICE  CH_LAST_TRADED_PRICE  CH_PREVIOUS_CLS_PRICE  \
0            430.35                430.00                 429.60   
1            429.60                429.40                 432.25   
2            432.25                432.40                 421.45   
3            421.45                421.95                 427.20   
4            427.20                427.40                 432.25   

   CH_TOT_TRADED_QTY  CH_TOT_TRADED_VAL  CH_52WEEK_HIGH_PRICE  \
0           30106015       1.279312e+10                441.95   
1           26831924       1.153870e+10                441.95   
2           27397712       1.174471e+10                441.95   
3           27784834       1.185249e+10                441.95   
4           31113823       1.330030e+10                441.95   

   CH_52WEEK_LOW_PRICE  CH_TOTAL_TRADES       CH_ISIN CH_TIMESTAMP  \
0               169.25           279081  INE062A01020   2021-06-14   
1               169.25           211915  INE062A01020   2021-06-11   
2               169.25           211924  INE062A01020   2021-06-10   
3               169.25           241080  INE062A01020   2021-06-09   
4               169.25           247824  INE062A01020   2021-06-08   

                  TIMESTAMP                 createdAt  \
0  2021-06-13T18:30:00.000Z  2021-06-14T12:00:40.201Z   
1  2021-06-10T18:30:00.000Z  2021-06-11T12:00:27.251Z   
2  2021-06-09T18:30:00.000Z  2021-06-10T12:01:02.131Z   
3  2021-06-08T18:30:00.000Z  2021-06-09T12:00:35.995Z   
4  2021-06-07T18:30:00.000Z  2021-06-08T12:00:34.187Z   

                  updatedAt  __v    VWAP   mTIMESTAMP  
0  2021-06-14T12:00:40.201Z    0  424.94  14-Jun-2021  
1  2021-06-11T12:00:27.251Z    0  430.04  11-Jun-2021  
2  2021-06-10T12:01:02.131Z    0  428.67  10-Jun-2021  
3  2021-06-09T12:00:35.995Z    0  426.58  09-Jun-2021  
4  2021-06-08T12:00:34.187Z    0  427.47  08-Jun-2021  

Derivative History:

Syntax:

derivative_history(symbol,start_date,end_date,instrumentType,expiry_date,strikePrice="",optionType="")

Example:

symbol = "SBIN"
start_date = "15-05-2021"
end_date ="15-06-2021"
instrumentType = "options"
expiry_date ="24-Jun-2021"
strikePrice = 300
optionType="PE"
print(derivative_history(symbol,start_date,end_date,instrumentType,expiry_date,strikePrice,optionType))

The Strike Price and Option Type can be given when the instrument type is Options. They are not mandatory.

Output:


                        _id FH_INSTRUMENT FH_SYMBOL FH_EXPIRY_DT  \
0  60c755447984ddf3843dc745        OPTSTK      SBIN  24-Jun-2021   
1  60c35b6d7984ddf38457d4a9        OPTSTK      SBIN  24-Jun-2021   
2  60c211e67984ddf38439b427        OPTSTK      SBIN  24-Jun-2021   
3  60c0baf27984ddf38458bfe4        OPTSTK      SBIN  24-Jun-2021   

  FH_STRIKE_PRICE FH_OPTION_TYPE FH_MARKET_TYPE FH_OPENING_PRICE  \
0          300.00             PE              N             0.25   
1          300.00             PE              N             0.25   
2          300.00             PE              N             0.35   
3          300.00             PE              N             0.30   

  FH_TRADE_HIGH_PRICE FH_TRADE_LOW_PRICE FH_CLOSING_PRICE  \
0                0.30               0.20             0.25   
1                0.30               0.20             0.25   
2                0.35               0.20             0.25   
3                0.35               0.25             0.35   

  FH_LAST_TRADED_PRICE FH_PREV_CLS FH_SETTLE_PRICE FH_TOT_TRADED_QTY  \
0                 0.20        0.25            0.25            117000   
1                 0.25        0.25            0.25             48000   
2                 0.20        0.35            0.25             34500   
3                 0.35        0.30            0.35            111000   

  FH_TOT_TRADED_VAL FH_OPEN_INT FH_CHANGE_IN_OI FH_MARKET_LOT FH_TIMESTAMP  \
0       35128125.00      756000       -54000.00          1500  14-Jun-2021   
1       14411700.00      810000            0.00          1500  11-Jun-2021   
2       10359075.00      810000        -7500.00          1500  10-Jun-2021   
3       33332175.00      817500        -3000.00          1500  09-Jun-2021   

                  TIMESTAMP  CALCULATED_PREMIUM_VAL  
0  2021-06-13T18:30:00.000Z                   28125  
1  2021-06-10T18:30:00.000Z                   11700  
2  2021-06-09T18:30:00.000Z                    9075  
3  2021-06-08T18:30:00.000Z                   32175  

Expiry History:

Syntax:
expiry_history(symbol,start_date="",end_date="")

It means start_date and end_date is not mandatory.

Usage:

symbol = "SBIN"
start_date = "15-05-2020"
end_date ="15-06-2021"

print(expiry_history(symbol,start_date,end_date))
print(expiry_history(symbol,start_date))
print(expiry_history(symbol))

Output:

['28-May-2020', '25-Jun-2020', '30-Jul-2020', '27-Aug-2020', '24-Sep-2020', '29-Oct-2020', '26-Nov-2020', '31-Dec-2020', '28-Jan-2021', '25-Feb-2021', '25-Mar-2021', '29-Apr-2021', '27-May-2021', '24-Jun-2021', '29-Jul-2021', '26-Aug-2021']

['28-May-2020', '25-Jun-2020', '30-Jul-2020', '27-Aug-2020', '24-Sep-2020', '29-Oct-2020', '26-Nov-2020', '31-Dec-2020', '28-Jan-2021', '25-Feb-2021', '25-Mar-2021', '29-Apr-2021', '27-May-2021', '24-Jun-2021', '29-Jul-2021', '26-Aug-2021']

['27-May-2021', '24-Jun-2021', '29-Jul-2021', '26-Aug-2021']

As You see the end_date has no meaning when the start_date is given.