Need code logic for stock options

Hi,

Need code logic for getting stock options strike price.



 

If you want to download SO data from NSE using Python code then you can follow these steps -





Step1:



1 First hit this URL with GET method:

https://www.nseindia.com/option-chain

2. It will return the HTML content, but you are more interested in the responses cookies only.

3. Save the response cookies to be used later.



Step2:


  1. For index
  • Use the response cookies from Step1 to hit this URL with GET method: https://www.nseindia.com/api/option-chain-indices?symbol=NIFTY
  • You may use any Index symbol here, like BANKNIFTY etc.
2. For stock
  • Use the response cookies from Step1 to hit this URL with GET method: https://www.nseindia.com/api/option-chain-equities?symbol=INFY
  • You may use any Stock symbol here, like VEDL etc.
3. Response will be a JSON string, you can parse it to have a dict object.
4. You can then use the list value of data key to get entire option chain as per their strike prices.
5. You can then play with this data to extract details for any strike price.
​​​​​

Thanks 

Hi Mangesh,



You can extract the strike price for an option using the instrument name. The format of the instrument name, which is a string, can vary from data provider to data provider but usually consists of the following components:



INFY23APR1140PE –> "asset name" (INFY) + "year of expiry" (23) + "month of expiry" (APR) + "strike price" (1140) + "option type" (PE)



The strike price can be extracted from this string using simple string manipulations, for example, removing the last 2 characters (CE/PE) and storing the following "n" characters, which are numbers as the strike price. This is just one way. You can extract the same using some other form too.



Hope this helps!



Thanks,

Akshay