NSE India API Live Analysis Variations Index Gainers in Python
Follow the Instructions from the Video then go for the Code Input:
import json
import pandas as pd
with open('gain.json','r') as f:
data=json.load(f)
categories=['NIFTY', 'BANKNIFTY','NIFTYNEXT50','SecGtr20','SecLwr20','FOSec','allSec']
df=pd.concat([pd.DataFrame(data[cat]['data'])[['symbol','ltp']] for cat in categories if cat in data])
df_sorted=df.sort_values('ltp').reset_index(drop=True)
print(df_sorted.to_string(index=False))
Read NSE Gainers Data Directly from NSE India API
Follow the Instructions from the Video then go for the Code Input:
import requests
import pandas as pd
url='https://www.nseindia.com/api/live-analysis-variations?index=gainers'
headers={
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebkit/537.36',
'Accept-Language' : 'en-US, en; q=0.9'
}
response=requests.get(url,headers=headers)
data=response.json()
categories=['FOSec']
df=pd.concat([pd.DataFrame(data[cat]['data'])[['symbol','ltp']] for cat in categories if cat in data])
df_sorted=df.sort_values('ltp').reset_index(drop=True)
print(df_sorted.to_string(index=False))