How to use an API to Fetch Nifty 50 Stock Data
To use the NSE API (or similar APIs) to fetch Nifty 50 stock data. Here’s an example in Python:
import requests
import pandas as pd
# URL for NSE's stock data (for reference)
url = "https://www.nseindia.com/api/equity-stockIndices?index=NIFTY%2050"
# Make a request
headers = {
"User-Agent": "Mozilla/5.0"
}
response = requests.get(url, headers=headers)
data = response.json()
# Extract stock data
stocks = data["data"]
df = pd.DataFrame(stocks)
# Save to Excel
df.to_excel("Nifty_50_Stocks.xlsx", index=False)
Members Online 0
Newest Member: apitech