Skip to main content

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

  1. 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.'}
  1. For partial positions, a maximum of five SL/TP orders can be configured. To do so, set the parameter stopType = 1.
  2. 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

/v1/perpum/addTpsl

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/Position ID/Plan ID
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
priceTypefalseIntegerTake profit and stop loss trigger price type:
1: Index price
2: Latest price
3: Mark price
stopFromtrueIntegerOrder 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)
stopTypefalseIntegerType 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)
closePiecefalseBigDecimalNumber 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

ParameterTypeDescription
msgStringReturns "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'}