Special Functions

These are very unusual functions which is first time having python wrapper on them.

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(opens new window)

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 variable inp is used in many places in this documentation. So, Let’s highlight it.

The Holiday API

				
					nse_holidays(type)

				
			

or,

				
					nse_holidays(type)

				
			

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

Here is how to see the holidays of FNOs –

				
					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 Event Calendar API

Example Usage:

				
					nse_events()

				
			

TIP

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

The Block Deals API

				
					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.

The Beta API

Beta is a coefficient is a measure of its volatility over time compared to a market benchmark. Market benchmark has a beta of 1. Shortly, if volatility is 1.5 it means it is 50% more volatile than the market.

You can read here about more details on the construction and working of this API here – How to find the beta of Indian stocks using Python? 

Syntax:

				
					get_beta(symbol,days=365,symbol2="NIFTY 50")
				
			
  • symbol – The stock/index of whose beta has to be checked.
  • days – Time period of comparison. It’s optional with a default value of 365.
  • symbol2 – The stock/index against which beta has to be checked. It’s optional with a default value of NIFTY 50.

Example 1:

This will run a for loop on all FNO stocks and breaks the loop on first stock’s output.

				
					for x in fnolist():
    try:
        print(x+" : "+str(get_beta(x,255)))
        break
        #Remove break if you want to print whole list
    except:
        pass
				
			

Output:

				
					TORNTPHARM : -0.168

				
			

Example 2:

  • The first function is checking NIFTY’s beta against NIFTY Bank.
  • The second function is checking NIFTY Bank’s beta against NIFTY
				
					#NIFTY Against NIFTY Bank
x = "NIFTY 50"
print(x+" : "+str(get_beta(x,255,"NIFTY BANK")))

#NIFTY Bank Against NIFTY
x = "NIFTY BANK"
print(x+" : "+str(get_beta(x,255)))
				
			

Output:

				
					NIFTY 50 : 0.55
NIFTY BANK : 1.395
				
			

Note – We used 255 as Number of Days because it is globally assumed that, there are 255 trading days. For near-term correlation, feel free to change the values.

The NSE PreOpen API

Command:

				
					nse_preopen(key,type)
				
			

Variations:

				
					key = "NIFTY" (default)
key = "BANKNIFTY"
key = "SME"
key = "FO"
key = "OTHERS"
key = "ALL"

type = "raw"
type = "pandas" (default)
				
			

Example 1:

				
					payload=nse_preopen("FO","raw")
print(payload) # It will print raw JSON
print(payload["advances"])
print(payload["declines"])
print(payload["unchanged"])
				
			

Example 2:​

				
					payload=nse_preopen("FO","pandas") # It will post Pandas DataFrame

				
			

The NSE PreOpen Movers API

Command:

				
					nse_preopen_movers(key="FO",filter=1.5)

				
			
  • key is the same as just pasted above in the NSE Pre openc function.
  • filter is where you can choose how much gap up or down.

Usage:

				
					gainers,movers=nse_preopen_movers("NIFTY")
print(gainers)
print(movers)
				
			

This function is coded to avoid the usage of numpy library. You can read about this discussion here. 

The NSE Most Active API

Command:

				
					nse_most_active(type="securities",sort="value")
				
			

Variations:

				
					type = "securities" (default)
type = "etf"
type = "sme"

sort = "volume"
sort = "value" (default)
				
			

Let’s take the example with the default type which is securities. You can find two things with this API in that case –

  • Most Active Securities by Volume
  • Most Active Securities by Values

This function is coded as a helper function to the query of How can I get the top 20 most liquid F&O stocks from NSE?

The StockList API

Command:

				
					nse_eq_symbols()
				
			

It will paste the entire codes of all equities in a single list. Right now (22-08-2023), It will post 1898 such codes. This function is coded as a helper function to the query of [Feature Request] StockList API

The NSE FNO Pariticipant Wise OI API

Command:

				
					get_fao_participant_oi(date)

				
			

The  date should in a string format. Here you can see an example –

Example Usage:

				
					get_fao_participant_oi("04-06-2021")

				
			

It will give the Participant wise Open Interest in that Date above. The output will look like – 

				
						Participant wise Open Interest (no. of contracts) in Equity Derivatives as on Jun 04,2021	Unnamed: 1	Unnamed: 2	Unnamed: 3	Unnamed: 4	Unnamed: 5	Unnamed: 6	Unnamed: 7	Unnamed: 8	Unnamed: 9	Unnamed: 10	Unnamed: 11	Unnamed: 12	Unnamed: 13	Unnamed: 14
0	Client Type	Future Index Long	Future Index Short	Future Stock Long	Future Stock Short\t	Option Index Call Long	Option Index Put Long	Option Index Call Short	Option Index Put Short	Option Stock Call Long	Option Stock Put Long	Option Stock Call Short	Option Stock Put Short	Total Long Contracts\t	Total Short Contracts
1	Client	115751	150820	1067753	165524	983422	884125	1006084	1087839	726845	226208	425543	323856	4004104	3159666
2	DII	2176	41572	33248	1082528	267	44771	0	0	0	0	49490	0	80462	1173590
3	FII	99389	21814	686884	686197	250553	316276	161235	169809	51329	58603	89957	46531	1463034	1175543
4	Pro	19346	22456	232887	86523	321284	342464	388207	329988	157826	213394	371010	127818	1287201	1326002
5	TOTAL	236662	236662	2020772	2020772	1555526	1587636	1555526	1587636	936000	498205	936000	498205	6834801	6834801
				
			

This function is coded as a helper function to the query of [Feature Request] NSE FNO Participant Wise OI

Join The Conversation?