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
dino
November 17, 2020, 3:47am
2
Is there error message received? Maybe this one can be helpful.
By default the futures keeps the position mode to One-way. In order to enable the new feature of Hedge Mode, so you can have dual sides positions.
enable it by endpoint POST /fapi/v1/positionSide/dual, setting the parameter dualSidePosition = true
Open position:
Long : positionSide=LONG, side=BUY
Short: positionSide=SHORT, side=SELL
Close position:
Close long position: positionSide=LONG, side=SELL
Close short position: positionSide=SHORT, side=BUY
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.
MJW
November 17, 2020, 11:09am
6
‘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
xz013
February 4, 2021, 6:13am
10
Hello sir, I have a big problem here and hope you can help me
wanna close 20% of my open position " LONG " on “dotusdt” future
My total amount is 4.0
my request is :
symbol = DOTUSDT,
side = OrderSide.SELL,
positionSide = “Long”,
type = LIMIT,
Price = 22.00,
Quantity = 0.60
wanna do it with limit order
and I got this error : Exception: {“code”:-1111,“msg”:“Precision is over the maximum defined for this asset.”}
i’m using HEDGE MODE
so any trick how to do it !
OK, now I fixed it.
“Long” = “Sell” thanks
Hi!
I want to close Long trade (usdt future testnet) , buy I can’t do it.
I wrot this code:
params = {
"symbol": "BTCUSDT",
"type":"MARKET",
"dualSidePosition": "LONG",
"side":"SELL",
"quantity":0.001,
"timestamp": timestamp
}
response = send_signed_request(‘POST’, ‘/fapi/v1/positionSide/dual’, params)
print(response)
error response:
{‘code’: -1102, ‘msg’: “Mandatory parameter ‘dualSidePosition’ was not sent, was empty/null, or malformed.”}
What is wrong ? Where is the problem?
MJW
January 11, 2021, 5:36am
9
Wrong endpoint, should be /fapi/v1/order
dino
February 8, 2021, 2:37am
11
this endpoint is for adjust the position mode, only dualSidePosition
is allowed, please check the document for details, https://binance-docs.github.io/apidocs/futures/en/#composite-index-symbol-information-streams