How to get option chain for Nifty using python api

kindly please let us know how to get option chain for Nifty/Bannifty using python api.

Hi @196779,

Welcome to the Upstox community!

The feature of option chain data via API is not available at the moment.

But we have noted down your suggestion and passed it on to the concerned team. Thanks!

Is this available now?

OK, Thanks for response, can you tell me tentative time to roll- out this feature . as i have seen many of broker already providing this, As we are upstox old customer of upstox we also need this feature in upstox ASAP. Delay may cause churn the customers.

Thank you, @Gaurav_Singh_Yadav for being a Upstox customer. We understand the significance of your requested feature and this is already on consideration for implementation. We will update you with a provisional timeline as soon as possible. Your patience is greatly appreciated.

OK Mr. Pradeep, Keep Posting us regarding updates, Thanks…

Is this available now???

This is picked up and currently in the development pipeline and will be available by mid-February 2024. We sincerely appreciate your patience.

Sir facility to fetch option chain in Excel or Google sheet is now available if yes then how to use it

The Option Chain API is scheduled for release and is currently in QA testing. It will be available soon, and the relevant documentation will be updated accordingly.

@Dewanshi_Ramani @Gaurav_Singh_Yadav We’ve launched our Option Chain API’s, which is comprised of two sections:

We welcome you to test them out and share your feedback.

1 Like

There is a bug in the Put/Call Option Chain endpoint. In documentation the expected output is

{
  "status": "success",
  "data": [
    {
      "expiry": "2024-02-15",
      "pcr": 1684.0638,
      "strike_price": 19500,
      "underlying_key": "NSE_INDEX|Nifty 50",
      "underlying_spot_price": 22122.25,
      "call_options": {
        "instrument_key": "NSE_FO|37263",
        "market_data": {
          "ltp": 2291.8,
          "close_price": 2259.9,
          "volume": 1200,
          "oi": 2350,
          "bid_price": 2292.85,
          "bid_qty": 50,
          "ask_price": 2302.25,
          "ask_qty": 800,
          "prev_oi": 0
        },
        "option_greeks": {
          "vega": 0,
          "theta": 0,
          "gamma": 0,
          "delta": 1,
          "iv": 0
        }
      },
      "put_options": {
        "instrument_key": "NSE_FO|37264",
        "market_data": {
          "ltp": 0.7,
          "close_price": 1.5,
          "volume": 12367100,
          "oi": 3957550,
          "bid_price": 0.65,
          "bid_qty": 382600,
          "ask_price": 0.7,
          "ask_qty": 88300,
          "prev_oi": 14400
        },
        "option_greeks": {
          "vega": 0.2278,
          "theta": -0.5966,
          "gamma": 0,
          "delta": -0.0026,
          "iv": 31.43
        }
      }
    }
  ]
}

where as the while using the endpoint I am getting the output of the smart contract endpoint.

