Guides
Guides

Set SL/TP

Define stop-loss and take-profit levels for an existing position.

Define stop-loss and take-profit levels for an existing position (by UUID). Prices are USDT levels. The currency is inherited from the position.

Request

curl -X POST "https://trade.mudrex.com/fapi/v1/futures/positions/{position_id}/riskorder" \
  -H "Content-Type: application/json" \
  -H "X-Authentication: your-secret-key" \
  -d '{
    "stoploss_price": "0.10",
    "takeprofit_price": "0.13",
    "order_source": "API",
    "is_stoploss": true,
    "is_takeprofit": true,
    "stoploss_client_order_id": "my-sl-123",
    "takeprofit_client_order_id": "my-tp-123"
  }'

Parameters

ParameterTypeRequiredDescription
position_idstringYesThe unique identifier of the position (path parameter).
stoploss_pricestringConditionalRequired if is_stoploss is true. USDT price (above liquidation for LONG).
takeprofit_pricestringConditionalRequired if is_takeprofit is true. USDT price.
order_sourcestringNoSource of the order (e.g. "API").
is_stoplossbooleanNoWhether to set a stop loss order (default: false).
is_takeprofitbooleanNoWhether to set a take profit order (default: false).
stoploss_client_order_idstringNoOptional client id for the stop-loss leg.
takeprofit_client_order_idstringNoOptional client id for the take-profit leg.

Response

Status: 200 OK

{
    "success": true,
    "data": {
        "position_id": "019ecc52-2f95-7ab5-8682-c3a0f43ccda6",
        "status": "CREATED",
        "message": "Risk order placed successfully"
    }
}

Response fields

FieldDescription
position_idID of the position for which the risk order was set.
statusStatus of the risk order (e.g. CREATED).
messageStatus message.

The response does not include the stop-loss or take-profit order UUIDs. Read them from Open Positions (stoploss.order_id, takeprofit.order_id). Open Orders lists each leg as an order with order_type STOPLOSS or TAKEPROFIT, trigger_type: MARKET, status: CREATED, price set to the trigger price and the supplied stoploss_client_order_id / takeprofit_client_order_id.

Closing the position sets both legs to SYSTEM_CANCELLED.

If the position already has SL/TP, the call updates them and returns {"message": "Risk order amended successfully"}.

Errors

❕Common errors

Position not found

{
    "success": false,
    "errors": [
        { "code": 404, "text": "Position not found" }
    ]
}

Status: 404 Not Found

Position not in OPEN state

{
    "success": false,
    "errors": [
        { "code": 400, "text": "Position is not in OPEN state" }
    ]
}

Status: 400 Bad Request

Risk order creation failed (SL below liquidation)

{
    "success": false,
    "errors": [
        { "code": 400, "text": "Risk order creation failed" }
    ]
}

Status: 400 Bad Request — stop loss below liquidation price for a LONG position (or above for a SHORT).


Did this page help you?