Square off open positions on Alice Blue using python

I have coded MIS straddle strategy with defined loss. However at 3:15 PM I would like to square off any open positions. I couldn’t get an api function for this. Could you help me on this?

Scan for all the positions.
Then, Scan for all the positions that are in MIS.

Fire, Reverse order.

Did you mean if position is on long/buy the reverse order should be sort/sell?.

Yes. and also check the order_status that if it is filled.

Sometimes market orders go to rejection. So when you close 20 trades, 2 will still stay open and skullfuck if market moves sharp.