Unintentional shorting as Limit Sell Order actioned twice?

I have been messing around with the API for a little bit and I have a few Guards all over my code for when I think the unexpected has happened and one of those triggered today…

I put in a Limit Sell Order in and it got filled twice within a few minutes. As well as selling my position it then shorted it…

I have turned on “No Shorting” now so I can just handle that rejection in future, I hope…

But is there a parameter I should have been passing with my Sell Order to indicate that it was to Close rather to Open or if best practice is to then Cancel after it has been fulfilled? Because it the first time it has happened.

There is a python method close_position and associated low level DELETE position endpoint (see python version and low level API )

I always use a ‘buy’ or ‘sell’ order when opening a long and short position respectively, but then use close_position to close out. That may help from ever unintentionally shorting?