Custom Functions
Unofficed is a community. So, there are lots of custom functions made to the needs of different requests and to simplify our needs.
Although some may sound silly, it is no harm to have them in the arsenal. Most of them are developed on top of the previous functions.
Illiquid Options Bid Ask
nse_optionchain_ltp() Function is the best function — it can give you both the last traded price and (when available) the bid/ask for a specific strike/expiry out of an option-chain payload. A lifesaver if you end up in illiquid options.
The source code is actively maintained and has changed shape a few times as NSE’s own option-chain payload changed underneath it (it now auto-detects both the old nested shape and the current flat shape). Rather than re-embed another source snapshot here that will go stale again, see the real, current implementation directly on GitHub: nsepython/rahu.py (search for def nse_optionchain_ltp).
nse_optionchain_ltp(payload, strikePrice, optionType, inp=0, intent="")
Originally created for Artemis. Here is the usage (strike updated to BANKNIFTY’s current realistic range — it trades around 55,000 as of this writing, not the 23,000 this page used to show):
payload=nse_optionchain_scrapper('BANKNIFTY')
print(nse_optionchain_ltp(payload,55000,"CE",0,"")) # lastPrice -- works
print(nse_optionchain_ltp(payload,55000,"CE",0,"sell")) # bid -- see note below
Output:
894.8
None
HONEST NOTE (confirmed live, 2026-10-08): intent="buy" and intent="sell" (the bid/ask lookup) currently always return None, for every strike — this is a genuine, confirmed NSE-side data gap, not a bug in this library. NSE’s current live option-chain payload carries no bid/ask order-book fields at all any more (no bidprice/askPrice, no buyPrice1/sellPrice1 on any leg). intent="" (last traded price, shown above) is unaffected and still works fine — keep using it; just don’t rely on the bid/ask branch until NSE brings that data back.
The variable inp is used in many places in this documentation. So, Let’s highlight it.
INP Variable
inp –
- inp = 0 means current expiry. It is the default.
- inp = 1 means next expiry and so on.
intent –
- If you write your intent as a sell. It will take the bid price.
- If you write your intent as a buy. It will take the ask price.
LTP is quite deceptive when you trade using ITM right?
PCR API
Here is the usage:
payload=nse_optionchain_scrapper('BANKNIFTY')
print(pcr(payload,1))
As inp is 1 here, It will show PCR of next expiry!
Expiry Details API
Originally created for Artemis, it shows the date of the expiry and number of days to expiry (DTE)
nse_expirydetails(payload,inp)
payloadis JSON input.inp(Optional) – It tells which expiry. 0 being the current. 1 being the next. Default is 0.
Usage:
payload=nse_optionchain_scrapper('BANKNIFTY')
currentExpiry,dte=nse_expirydetails(payload,1)
print(currentExpiry)
print(dte)
Output:
2021-06-10
11
inp is 1 here, It is showing the details of Expiry and PCR of next expiry! SecFNO Scarapper Function
This function is written as a complex usage of nsefetch() function.
You can check the section of Building Custom functions with nsefetch() function for usage.
