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
There are two types –
- https://www.nseindia.com/api/?type=trading(opens new window)
- https://www.nseindia.com/api/?type=clearing(opens new window)
Here is how to use the function
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 Past Results API
Example Usage:
print(nse_past_results('JUSTDIAL'))
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.
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.
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?