Set Position Take Profit and Stop Loss
Set Position Take Profit and Stop Loss
Set take profit and stop loss for existing positions, supporting both spot and contract trading.
Request frequency limit: 1/s
Rate limit rule: UserID
Request URL
POST /deepcoin/trade/set-position-sltp
Request Parameters
| Field Name | Required | Type | Description |
|---|---|---|---|
| instType | true | string | Product type Spot: SPOTContract: SWAP |
| instId | true | string | Product ID e.g., BTC-USDT for spot, BTC-USDT-SWAP for contract |
| posSide | false | string | Position side (required for contract) Long: longShort: short |
| mrgPosition | false | string | Margin position mode (for contract) Merged: mergeSplit: split |
| tdMode | false | string | Trade mode (for contract) Cross margin: crossIsolated margin: isolated |
| posId | false | string | Position ID (required when mrgPosition is split) |
| tpTriggerPx | false | string | Take profit trigger price At least one of TP or SL must be set |
| tpTriggerPxType | false | string | Take profit trigger price type Last price: lastIndex price: indexMark price: markDefault: last |
| tpOrdPx | false | string | Take profit order price-1 means market priceDefault: -1 |
| slTriggerPx | false | string | Stop loss trigger price At least one of TP or SL must be set |
| slTriggerPxType | false | string | Stop loss trigger price type Last price: lastIndex price: indexMark price: markDefault: last |
| slOrdPx | false | string | Stop loss order price-1 means market priceDefault: -1 |
| sz | false | string | Position size for partial TP/SL Empty means full position |
Notes:
- At least one of
tpTriggerPxorslTriggerPxmust be provided - For contract trading with split position mode (
mrgPosition=split),posIdis required - For spot trading,
posSide,mrgPosition,tdMode, andposIdare not applicable
Request Example
Spot - Set both take profit and stop loss:
{
"instType": "SPOT",
"instId": "BTC-USDT",
"tpTriggerPx": "107000",
"slTriggerPx": "102000"
}
Contract - Set take profit and stop loss for long position (merged mode):
{
"instType": "SWAP",
"instId": "BTC-USDT-SWAP",
"posSide": "long",
"mrgPosition": "merge",
"tdMode": "cross",
"tpTriggerPx": "107000",
"slTriggerPx": "102000"
}
Contract - Set take profit and stop loss for specific position (split mode):
{
"instType": "SWAP",
"instId": "BTC-USDT-SWAP",
"posSide": "long",
"mrgPosition": "split",
"tdMode": "isolated",
"posId": "1000596063679172",
"tpTriggerPx": "107000",
"tpTriggerPxType": "mark",
"tpOrdPx": "-1",
"slTriggerPx": "102000",
"slTriggerPxType": "mark",
"slOrdPx": "-1"
}
Set only take profit:
{
"instType": "SPOT",
"instId": "BTC-USDT",
"tpTriggerPx": "107000"
}
Set only stop loss:
{
"instType": "SPOT",
"instId": "BTC-USDT",
"slTriggerPx": "102000"
}
Response Parameters
| Field Name | Type | Description |
|---|---|---|
| ordId | string | SLTP Order ID (use this ID to cancel the order) |
| sCode | string | Event execution result status code0: Success |
| sMsg | string | Rejection message if the request is unsuccessful |
Response Example
Successful response:
{
"code": "0",
"msg": "",
"data": {
"ordId": "1001063717138767",
"sCode": "0",
"sMsg": ""
}
}
Failed response:
{
"code": "51000",
"msg": "Parameter error",
"data": {
"ordId": "",
"sCode": "51000",
"sMsg": "At least one of take profit or stop loss must be set"
}
}
Description
Functionality
- Set take profit and/or stop loss for existing positions
- Supports both spot (SPOT) and contract (SWAP) trading
- Allows partial position TP/SL by specifying
szparameter - Supports different trigger price types (last, index, mark)
- Can set market or limit order price for TP/SL execution
Use Cases
- Risk Management: Automatically close positions when price reaches target or stop loss level
- Profit Protection: Lock in profits when price reaches desired level
- Loss Limitation: Limit potential losses by setting stop loss
- Partial Position Management: Set TP/SL for only part of the position
Important Notes
- Order ID: Save the returned
ordIdto cancel or modify the TP/SL order later - Price Precision: Trigger prices must comply with the product's price precision requirements
- Position Verification: Ensure you have an existing position before setting TP/SL
- Overwriting: Setting new TP/SL may overwrite existing TP/SL orders for the same position
- Contract Specifics: For contract trading, specify position side (
posSide) and margin mode correctly
Related APIs
- Modify Position TP/SL:
/deepcoin/trade/modify-position-sltp- Modify existing TP/SL orders - Cancel Position TP/SL:
/deepcoin/trade/cancel-position-sltp- Cancel TP/SL orders - Query Pending Trigger Orders:
/deepcoin/trade/trigger-orders-pending- Query existing TP/SL orders