Beta version they are giving it as JSON which is very easy for us.
1. JSON output,
2. Directly use the JSON for your business logic.
3. Before install requests, simplejson plugin
pip install simplejson
pip install requests
http://drvijayy2k2.blogspot.com/2019/08/python-code-to-pull-nse-option.html
Code
import requests
import simplejson as json
result = requests.get ( "https://beta.nseindia.com/api/quote-derivative?symbol=NIFTY&identifier=OPTIDXNIFTY07-11-2019" );
resultJson = json.loads( result.content )
#print ( resultJson["info"] );
strikePricesDetailsJson = resultJson["stocks"]
for strikePrice in strikePricesDetailsJson:
spDetails = strikePrice["metadata"];
#print ( spDetails );
print ( spDetails["optionType"] , " : ", spDetails["strikePrice"] , " : ", spDetails["lastPrice"]);
Output
Call : 12350 : 0
Put : 11050 : 0
Call : 12750 : 0
{'metadata': {'instrumentType': 'Index Options', 'expiryDate': '28-Dec-2023', 'optionType': 'Put', 'strikePrice': 12700, 'identifier': 'OPTIDXNIFTY28-12-2023PE12700.00', 'openPrice': 0, 'highPrice': 0, 'lowPrice': 0, 'closePrice': 0, 'prevClose': 1005, 'lastPrice': 0, 'change': -1005, 'pChange': -100, 'numberOfContractsTraded': 0, 'totalTurnover': 0}, 'underlyingValue': 11998.1, 'volumeFreezeQuantity': 5001, 'marketDeptOrderBook': {'totalBuyQuantity': 225, 'totalSellQuantity': 0, 'bid': [{'price': 645.05, 'quantity': 75}, {'price': 645, 'quantity': 75}, {'price': 597, 'quantity': 75}, {'price': 0, 'quantity': 0}, {'price': 0, 'quantity': 0}], 'ask': [{'price': 0, 'quantity': 0}, {'price': 645, 'quantity': 0}, {'price': 0, 'quantity': 0}, {'price': 0, 'quantity': 0}, {'price': 0, 'quantity': 0}], 'carryOfCost': {'price': {'bestBuy': 645.05, 'bestSell': 0, 'lastPrice': 0}, 'carry': {'bestBuy': -70.5660812600072, 'bestSell': 0, 'lastPrice': 0}}, 'tradeInfo': {'tradedVolume': 0, 'value': 0, 'vmap': 0, 'premiumTurnover': 0, 'openInterest': 6, 'changeinOpenInterest': 0, 'pchangeinOpenInterest': 0, 'marketLot': 75}, 'otherInfo': {'settlementPrice': 0, 'dailyvolatility': 0.91, 'annualisedVolatility': 17.45, 'impliedVolatility': 0, 'clientWisePositionLimits': 19597661, 'marketWidePositionLimits': 0}}}