That may work, but if you're cancelling existing orders, you may want to wait for the cancels to come back as cancelled before you close positions. So you would hook into OrderUpdated and wait for your cancels to close. Once all orders are cancelled, the foreach loop you have is the right way to do it. You could also use CloseAllPositions.