alice_blue
alice_blue copied to clipboard
use dictionary look up instead of for loop search [Improvement]
trafficstars
Improve performance on loop up.
concat with Symbol+Month+strike+call/put
Example,
"BANKNIFTYAUG31100.0CE": [ "NFO", 82505, "BANKNIFTYAUG31100.0CE", "", "2022-08-26", "25" ]
def get_instrument_for_option(self, symbol, expiry_date, strike=None,option_type='CE' , exchange='NFO'): """ get instrument for FNO """ master_con = self.get_master_contract('NFO') strike_str="{:.1f}".format(strike) symbol_u=symbol.upper() dateFormatted = expiry_date.strftime("%b").upper() key="{} {} {} {}".format(symbol_u,dateFormatted,strike_str,option_type) if (key in master_con): res=master_con[key] return res.token return
I didn't get what it is.