Yes, so thereβs no direct API that gives you βstrike gapβ.
The one way to do that calculate it from available strikes from the any source like script master file.
So, the simple idea is Strike gap = difference between consecutive strikes
Can understand with simple steps:
Fetch option chain / instruments
Take available strikes
Sort them
Find difference
Can also refer below code:
def get_strike_gap(strikes):
strikes = sorted(set(strikes))
if len(strikes) < 2:
return None
gaps = [strikes[i+1] - strikes[i] for i in range(len(strikes)-1)]
# Most common gap
gap = min(gaps)
return gap
# Sample - Inplace of this have the stricks from instrument/option chain
strikes = [19800, 19850, 19900, 19950, 20000]
gap = get_strike_gap(strikes)
print("Strike Gap:", gap)