I thought it was impossible to open a long when in a short position and Visversa
He would not be able to open both long and short position if the exchange does not allow that.
On the exchanges that I have used before:
On Binance, you can open long position and later open short position without closing the long position and vice versa if you use hedge mode, but you can not with one-way mode.
On OKX, you can use long/short position to do that also, but if changed to net mode, it is the same as one-way mode on Binance and you will not be able to do that.
But the fault is from the script not the exchange.