Closing the long position with Hedge-Mode

Hello,

How can I close my current “ETHUSDT Long” position with api. Hedge mode is turned on. Can’t close in hedge mode

def close_order(positionSide, side, quantity, symbol):
try:
    order = client.futures_create_order(symbol=symbol,
                                        type=Client.ORDER_TYPE_MARKET,
                                        positionSide=positionSide,
                                        side=side,
                                        quantity=quantity,
                                        closePosition=True)
except Exception as e:
    print("an exception occurred - {}".format(e))
    return False
return True

Is there error message received? Maybe this one can be helpful.

Please

  1. set positionSide to “LONG” to close a “LONG” position
  2. remove closePosition=True, it only works for stop orders
  3. remove “reduceOnly=True”, side=‘SELL’ and positionSide=‘LONG’ already say it

order = client.futures_create_order(symbol=symbol,
type=Client.ORDER_TYPE_MARKET,
positionSide=“SHORT”,
side=“SELL”,
quantity=quantity,
recudeOnly=True)

an exception occurred - APIError(code=-1106): Parameter 'reduceOnly' sent when not required.

order = client.futures_create_order(symbol=symbol, type=Client.ORDER_TYPE_MARKET, positionSide="SHORT", side="SELL", quantity=quantity, closePosition=True)
an exception occurred - APIError(code=-1128): Combination of optional parameters invalid.

my friend,
I did as you said. The current “LONG” position closes and opens the long position again.

‘SELL’ ‘LONG’ combination would only close positions.
Please confirm you didn’t place another order to ‘BUY’ ‘LONG’
You can also try again and this time print out the return value from client.futures_create_order

OK, now I fixed it.
“Long” = “Sell” thanks