NSEPython Documentation

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'))

1 Like

Hi,

I have been using and building my own database for years on some of these APIs now, but didnt know bulk results API, events API existed. I was using

https://www.nseindia.com/api/quote-equity?symbol=KTKBANK&section=corp_info

https://www.nseindia.com/api/historical/cm/equity?symbol=PEL

Thanks a lot for sharing those APIs. I think I can simplify some of my processing with your urls.

1 Like

TypeError: cannot unpack non-iterable NoneType object
Getting this error intermittently while using the function: df, ltp, crontime = oi_builder(“NIFTY”)
need to know a way to handle this

can we make the function to retry multiple times if there is no data?? because if i keep trying Iam getting data after some 10-15 seconds

2 Likes

Is there a way to get all expiry dates with new nseindia api without having to use quote or chain api?
An api that just returns expiry dates?

Does anybody have list of all the apis provided by nseindia?

def expiry_list(symbol):
    logging.info("Getting Expiry List of: "+ symbol)
    payload = nse_optionchain_scrapper(symbol,)
    payload = pd.DataFrame({'Date':payload['records']['expiryDates']})    
    return
1 Like

I will add a try except.

why its not working on AWS Lambda …when i tried to get option chain data always showing timeout error even i provide full time limit i.e 15 min on Aws.

Mother NSE has blocked all server requests.

is there any solution for that?

CURL Method. When I get time to update ; I will update this library with that.

You can’t do this as per the SEBI circular. https://archives.nseindia.com/content/circulars/WEB45032.pdf

The SEBI mandated Website Security Policy has been enforced on the new NSE website to
protect Investor data and prevent misuse or theft of information.
 Using scripts to download information or scrapping data from NSE website is not
permitted. Hence most pages have a “Download in (.csv)” option enabled on the front
end.

They are free to file legal suit lol on a small retailer like me :stuck_out_tongue: .

Hahaha :smiley:

I tried with curl… But seems they blocked that also…

From Friday yes. Now two methods work -

Just get the cookies from Curl session

Or

Json Token using Python

I will update later.

did you try with https://alternativeto.net/software/httpie/about/

I have really no clue what is it

Adding this to main library.

Updated New Version:

Refactored the NSE’s Request Scrapper with a try-except on the days NSE makes certain problems that need access to cookies.

New functions added -

nse_quote_ltp|() Function:

print(nse_quote_ltp(“BANKNIFTY”))
It will print the price of the BankNIFTY Index.

print(nse_quote_ltp(“BANKNIFTY”,“latest”,“Fut”))
It will print the price of BankNIFTY Futures of the current expiry.

print(nse_quote_ltp(“RELIANCE”,“latest”,“Fut”))
It will print the price of Reliance Futures of the current expiry.

print(nse_quote_ltp(“RELIANCE”))
It will print the price of Reliance.

print(nse_quote_ltp(“BANKNIFTY”,“13-Aug-2020”,“PE”,21000))
print(nse_quote_ltp(“RELIANCE”,“latest”,“PE”,2300))

nsefetch() Function:

We added a new function named nsefetch() which downloads the NSE website links and parse them into JSONs automatically.

Here is how you use it -

positions = nsefetch('https://www.nseindia.com/api/equity-stockIndices?index=SECURITIES%20IN%20F%26O')
print(positions)

Just the link inside the function! That’s it.

nse_quote() Function:

It acts as a universal function towards the quote system defined using nse_eq() and nse_fno(). It will automatically give the correct scrip info.

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!

Make sure to update to the latest version.