tpSl action creates take-profit (TP) and stop-loss (SL) trigger orders for an existing position. Unlike regular orders, TP/SL orders do not consume margin when created — they sit dormant and automatically place a real closing order when the market reaches the trigger price.
The action has two forms:
- Position-level TP/SL (
isPositionTpsl: true) — set a TP only, an SL only, or both in one request. The closing direction is determined automatically from the position side, and the position must already exist. - Standalone trigger order (
isPositionTpsl: falsewithorderSide) — places an order when the trigger fires, for example a breakout entry. It takes exactly one oftpPrice/slPrice, and can carry anopenTp*/openSl*group that sets the TP/SL of the order placed after it fires.
Endpoint
Request
All requests must include an ECDSA signature and a millisecond-precision nonce.slPrice level, and whose resulting order carries its own take-profit and stop-loss:
slPrice and openSlPrice are two different layers: slPrice is when this conditional order fires; openSlPrice is the stop-loss of the order placed after it fires.
Action fields
string
required
type (required) — Fixed value: "tpSl".int32
required
a (required) — The contract ID the TP/SL orders apply to.int8
positionSide — Identifies the position side: 0 = ONE_WAY, 1 = LONG, 2 = SHORT. Defaults to 0.boolean
isPositionTpsl — When true, creates position-level TP/SL orders that automatically close the position when triggered. When false, creates standalone trigger orders. Defaults to false.string
orderSide — The side of the order placed when the trigger fires: "B" = buy, "S" = sell. Used only for standalone trigger orders (isPositionTpsl = false); for position-level TP/SL the closing direction is inferred automatically.boolean
reduceOnly — When true, the triggered order is marked reduce-only and will only execute if it reduces an open position. Defaults to false.string
tpPrice — Trigger price for the take-profit leg, as a raw integer string. Set to "0" or omit to skip the TP leg. With isPositionTpsl: true, at least one of tpPrice / slPrice must be greater than "0", and both may be. With isPositionTpsl: false, exactly one of them must be greater than "0".string
slPrice — Trigger price for the stop-loss leg. Set to "0" or omit to skip the SL leg. Same rules as tpPrice.string
tpLimitPrice — Execution price used once the TP triggers. Must be greater than zero. With tpOrderType set to limit it is the resting price of a GTC order; with market it is the price the IOC order may cross to, computed as mark price ± your slippage allowance.string
slLimitPrice — Execution price used once the SL triggers. Must be greater than zero, with the same meaning as tpLimitPrice.string
tpSize — The position size to close when the TP triggers. "0" = close the entire position.string
slSize — The position size to close when the SL triggers. "0" = close the entire position.int8
tpTriggerType — The price feed used to evaluate the TP trigger: 0 = mark price, 1 = oracle price. Defaults to 0. Only these two values are accepted — any other value is rejected with invalid tp/sl trigger type.int8
slTriggerType — The price feed used to evaluate the SL trigger: 0 = mark price, 1 = oracle price. Defaults to 0. Same restriction as tpTriggerType.int8
tpOrderType — Type of order placed when the TP triggers: 1 = limit, 2 = market. Required whenever tpPrice is greater than "0", and must be omitted or 0 when the TP leg is unset.int8
slOrderType — Type of order placed when the SL triggers: 1 = limit, 2 = market. Required whenever slPrice is set, with the same rule as tpOrderType.Open TP/SL fields
These fields set the take-profit and stop-loss of the order placed after a standalone trigger fires. They are accepted only withisPositionTpsl: false; a position-level request that carries them is rejected, because a position TP/SL closes a position rather than opening one. Each leg follows the same rules as the tp* / sl* legs above.
string
openTpPrice — Take-profit trigger price of the resulting order. "0" or omitted sets none.string
openTpLimitPrice — Execution price once that take-profit triggers, greater than zero. Same meaning as tpLimitPrice.string
openTpSize — Quantity that take-profit closes. "0" closes the entire position.int8
openTpTriggerType — Price source for that trigger: 0 = mark price, 1 = oracle price.int8
openTpOrderType — Order type placed when that take-profit triggers: 1 = limit, 2 = market. Required whenever openTpPrice is greater than "0".string
openSlPrice — Stop-loss trigger price of the resulting order. Mirrors openTpPrice.string
openSlLimitPrice — Execution price once that stop-loss triggers. Mirrors openTpLimitPrice.string
openSlSize — Quantity that stop-loss closes. Mirrors openTpSize.int8
openSlTriggerType — Price source for that trigger. Mirrors openTpTriggerType.int8
openSlOrderType — Order type placed when that stop-loss triggers. Mirrors openTpOrderType.Response
Success
Rejection
A rejected request still returns HTTP 200 withstatus: "ok", carrying errorCode and errorMessage inside response.data. Common causes are no open position, both tpPrice and slPrice at "0", not being enrolled in the market deployer, an unknown contract, and a position-level request that carries openTp* / openSl* fields.
Response fields
int64
The order ID assigned to the take-profit trigger order. Returns
0 if the TP leg was not set (i.e., tpPrice was "0").int64
The order ID assigned to the stop-loss trigger order. Returns
0 if the SL leg was not set (i.e., slPrice was "0").number
Present only when the request is rejected; a non-zero value means nothing was created.
string
Present together with
errorCode. The rejection reason.