Child instrument details

Does these lines of code work in algobulls python build to get last traded price and buying price of option instrument

child_instrument_ltp =
entry_price = self.get_entered_strike_price(child_instrument)

Hi @Kiran_Thomas ,

To get the last traded price:

ltp =

To get the buying price / entry price after the order is placed:

entry_price = order.entry_price


what if i want to make exit decisions based on child instrument price rather than main instrument price ,

Hi @Kiran_Thomas ,

For the strategy_select_instruments_for_exit() method, the instruments bucket will have the instruments on which orders have been placed.

For options, this means child instruments, since the order was placed on them.

The line:
ltp =
will work if you pass a child instrument to the get_ltp() method.

Hope this helps.


what if in strategy_select_instruments_for_exit() method i also need ltp of the base instrument for another condition for exit

Hi @Kiran_Thomas ,

Just set up a simple map using basic python.

Here is a code snippet:

base_instrument_nifty_bank = 'NIFTY BANK'
child_instrument_nifty_bank = 'BANKNIFTY01NOV2340300CE'
instrument_mapper = {}

def map_instrument(base_instrument, child_instrument):
  instrument_mapper[child_instrument] = base_instrument
def get_base_instrument(child_instrument):
  return instrument_mapper.get(child_instrument)    # get will return None, so we can manage errors accordingly

print(get_base_instrument(child_instrument=child_instrument_nifty_bank))    # will give None
map_instrument(base_instrument=base_instrument_nifty_bank, child_instrument=child_instrument_nifty_bank)
print(get_base_instrument(child_instrument=child_instrument_nifty_bank))    # will give base instrument

In the entry methods of your strategy, use map_instrument() to save your mapping.

In the exit methods of your strategy, use get_base_instrument() to retrieve your mapped base instrument.

You can use this base instrument to get the ltp now.
ltp =

You can try the above code snippet on any compiler. Here’s one.

Hope this helps.


1 Like