Skip to main content

Set SL/TP

API Description

This interface allows users to set take profit (TP) and stop loss (SL) for both filled and unfilled orders.

Note: Setting SL/TP is only available via RESTful API.

Precautions

  1. To set SL/TP for a filled order, please provide the Position ID. To set SL/TP for an unfilled order, please provide the Order ID.
  2. To setup SL/TP in batches, please refer to Futures > Place Orders > Set SL/TP in Batches.

Authentication

This is a private interface and requires authentication. For details on using the RESTful API, refer to Introduction > Authentication & Code Snippet > Futures > RESTful Private Interface.

Request Method

POST

Endpoint

/v1/perpum/TPSL

Frequency Limit

The frequency limit for this interface is 10 requests/2s per user ID and IP. In addition to this per-interface limit, a global rate limit is also enforced.

For detailed information on Global rate limits and API Rate Limiting Policy, please refer to the "Frequency Limit" section at click here

Request Parameters

ParameterMandatoryTypeDescription
idtrueLongOrder ID (for unfilled orders) Position ID (for filled orders)
instrumentfalseStringThe base currency of the instrument. (e.g., BTC or btc). This parameter is case-insensitive.
Note: For instruments that start with numbers (e.g., 1000PEPE), both uppercase and lowercase formats are valid.
stopLossOrderPricefalseBigDecimalStop loss limit price
stopProfitOrderPricefalseBigDecimalTake profit limit price
stopLossPricefalseBigDecimalStop loss price
stopProfitPricefalseBigDecimalTake profit price
stopLossRatefalseBigDecimalStop loss rate
stopProfitRatefalseBigDecimalTake profit Rate

Response Parameters

ParameterTypeDescription
msgStringReturns "Success" upon successful execution.

Request Example

The following Python code shows how to set ST/TP for an unfilled order using an order ID

Note: For a complete code example, please refer to Introduction > Authentication & Code Snippet > Futures > RRESTful Private Interface.

params = {
"id": "33308751688900817",
"instrument": "BTC",
"stopProfitPrice" : 95000,
"stopLossPrice" : 82000
}

api_url = "/v1/perpum/TPSL"
method = "POST"
response_code, response_data = FuturesRestfulPrivate(params, api_url, method, sec_key, api_key) # function FuturesRestfulPrivate() is defined in section (Introduction > Authentication & Code Snippet > Futures > RESTful Private Interface)

Note: For a complete Java code example, please refer to Introduction > Authentication & Code Snippet > Futures > RESTful Private Interface.

Response Example

The following is an example response returned by the above Python request:

{'code': 0, 'msg': 'Success'}