So, you can find it from the instrument list provided by broker.
Root idea is that broker gives the full instrument data (CSV/list).
We can filter it based on symbol, Strick, expire, option type (CE/PE).
So, the logic is simple we will select the most common Strick gap.
Below is the code you can refer:
def find_option(instruments, name, strike, option_type):
filtered = []
for ins in instruments:
if (
ins["name"] == name and
ins["instrument_type"] == option_type and
ins["strike"] == strike
):
filtered.append(ins)
if not filtered:
return None
# pick nearest expiry
filtered.sort(key=lambda x: x["expiry"])
return filtered[0]
# Sample instrument data
instruments = [
{"name": "NIFTY", "strike": 19900, "instrument_type": "CE", "expiry": "2026-04-30", "token": 111},
{"name": "NIFTY", "strike": 19900, "instrument_type": "CE", "expiry": "2026-05-07", "token": 222},
]
result = find_option(instruments, "NIFTY", 19900, "CE")
print(result)