Python get atm from ltp

 def ATM_CE_AND_PE_COMBIMED(ltp,symbol):

    try:
monthlyexp = credentials_dict.get('monthlyexp')
monthlyexp = datetime.strptime(monthlyexp, "%d-%m-%Y")
monthlyexp = monthlyexp.strftime("%Y-%m-%d")
pf = pd.read_csv("Instruments.csv")
filtered_df = pf[(pf['expiry'] == monthlyexp) & (pf['instrument_type'] == 'CE') & (pf["name"]==symbol)]
if not filtered_df.empty:
filtered_df["strike_diff"] = abs(
filtered_df["strike"] - ltp)
min_diff_row = filtered_df.loc[filtered_df['strike_diff'].idxmin()]
strike=int(min_diff_row["strike"])
cesymname=min_diff_row["tradingsymbol"]
pesymname = cesymname.rsplit('CE', 1)[0] + 'PE'

ce_ltp=Zerodha_Integration.get_ltp_option(cesymname)
pe_ltp=Zerodha_Integration.get_ltp_option(pesymname)
com=ce_ltp+pe_ltp

return int(com)

Comments

Popular posts from this blog

MQL5 : Add time to current time in mins

MQL5 : Get current trading session