Hi @Hardik
I faced this issue on 28/08/2024
I would politely differ with you here, this should not be intended way of positions API as per documentation and nomenclature.
Once the position has been squared off/closed 'buyAvg’: , ‘costPrice’: , ‘buyQty’: , ‘sellAvg’: , ‘sellQty’, ‘net qty’ should be reset to zero and ‘positionType’ to CLOSED.
And the ‘dayBuyQty’: , ‘daySellQty’: , ‘dayBuyValue’: , ‘daySellValue’: should be updated as per CLOSED position.
This can be comprehended from the nomenclature as well as the documentation
Now, the net qty is correctly reset to 0 once the position is closed and the positionType is also correctly set to CLOSED .
If it would have not been the case that why would we need ‘dayBuyQty’: , ‘daySellQty’: , ‘dayBuyValue’: , ‘daySellValue’:
And as per documentation too is clearly stated that
‘dayBuyQty’: Quantities bought today
‘daySellQty’: Quantities sold today
‘dayBuyValue’: Value of quantities bought today
‘daySellValue’: Value of quantities sold today
Now, going as per your reply the values/calculations both ‘buyQty‘ and ‘dayBuyQty’ would be same.
and also the values/calculations for ‘sellQty’ and ‘daySellQty’ would be same.
Which should not be as per documentation snippet attached above and as per nomenclature.
Let me give you an example from a trading perspective:
Suppose you buy the 51000 CE option at 10:30 AM for Rs. 100 with a quantity of 50, and then again at 10:31 AM for Rs. 120 with a quantity of 50. The ‘buyAvg’ should be 110, and the ‘net qty’ should be 100, which is correct.
If you close the entire position at 10:35 AM by selling all 100 quantities at Rs. 130, the ‘net qty’ becomes 0, and the ‘positionType’ changes to CLOSED.
Now, if you buy the same 51000 CE option again at 12:10 PM for Rs. 200 with a quantity of 100, the correct ‘buyAvg’ should be 200, and the ‘net qty’ should be 100. for this current open position
But instead, the ‘buyAvg’ when fetched by using dhan.getpositions shows as 155, which is wrong (as it is including the previous closed position), the correct and true avgprice for current open position is 200 .
This is why we have separate fields like ‘dayBuyQty,’ ‘daySellQty,’ ‘dayBuyValue,’ and ‘daySellValue.’
Awaiting your response
Adding to this by Edit:
i went through other brokers api too specifically zerodh
there too they have similar nomenclature as yours and have very clearly stated that
average_price
float64 -----> Average price at which the net position quantity was acquired
Important to note here the word NET POSITION
and also they have similar nomenclature for the day
day_buy_quantity": , “day_buy_price”: ,“day_buy_value”: , “day_sell_quantity”:, “day_sell_price”: ,“day_sell_value”:
There is a reason to have a separate field for Day
Looking forward to your response.