I already have the code to send orders to FTX (with TP and SL).
But since TP and SL are not 'attached' to the position and the positions are aggregated it makes a mess with orders.
I have seen people suggest cancelling all orders before opening a new one: https://stackoverflow.com/a/69371405/6014804 Which is a nice idea but unusable in my case.
I regularly have several current positions at the same time.
So I can't cancel all pending orders as soon as I open a new position. Because some orders are still active and relevant.
The only option I guess is to fetch closed orders/positions (when a TP / SL is hit) to individually cancel the remaining order to this position (the opposite order, either TP / SL). Right?
Even if it's the right solution, I don't know how to do that. Has anyone ever experienced that? Thanks in advance.