is this available in present API ?
also how to fetch pre-open market data?
Yes.
You want a function on getting Pre Open data?
Yes to get pre open gainers, losers.
key = "NIFTY"
key = "BANKNIFTY"
key = "SME"
key = "FO"
key = "OTHERS"
key = "ALL"
def nse_preopen(key="NIFTY"):
payload = nsefetch("https://www.nseindia.com/api/market-data-pre-open?key="+key+"")
return payload
print(nse_preopen("NIFTY"))
Now just manipulate the output, If you do something interesting, Share back. I will add this function or similar function when I update.
def nse_preopen_movers(key="FO"):
positions = nsefetch("https://www.nseindia.com/api/market-data-pre-open?key="+key+"")
idf = pd.DataFrame(positions['data'])
df = pd.json_normalize(idf['metadata'])[['symbol', 'pChange', 'lastPrice', 'totalTurnover']].dropna()
adv_dec = np.array([[positions['advances'],positions['declines'],positions['unchanged']]])
return df.loc[df['pChange'] > 1.5], df.loc[df['pChange'] < -1.5],adv_dec
preOpen_gainer, preOpen_loser, adv_dec = nse_preopen_movers()
I’m filtering pre-open gainers and losers with a 1.5% range, with advances and declines.
1 Like
Lovely.
I added the functions to the main library with certain changes. Update the main library.
Two functions added.
Command:
nse_preopen(key,type)
Variations:
key = "NIFTY" (default)
key = "BANKNIFTY"
key = "SME"
key = "FO"
key = "OTHERS"
key = "ALL"
type = "raw"
type = "pandas" (default)
Usage:
payload=nse_preopen("FO","raw")
print(payload) # It will print raw JSON
print(payload["advances"])
print(payload["declines"])
print(payload["unchanged"])
payload=nse_preopen("FO","pandas") # It will post Pandas DataFrame
1 Like
Another one is yours. Also added your name there in code. See in Github.
Usage:
nse_preopen_movers(key="FO",filter=1.5)
- key is same like just pasted above.
- filter is where you can choose how much gap up or down.
So,
gainers,movers=nse_preopen_movers("NIFTY")
print(gainers)
print(movers)
PS: I recoded this way because I desperately wanted to avoid adding a new library like numpy
. Adding library can cause error in all past installations.
1 Like