Set SL/TP in Batches
API Description
This interface allows users to set up stop loss (SL) and take profit (TP) in batches for futures trading.
Note: Set SL/TP in Batches is only available via RESTful API.
Precautions
- For unfilled orders, maximum of one Stop-Loss/Take-Profit (SL/TP) can be set at a time.
{'code': 9610, 'msg': 'Each limit order can only add one take profit and stop loss.'}
- For partial positions, a maximum of five SL/TP orders can be configured. To do so, set the parameter stopType = 1.
- For a full position, only one SL/TP order can be configured. In this case, set stopType = 2.
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/Position ID/Plan ID |
| 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 |
| priceType | false | Integer | Take profit and stop loss trigger price type: 1: Index price 2: Latest price 3: Mark price |
| stopFrom | true | Integer | Order type after take profit/stop loss is triggered: 1: Limit order (provide Order ID in "id" parameter) 2: Market order (provide Position ID in "id" parameter) 3: Conditional order(provide Plan ID in "id" parameter) |
| stopType | false | Integer | Type of stop loss/take profit: 1: Take profit/stop loss in batches (partial) 2: Entire position take profit/stop loss.(only applicable to filled orders) |
| closePiece | false | BigDecimal | Number of take-profit and stop-loss contracts (Mandatory for take profit/stop loss in batches) Note: If not specified, the SL/TP will be applied to all contracts. |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| msg | String | Returns "Success" upon successful execution. |
Request Example
The following Python code shows how to set up SL/TP in batches.
Note: For a complete code example, please refer to Introduction > Authentication & Code Snippet > Futures > RESTful Private Interface.
params = {
"id": 2435521222632243158,
"instrument": "btc",
"stopLossPrice": 86000 ,
"stopProfitPrice": 90000,
"priceType" : 3,
"stopFrom" : 2,
"stopType" : 1,
"closePiece" : 1,
}
api_url = "/v1/perpum/addTpsl"
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'}