NSEPython Documentation

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

anyway to check on delivery of stocks?
also global cues…

It is in the Bhavcopy. Filter it.

How can I get the top 20 most liquid F&O stocks from NSE?

Add the old nse_quote_meta function back.

Refer this discussion -

Also -

print(nse_quote_ltp("BANKNIFTY","latest","Fut")) this used to give error. Now it will automatically chek if it is BN or N and if You’re asking for Fut, then it will take monthly expiry.

This nse_quote_meta will give you all the information along with the LTP.

Here is the sample -

print(nse_quote_meta("BANKNIFTY","latest","Fut"))

Output:

{
   "instrumentType":"Index Futures",
   "expiryDate":"29-Jul-2021",
   "optionType":"-",
   "strikePrice":0,
   "identifier":"FUTIDXBANKNIFTY29-07-2021XX0.00",
   "openPrice":35698.95,
   "highPrice":35990,
   "lowPrice":35350,
   "closePrice":35516.15,
   "prevClose":35488.65,
   "lastPrice":35543.55,
   "change":54.900000000001455,
   "pChange":0.15469734689823775,
   "numberOfContractsTraded":132482,
   "totalTurnover":1176203.35
}

nse_most_active() Function

There are two ways -

  • Most Active Securities by Volume
  • Most Active Securities by Values

If You want the first type print(nse_most_active())

Make sure You have upgraded NSEPython to the latest version. Now cross-reference that output’s instruments with FNOs. The output is in pandas. It is easy to cross-reference a Pandas Column against a List of FNO Symbols

The full function is -

nse_most_active(type="securities",sort="value")

Here are the types -

type = "securities" (default)
type = "etf"
type = "sme"

sort = "volume"
sort = "value" (default)

I have updated my existing NSEPython but still got this error.

NameError: name ‘nse_most_active’ is not defined

How to import the function from NSEpython?

Update again following - NSEPython

Oh God. Go through - Algorithm Trading Session 1: Basics of Python and Jupyter - Unofficed

Run -

from nsepython import *

print(nse_most_active())

Brother, can you add nifty500 key to the preopen movers

It’s working after restarting the system.

But it is giving most active NSE stocks, not most active F&O stocks.

Hire a coder.

NFO is subset of NSE.

Already told how to do it.

Areh… If NSE themselves do not give NIFTY500 as parameter how can I?
Refer - nseindia.com/market-data/pre-open-market-cm-and-emerge-market

Oh…okay thank you for the reply

I can code it myself, in fact, without using this function from the option chain scrapper. Asking if that ready-made function is available because coding is not my primary job but I know how to do that. Thanks for your suggestion anyway.

Before You started replying like oversmart golden assface, acknowledge the fact that coding is not my primary fucking job either.

Despite that, I coded a function because you were seeking something and using that function it can be done. From option chain scrapper You will code most active “stonks”? Where will futures’ data will go? I am sure You’re fucked in coding! Because that needs common sense.

Now code it yourself!

Very nice done (y). I was looking for python libraries and came across yours… Just loved it!

One question though, I am looking for way to fetch Fundamental Data for any Stock and their intrinsic value. Have you built something on that too?

You tell me from where theoretically it can be fetched with proper values. [The Human Path to see it]. I will think of adding it.

One Source that I use : Indian Energy Exchange Ltd financial results and price chart - Screener
Fundamental Data points such as ROE, PE, Share ownership % breakdown, etc.

I’ll look for more examples.