Hi, My code is guaranteed to execute only one buy and sale transaction (in sequence) at a time.
I am trying to get the last buy price from open position. I assumed 'buy_price' field will give me that value. But it seems as more and more trades are executed, this is actually same as average price and not the last buy_price. How should I compute the last buy price for pending quantity?
Since this is an important detail, can someone also please document the meaning of each field in positions response? Following is not my actual response, but just for the sake of reference in fields. { 'last_price': 0.55, 'tradingsymbol': 'NIFTY16SEP9800CE', 'sell_quantity': 0, 'buy_value': 0.0, 'unrealised': 0.0, 'buy_price': 0.0, 'sell_price': 0.0, 'm2m': 0.0, 'instrument_token': 11318530, 'net_sell_amount_m2m': 0.0, 'buy_quantity': 0, 'product': 'NRML', 'overnight_quantity': 0, 'exchange': 'NFO', 'sell_value': 0.0, 'net_buy_amount_m2m': 0.0, 'pnl': 0.0, 'multiplier': 1, 'average_price': 0.0, 'value': 82.5, 'close_price': 0, 'realised': 0.0, 'quantity': -150 }
Hi, There will be only one position for an instrument, even though you buy and sell multiple times. buy price will be the average price of multiple buys and sell price is the average price of multiple sells.
Let us consider a scenario wherein you bought some instrument of 10 quantity at 100, sold it and bought 10 quantity again at 101.
Your buy price will be ((100*10)+(101*10))/20 which will be equal to buy_value/quantity. If it is a long position then you will see buy price as average price else if it is short position then it will be sell price.
There will be only one position for an instrument, even though you buy and sell multiple times.
buy price will be the average price of multiple buys and sell price is the average price of multiple sells.
Your buy price will be ((100*10)+(101*10))/20 which will be equal to buy_value/quantity. If it is a long position then you will see buy price as average price else if it is short position then it will be sell price.