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
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?
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)
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.
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.