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
- 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.
- 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
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
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| id | true | Long | Order ID (for unfilled orders) Position ID (for filled orders) |
| instrument | false | String | The 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. |
| stopLossOrderPrice | false | BigDecimal | Stop loss limit price |
| stopProfitOrderPrice | false | BigDecimal | Take profit limit price |
| stopLossPrice | false | BigDecimal | Stop loss price |
| stopProfitPrice | false | BigDecimal | Take profit price |
| stopLossRate | false | BigDecimal | Stop loss rate |
| stopProfitRate | false | BigDecimal | Take profit Rate |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| msg | String | Returns "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'}