I want to send orders on 2 legs and either both of them should be filled or none Here, the two orders are on different instruments.
As your one order is dependent on others. You need to handle this at your end. Place the first IOC order, check it's status then place the subsequent dependent order.
So the case of self trading does not arise.