{
  "status": "success",
  "data": [
    {
      "name": "NIFTY",
      "segment": "NSE_FO",
      "exchange": "NSE",
      "expiry": "2024-02-22",
      "weekly": true,
      "instrument_key": "NSE_FO|35549",
      "exchange_token": "35549",
      "trading_symbol": "NIFTY 19800 PE 22 FEB 24",
      "tick_size": 5.0,
      "lot_size": 50,
      "instrument_type": "PE",
      "freeze_quantity": 1800.0,
      "underlying_key": "NSE_INDEX|Nifty 50",
      "underlying_type": "INDEX",
      "underlying_symbol": "NIFTY",
      "strike_price": 19800.0,
      "minimum_lot": 50
    },
    {
      "name": "NIFTY",
      "segment": "NSE_FO",
      "exchange": "NSE",
      "expiry": "2024-02-22",
      "weekly": true,
      "instrument_key": "NSE_FO|35558",
      "exchange_token": "35558",
      "trading_symbol": "NIFTY 20050 CE 22 FEB 24",
      "tick_size": 5.0,
      "lot_size": 50,
      "instrument_type": "CE",
      "freeze_quantity": 1800.0,
      "underlying_key": "NSE_INDEX|Nifty 50",
      "underlying_type": "INDEX",
      "underlying_symbol": "NIFTY",
      "strike_price": 20050.0,
      "minimum_lot": 50
    },
    {
      "name": "NIFTY",
      "segment": "NSE_FO",
      "exchange": "NSE",
      "expiry": "2024-02-22",
      "weekly": true,
      "instrument_key": "NSE_FO|35602",
      "exchange_token": "35602",
      "trading_symbol": "NIFTY 20500 CE 22 FEB 24",
      "tick_size": 5.0,
      "lot_size": 50,
      "instrument_type": "CE",
      "freeze_quantity": 1800.0,
      "underlying_key": "NSE_INDEX|Nifty 50",
      "underlying_type": "INDEX",
      "underlying_symbol": "NIFTY",
      "strike_price": 20500.0,
      "minimum_lot": 50
    },
    {
      "name": "NIFTY",
      "segment": "NSE_FO",
      "exchange": "NSE",
      "expiry": "2024-02-22",
      "weekly": true,
      "instrument_key": "NSE_FO|35616",
      "exchange_token": "35616",
      "trading_symbol": "NIFTY 20800 CE 22 FEB 24",
      "tick_size": 5.0,
      "lot_size": 50,
      "instrument_type": "CE",
      "freeze_quantity": 1800.0,
      "underlying_key": "NSE_INDEX|Nifty 50",
      "underlying_type": "INDEX",
      "underlying_symbol": "NIFTY",
      "strike_price": 20800.0,
      "minimum_lot": 50
    },
    {
      "name": "NIFTY",
      "segment": "NSE_FO",
      "exchange": "NSE",
      "expiry": "2024-02-22",
      "weekly": true,
      "instrument_key": "NSE_FO|35619",
      "exchange_token": "35619",
      "trading_symbol": "NIFTY 20850 PE 22 FEB 24",
      "tick_size": 5.0,
      "lot_size": 50,
      "instrument_type": "PE",
      "freeze_quantity": 1800.0,
      "underlying_key": "NSE_INDEX|Nifty 50",
      "underlying_type": "INDEX",
      "underlying_symbol": "NIFTY",
      "strike_price": 20850.0,
      "minimum_lot": 50
    },
]

Either the proper endpoint is missing in the documentation or there is some sort of bug.
I reffered below documentation
Put/Call Api

@Pradeep_Jaiswar please look into this

@rushi1192 The problem has been fixed and the document has been updated. Please try again and let me know if the issue persists.

Got it now. Thanks for the help.

why dont you guys make some videos about all the new option chain documents @Pradeep_Jaiswar

@Davinci_Code, we appreciate your input. Videos series are in the pipeline, and we will inform clients as soon as they begin to roll out.

1 Like

url = ‘https://api.upstox.com/v2/option/chain/NSE_INDEX|Nifty 50/2024-02-29’
headers = {“accept”: “application/json”, “Authorization”: f’Bearer {token}'}

{‘status’: ‘error’, ‘errors’: [{‘errorCode’: ‘UDAPI100060’, ‘message’: ‘Resource not Found.’, ‘propertyPath’: None, ‘invalidValue’: None, ‘error_code’: ‘UDAPI100060’, ‘property_path’: None, ‘invalid_value’: None}]}

please help…

**need help :::: **
how did you get the option chain . provide the template in python . it would be great help. thanks

import requests

url = “https://api.upstox.com/v2/option/chain

payload={}
headers = {
‘Accept’: ‘application/json’
}

response = requests.request(“GET”, url, headers=headers, data=payload)

print(response.text)

With this request . I am not able to get any option chain data ,

I tried this :

import requests

url = “https://api.upstox.com/v2/option/contract

payload= {
‘instrument_key’: ‘NSE_FO|Nifty 50’,
‘expiry_date’: ‘2024-02-29’ # format YYYY-MM-DD
}
headers = {
‘Content-Type’: ‘application/json’,
‘Accept’: ‘application/json’,
‘Authorization’: f’Bearer {access_token}’
}

response = requests.request(“GET”, url, headers=headers, data=payload)

print(response.text)

But the output :

{“status”:“error”,“errors”:[{“errorCode”:“UDAPI100060”,“message”:“Resource not Found.”,“propertyPath”:null,“invalidValue”:null,“error_code”:“UDAPI100060”,“property_path”:null,“invalid_value”:null}]}

why is that @Pradeep_Jaiswar