Active position closing Api PHP

Hi,

I am successfully opening a position with the php code I specified below.

However, if the bot program I made is in the buy position in the sell command from the indicator, the transaction is canceled and all profits are cancelled.

I want to limit that process as in the web application and have it close automatically and instantly.

I couldn’t do it this way.

I searched the document but couldn’t understand exactly what to do. I’m stuck at a small point, I’m waiting for your help on this issue. :grinning:

$result=$binance->trade()->postOrder([
‘symbol’=>‘BTCUSDT’,
‘side’=>‘SELL’,
‘positionSide’ => ‘BOTH’,
‘type’=>‘LIMIT’,
‘quantity’=>‘0.005’,
‘price’=>‘37930’,
‘timeInForce’=>‘GTC’
]);

Array
(
[orderId] => 2982805432
[symbol] => BTCUSDT
[status] => NEW
[clientOrderId] => D5oFeJ1gKbYC5zrf2amNCN
[price] => 37930
[avgPrice] => 0.00000
[origQty] => 0.005
[executedQty] => 0
[cumQty] => 0
[cumQuote] => 0
[timeInForce] => GTC
[type] => LIMIT
[reduceOnly] =>
[closePosition] =>
[side] => SELL
[positionSide] => BOTH
[stopPrice] => 0
[workingType] => CONTRACT_PRICE
[priceProtect] =>
[origType] => LIMIT
[updateTime] => 1645570326638
)

can you explain what’s the question?

I can’t close the position that I opened via API, again via API.