Skip to main content

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 NameRequiredTypeDescription
instTypetruestringProduct type
Spot: SPOT
Contract: SWAP
instIdtruestringProduct ID
e.g., BTC-USDT for spot, BTC-USDT-SWAP for contract
posSidefalsestringPosition side (required for contract)
Long: long
Short: short
mrgPositionfalsestringMargin position mode (for contract)
Merged: merge
Split: split
tdModefalsestringTrade mode (for contract)
Cross margin: cross
Isolated margin: isolated
posIdfalsestringPosition ID (required when mrgPosition is split)
tpTriggerPxfalsestringTake profit trigger price
At least one of TP or SL must be set
tpTriggerPxTypefalsestringTake profit trigger price type
Last price: last
Index price: index
Mark price: mark
Default: last
tpOrdPxfalsestringTake profit order price
-1 means market price
Default: -1
slTriggerPxfalsestringStop loss trigger price
At least one of TP or SL must be set
slTriggerPxTypefalsestringStop loss trigger price type
Last price: last
Index price: index
Mark price: mark
Default: last
slOrdPxfalsestringStop loss order price
-1 means market price
Default: -1
szfalsestringPosition size for partial TP/SL
Empty means full position

Notes:

  • At least one of tpTriggerPx or slTriggerPx must be provided
  • For contract trading with split position mode (mrgPosition=split), posId is required
  • For spot trading, posSide, mrgPosition, tdMode, and posId are 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 NameTypeDescription
ordIdstringSLTP Order ID (use this ID to cancel the order)
sCodestringEvent execution result status code
0: Success
sMsgstringRejection 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 sz parameter
  • Supports different trigger price types (last, index, mark)
  • Can set market or limit order price for TP/SL execution

Use Cases

  1. Risk Management: Automatically close positions when price reaches target or stop loss level
  2. Profit Protection: Lock in profits when price reaches desired level
  3. Loss Limitation: Limit potential losses by setting stop loss
  4. Partial Position Management: Set TP/SL for only part of the position

Important Notes

  1. Order ID: Save the returned ordId to cancel or modify the TP/SL order later
  2. Price Precision: Trigger prices must comply with the product's price precision requirements
  3. Position Verification: Ensure you have an existing position before setting TP/SL
  4. Overwriting: Setting new TP/SL may overwrite existing TP/SL orders for the same position
  5. Contract Specifics: For contract trading, specify position side (posSide) and margin mode correctly
  • 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