Comment on Kite Connect APIs for programmatic access
Yeah, this has caused problems for me even.
I would suggest that for any existing trade it should be first checked if any existing square-off orders are there or not, if it is there two options
1. Prompt the user that a square-off already exits for his order,
2. Take the next square-off order as well then from the two whichever gets executed first take it and at the same time discard the pending orders associated it the trade. (As happens with a bracket order)
I would suggest the second one is better.