DEV Community 👩‍💻👨‍💻

Shoeb Ahmed
Shoeb Ahmed

Posted on • Updated on

Getting NSE data using python.

Getting NSE data using python.

If anyone like coding as a hobby or they like to explore more using code, python is the best example from my point of view.

I am going to demonstrate how can we extract simple stock market data using python. So, we are going to extract the NSE (National Stock Exchange of India Ltd). So this is just a sample code of how can you use it in your application or you can explore more from this blog.

pip install nsepy
Enter fullscreen mode Exit fullscreen mode

Now I am going to extract the share of “ICICI Bank” data of 30 days ago of the current date.



After running the above code you will get the data in CSV format as shown below but the date and data will be variant.

You can explore more on this topic on: https://nsepy.xyz/

Any queries drop me a question on my LinkedIn Account page.
Shoeb Ahmed - Trainee Software Engineer - Aress Software | LinkedIn

Now for option and Bank Nifty

stock_opt = get_history(symbol="SBIN",
                        start=date(2015,1,1),
                        end=date(2015,1,10),
                        option_type="CE",
                        strike_price=300,
                        expiry_date=date(2015,1,29))

nifty_next50 = get_history(symbol="NIFTY NEXT 50",
                            start=date(2015,1,1),
                            end=date(2015,1,10),
                            index=True)

Bank_Nifty = get_history(symbol="BANKNIFTY",
                            start=date(2015,1,1),
                            end=date(2015,1,10),
                            index=True)

Enter fullscreen mode Exit fullscreen mode

Top comments (5)

Collapse
 
anbu222 profile image
Anbarasu A

Hello,

Is it possible to fetch Bank Nifty & Nifty option pricing OHLC data as well for multiple strike & Expiries.

Thank you in advance.

Collapse
 
shoeb370 profile image
Shoeb Ahmed

Yes we can see, OHLC, in given screenshot.
You can see the column names with Open, High, Low and Close in data variable,

Image description

Collapse
 
shoeb370 profile image
Shoeb Ahmed

stock_opt = get_history(symbol="SBIN",
start=date(2015,1,1),
end=date(2015,1,10),
option_type="CE",
strike_price=300,
expiry_date=date(2015,1,29))

nifty_next50 = get_history(symbol="NIFTY NEXT 50",
start=date(2015,1,1),
end=date(2015,1,10),
index=True)

Bank_Nifty = get_history(symbol="BANKNIFTY",
start=date(2015,1,1),
end=date(2015,1,10),
index=True)
Just give the name of stock name in upper case in symbol

Collapse
 
anbu222 profile image
Anbarasu A

Thank you Shoeb Ahmed for taking time and responding on this .

Collapse
 
anbu222 profile image
Anbarasu A

Hello,

Is there a way to find only tradeable liquid options for both Nifty & Bank Nifty and Also for stocks with multiple expiries ,

Looking for out put in below format

Expiry3 Expiry2 Expiry1 CE strike price PE strike price Expiry1 Expiry2 Expiry 3

LTP LTP LTP 36000 CE 36000 PE LTP LTP LTP

Thank you in advance.

Create an Account!

👀 Just want to lurk?

That's fine, you can still create an account and turn on features like 🌚 dark mode.