[Feature Request] StockList API


With nseindia retiring its old website, it becomes very difficult to get all the EQ stock codes in one single url. It was earlier possible with nsetools get_stock_codes method to get all the symbols.


Now, with nseindia old website is retired and is getting confusing to check the new website and a python method for the same functionality.

Is this functionality available in nsepython module? please help with this

There seems to be a problem with either index_history method function or the response provided by NSE niftyindices website itself…sometimes somehow the index data of another index creeps into the output that is requested for a different index.

For example, check the output below: very strange to see Nifty 50 coming on top of the dataframe for Nifty metal index data.

             Index Name   INDEX_NAME HistoricalDate      OPEN      HIGH       LOW     CLOSE
2023-04-03     Nifty 50     NIFTY 50    03 Apr 2023  17427.95  17428.05  17312.75  17398.05
2023-04-03  Nifty Metal  NIFTY METAL    03 Apr 2023   5523.35   5524.30   5445.40   5477.85
2023-03-31  Nifty Metal  NIFTY METAL    31 Mar 2023   5519.55   5546.90   5475.40   5497.45
2023-03-29  Nifty Metal  NIFTY METAL    29 Mar 2023   5344.95   5484.00   5321.65   5460.20
2023-03-28  Nifty Metal  NIFTY METAL    28 Mar 2023   5398.65   5412.75   5304.45   5330.30
...                 ...          ...            ...       ...       ...       ...       ...
2022-09-29  Nifty Metal  NIFTY METAL    29 Sep 2022   5688.85   5775.35   5635.55   5645.95
2022-09-28  Nifty Metal  NIFTY METAL    28 Sep 2022   5666.15   5733.50   5603.00   5617.65
2022-09-27  Nifty Metal  Nifty Metal    27 Sep 2022   5818.65   5840.45    5647.7   5728.65
2022-09-26  Nifty Metal  Nifty Metal    26 Sep 2022   5971.25      5973   5734.55   5778.25
2022-09-23  Nifty Metal  NIFTY METAL    23 Sep 2022   6140.50   6174.45   6010.95   6027.35

It comes from this URL. ‘http://www1.nseindia.com/content/equities/EQUITY_L.csv

I did not find any URL like that in NSE main site.

But, We all use https://api.kite.trade/instruments/

No problem in the code. You can see the code. It is open source. Sometimes, indeed the responses are aladeen.

The forum website is broken though as I screwed up some stuff while migrating from Amazon S3.

:joy: yeah, I figured that, so I have kept some checks and balances to scrutinize the output before using it directly. Lol, I wish I could give this feedback to the owners of the website to make sure the responses are guaranteed to the client thread request that asked for it, what is probably happening is multi-responses to perhaps a common signature of client session which is running in a loop.

thanks. I am thinking of making use of a latest bhavcopy instead and filtering out the instruments from there which means it is authentic and kind of avoid any dependency on third parties which may or may not require authentication themselves. It would be cool to have this built into nsepython. What do you think?

pseudo code:

  • download latest bhavcopy csv
  • pandas read csv file and filter out the EQ instruments from there to get the latest EQ symbols and return the same (in lines of what is the expected out of get_stock_codes)

any suggestions or ideas on how do I get the latest bhavcopy available from the daily report archive (so I do not have to muck up a date or a holiday)

(since there are limits on number of replies by a user to the post, I am editing my previous reply)


Here is the url for the same on the new website’s archives subdomain: https://archives.nseindia.com/content/equities/EQUITY_L.csv

Hope this will help, to get the method get_stock_codes implemented into the library. So, no need to rely on download bhavcopy and then filter through it. This is a straightforward list as far as I could tell.

No need to re-invent the wheel. Its easy.

from nsepython import *
bhavcopy = get_bhavcopy(date)
eq_instruments = bhavcopy[bhavcopy["SERIES"] == "EQ"]
eq_symbols = list(eq_instruments["SYMBOL"].unique())

Please check the above reply with the link to EQUITY_L.csv. This is more appropriate as bhavcopy file contains ETFs and others also included under EQ series so it is tough to weed out etf instruments from them.

1 Like

Will add it in the next update.

Sounds good. thanks @dexter

I am able to move with the following for now

stocks_csv_url = 'https://archives.nseindia.com/content/equities/EQUITY_L.csv'
eq_list_pd = pd.read_csv(stocks_csv_url)
eq_symbols = eq_list_pd['SYMBOL'].tolist()
1 Like

Added nse_eq_symbols() function.

def nse_eq_symbols():
    eq_list_pd = pd.read_csv('https://archives.nseindia.com/content/equities/EQUITY_L.csv')
    return eq_list_pd['SYMBOL'].tolist()

1 Like

thank you @dexter appreciate it! I can now throw away my hacky stub and look forward to simply call the nse_eq_symbols method available from the package instead.

1 Like

Added Documentation → https://unofficed.com/nse-python/documentation/special/#stocklist-api