Ok, so donβt hardcode strikes β you calculate them using spot price and stick gap (step size).
As each stock has different strike gaps
ATM is just nearest rounded strike
ITM/OTM = shift from ATM
Simple approach in steps:
Get latest spot price
Round to nearest strike gap β ATM
Add/subtract gap β ITM/OTM
Can also refer the example code below:
def get_strikes(spot, strike_gap):
atm = round(spot / strike_gap) * strike_gap
strikes = {
"ATM": atm,
"OTM_CE": atm + strike_gap,
"ITM_CE": atm - strike_gap,
"OTM_PE": atm - strike_gap,
"ITM_PE": atm + strike_gap,
}
return strikes
# Sample
spot_price = 19876 # Since spot price from the socket
strike_gap = 50 # NIFTY = 50, BANKNIFTY = 100
strikes = get_strikes(spot_price, strike_gap)
print(strikes)