Hi everyone,
I’m working on integrating the Upstox API into a Python application and running into a persistent issue when trying to retrieve option contracts/expiries for the Nifty 50 Index.
I would appreciate it if anyone who has successfully implemented this call could point out what I might be missing, or if there is a known versioning/scope issue.
1. Goal
I am trying to fetch the list of available option contracts (the option chain or expiry list) for the Nifty 50 Index.
2. Implementation Details
-
Language/SDK: Python (using
requestsand/or the official Upstox Python SDK wrappers) -
Authentication: Successful (access token is generated and works for other basic calls, like profile details).
-
Index Key Used:
NSE_INDEX|Nifty 50
3. The Problem
Based on the official documentation, I am trying to use the GET /option/contract endpoint, but the request fails.
A. Original Error (Observed in local logs):
My initial attempts were hitting a different endpoint (possibly old/internal), which resulted in a failure before the call was fully formed:
Code snippet
DEBUG: Fetching expiries using URL: https://api-v2.upstox.com/v2/market-quote/instruments/expiries with key: NSE_INDEX|Nifty 50
...
127.0.0.1 - - [08/Oct/2025 22:21:19] "GET /get_master_contract?index=NIFTY_50 HTTP/1.1" 404 -
B. Current Error (When targeting the documented endpoint):
When I explicitly use the correct, documented endpoint for option contracts (/v2/option/contract), I receive an API error response:
Request URL Pattern: https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050
API Response Status & Body:
-
HTTP Status Code:
127.0.0.1 - - [08/Oct/2025 22:20:06] “GET / HTTP/1.1” 200 -127.0.0.1 - - [08/Oct/2025 22:20:07] “GET /favicon.ico HTTP/1.1” 404 -
127.0.0.1 - - [08/Oct/2025 22:20:08] “GET /login HTTP/1.1” 302 -
127.0.0.1 - - [08/Oct/2025 22:21:15] “GET /callback?code=yqHgZ_ HTTP/1.1” 302 -
127.0.0.1 - - [08/Oct/2025 22:21:15] “GET /dashboard HTTP/1.1” 200 -
DEBUG: Fetching expiries using URL: https://api-v2.upstox.com/v2/market-quote/instruments/expiries with key: NSE_INDEX|Nifty 50
127.0.0.1 - - [08/Oct/2025 22:21:19] “GET /get_master_contract?index=NIFTY_50 HTTP/1.1” 404 -
-
Error Body:
[The JSON block for the 401 error above.]
4. Steps Taken & Verification
-
Instrument Key: Confirmed that
NSE_INDEX|Nifty 50is the correct, case-sensitive key for the Nifty 50 Index itself, as confirmed by Upstox support and the instrument master CSV. -
Instrument File Check: I have the latest
complete.csvfile, and confirmed the index key format. -
Endpoint Change: Switched from the possibly internal
/expiriesendpoint to the public/option/contractendpoint.
5. My Questions to the Community
-
Is the
GET /v2/option/contractendpoint the definitively correct and currently active way to retrieve all option expiries for a major index like Nifty 50? -
If you are using this API, are there any specific access token scopes (beyond basic market data) required to hit the
/option/contractendpoint? Is it common to receive a401 Unauthorizedor400 Bad Requestif a specific scope is missing? -
Has anyone experienced an issue where the correct instrument key (
NSE_INDEX|Nifty 50) still fails and had to use a different token/key for the index?
Any guidance is greatly appreciated! Thank you for your time.
Prashant
