2

I am using NSEPY API and I would like to list out the stocks which are included in nifty 50 indice.

I am getting history data for the individual stocks but not getting nifty 50 stocks (totally 50 stocks). I want to retrieve it .

import nsepy
from nsepy import get_history
from datetime import date
data = get_history(symbol="IOC", start=date(2017,1,1), end=date(2019,2,15))
data[['Close']].plot()

I want the results for 50 stocks but I am getting results for specific stick which I have given in symbol

Kavikayal
  • 143
  • 4
  • 14

1 Answers1

6

According to the NSEpy documentation, you don't have any method to list the companies from the index using the API.

However, you can download a csv that contains the 50 companies list here.

To read the file in Python and list the companies, using Pandas, the code is:

import pandas as pd
import io
import requests
url = 'https://www.nseindia.com/content/indices/ind_nifty50list.csv'
s = requests.get(url).content
df = pd.read_csv(io.StringIO(s.decode('utf-8')))
df.Symbol
>>> 0     ADANIPORTS
>>> 1     ASIANPAINT
>>> 2       AXISBANK
>>> 3     BAJAJ-AUTO
>>> 4     BAJFINANCE
>>> 5     BAJAJFINSV
>>> 6           BPCL
>>> 7     BHARTIARTL
>>> 8       INFRATEL
>>> 9          CIPLA
>>> 10     COALINDIA
>>> 11       DRREDDY
>>> 12     EICHERMOT
>>> 13          GAIL
>>> 14        GRASIM
>>> 15       HCLTECH
>>> 16      HDFCBANK
>>> 17    HEROMOTOCO
>>> 18      HINDALCO
>>> 19     HINDPETRO
>>> 20    HINDUNILVR
>>> 21          HDFC
>>> 22           ITC
>>> 23     ICICIBANK
>>> 24    IBULHSGFIN
>>> 25           IOC
>>> 26    INDUSINDBK
>>> 27          INFY
>>> 28      JSWSTEEL
>>> 29     KOTAKBANK
>>> 30            LT
>>> 31           M&M
>>> 32        MARUTI
>>> 33          NTPC
>>> 34          ONGC
>>> 35     POWERGRID
>>> 36      RELIANCE
>>> 37          SBIN
>>> 38     SUNPHARMA
>>> 39           TCS
>>> 40    TATAMOTORS
>>> 41     TATASTEEL
>>> 42         TECHM
>>> 43         TITAN
>>> 44           UPL
>>> 45    ULTRACEMCO
>>> 46          VEDL
>>> 47         WIPRO
>>> 48       YESBANK
>>> 49          ZEEL
>>> Name: Symbol, dtype: object
Daniel Labbe
  • 1,979
  • 3
  • 15
  • 20
  • Does this answer address your question, @ganga? – Daniel Labbe Feb 19 '19 at 19:33
  • Hi @ganga, I'm glad to know that it helped you in some way. Please, accept and upvote my answer if you think it worths! :) – Daniel Labbe Mar 15 '19 at 10:25
  • 4
    Apparently they've changed their website. I'm not used to follow the NSE, I've just provided this answer. Regardless, after searching on Google, the new link seems to be https://www.niftyindices.com/IndexConstituent/ind_nifty50list.csv – Daniel Labbe May 22 '20 at 13:49
  • 3
    Thanks. the alternative link is: https://archives.nseindia.com/content/indices/ind_nifty50list.csv – Sandeep Sharma May 22 '20 at 15:35