Need help! Which way do you cancel orders?

Hello,
I’m pulling my hair out over a simple thing like canceling orders.
Could someone please explain to me what’s the best way to cancel an order?

I have read the documentation, but it doesn’t help me to answer these questions.

How to detect if the opposing order has been filled? (cancel stop order if take profit filled, or vice versa)
Should I detect via websocket or REST?
A small code example would be awesome

Thank you!

When creating the stop and take profit orders, you can save both originated order ids and then listen to the websocket (https://binance-docs.github.io/apidocs/futures/en/#event-order-update) for ORDER_TRADE_UPDATE to know when one of the order ids got filled, after filling, you can use (https://binance-docs.github.io/apidocs/futures/en/#cancel-order-trade) to cancel another saved order id.