Cancel stop gtc order immediately followed by close position

If I have an open stop (sell) gtc order on a stock, then want to close the position, I have to cancel that gtc order first, but that orders status becomes “pending_cancel”, and the call to close the position still returns and error with that gtc order’s qty in the “held_for_orders” property.

What is the best way to immediately cancel an existing sell order and place a new sell order without those qty’s conflicting?