Hi Team,
Could you please help me build Python logic to:
- Track OHLC data for ATM ±3 strikes from the option chain
- Send notifications (Telegram alerts) when any specific strike hits a new high or new low
Additionally, please provide complete working code for:
- ATM ±5 strikes tracking(CE/PE)
- Telegram notifications for new highs/lows
Example use case:
text
NIFTY ATM = 24,000
Track strikes: 23,650, 23,700, 23,750, 24,000, 24,050, 24,100, 24,150, 24,200, 24,250, 24,300
Alert: "🚀 NEW HIGH NIFTY CE 24200: ₹125.50"
I’ve already tested the NSE option chain scraping + Telegram bot integration. Just need the complete production-ready code.
Thanks!
Hi @mahendra.beit ,
Which broker API have you been using?
I m using Dhan / kotak/ zerodha , i m ok with any solution .
Consider as Dhan and give me idea(logic) accordingly.
HI @mahendra.beit ,
Refer the below code :
# To Fetch strikes from ATM above and below
df = tsl.instrument_df
expiries = tsl.get_expiry_list(Underlying="NIFTY", exchange="INDEX")
atm = tsl.ATM_Strike_Selection(Underlying="NIFTY", Expiry= 0)
expiry = expiries[0]
target_date = pd.to_datetime(expiry).date()
filt = df[(df['SEM_EXM_EXCH_ID']== 'NSE')&(df['SEM_INSTRUMENT_NAME']=='OPTIDX')&(df['SEM_EXPIRY_FLAG']=='W')]
filt = filt[pd.to_datetime(filt['SEM_EXPIRY_DATE']).dt.date == target_date]
filt1 = filt.sort_values(by='SEM_STRIKE_PRICE', ascending=True)
filt2 = filt1[filt1['SEM_STRIKE_PRICE'] >= atm[-1]].head(5)['SEM_CUSTOM_SYMBOL'].tolist()
filt3 = filt1[filt1['SEM_STRIKE_PRICE'] < atm[-1]].tail(5)['SEM_CUSTOM_SYMBOL'].tolist()
strikes = filt2 + filt3
# Logic of checking new high and low
new_high = {}
new_low = {}
while True:
for strike in strikes:
print(f'Checking New High and Low for {strike}')
if strike not in new_high:
new_high[strike] = None
if strike not in new_low:
new_low[strike] = None
ohlc = tsl.get_historical_data(strike, 'NFO', '1')
ohlc = ohlc[pd.to_datetime(ohlc['timestamp']).dt.date == pd.Timestamp.today().date()]
if ohlc.empty:
continue
high = ohlc['high'].max()
low = ohlc['low'].min()
if new_high[strike] is None or high > new_high[strike]:
new_high[strike] = high
message = f"{strike} New HIGH updated: {high}"
print(message)
tsl.send_telegram_alert(message, receiver_chat_id="1234567890", bot_token="1234567890")
if new_low[strike] is None or low < new_low[strike]:
new_low[strike] = low
message = f"{strike} New LOW updated: {low}"
print(message)
tsl.send_telegram_alert(message, receiver_chat_id="1234567890", bot_token="1234567890")
Refer the below link that how to receive chat token and id for the telegram alert :