Fetching Stock Data From Cloud

I was a regular user of NSEpy, it’s a great library, but recently I observed that while it worked fine on my local machine, it was not able to fetch any data when used from cloud. I tried AWS, Google colab and GCP but this behaviour looked consistent.

What’s happening

If you ping www1.nseindia.com from your local machine, it shows IP address -, But if you ping from your virtual machine, it shows IP address - So NSE is redirecting traffic from cloud to another ip and apparently it is not returning any results on http request.

How to solve this problem using Jugaad Data

Install Jugaad Data as per documentation.

Here’s a small snippet of code showing how to fetch data -

from jugaad_data import JugaadData
from datetime import date

z = JugaadData()
z.base_url = ""
z.ssl_verify = False

j = JugaadData()
symbol = "RELIANCE"
index = "NIFTY 50"
from_date = date(2019,1,3)
to_date = date(2020,1,10)

stock_df = j.stock_history(symbol, from_date, to_date)

index_df = j.index_history(index, from_date, to_date)

You will get an SSL warning, but at least it works for now.