Attach trigger orders to any order, or place standalone TP/SL on existing positions.
The examples on this page use Hyperliquid (provider: 'hyperliquid'). Replace the provider value with any supported DEX from getProviders().
Take Profit & Stop Loss
Attach trigger orders to any order using the takeProfit and stopLoss fields:
const { actions } = await createAction(client, {
provider: 'hyperliquid',
address: userAddress,
action: 'placeOrder',
params: {
asset: { assetId: 'BTC', market: 'hyperliquid' },
side: 'BUY',
type: 'MARKET',
size: '0.1',
price: '95500.00',
leverage: 10,
takeProfit: {
triggerPrice: '100000.00', // Triggers when mark price >= 100000
},
stopLoss: {
triggerPrice: '90000.00', // Triggers when mark price <= 90000
limitPrice: '89800.00', // Executes as limit order at 89800
},
},
});
This produces multiple actions:
| # | Action | Description |
|---|
| 1 | updateLeverage | Set leverage to 10 (if different from current) |
| 2 | placeOrder | BUY 0.1 BTC @ 95500.00 | TP @ 100000.00 | SL @ 90000.00 (limit @ 89800.00) |
Trigger wires are bundled into the placeOrder action. The placeTriggerOrder action type only appears for standalone trigger orders (via placeTriggerOrder() / buildTriggerOrder()).
If limitPrice is omitted from a trigger order, it executes as a market order when triggered.
Trigger Order Enums
The SDK exports enums for trigger order types and their lifecycle status:
TriggerOrderType | Description |
|---|
TAKE_PROFIT | Triggers when price moves in your favor |
STOP_LOSS | Triggers when price moves against you |
TriggerOrderStatus | Description |
|---|
WAITING | Trigger condition not yet met |
TRIGGERED | Condition met, order executed |
CANCELLED | Trigger order cancelled |
Standalone Trigger Orders
Place standalone TP/SL orders on existing positions, separate from a main order.
USER_AGENT mode
const result = await perps.placeTriggerOrder({
provider: 'hyperliquid',
address: userAddress,
asset: { assetId: 'BTC', market: 'hyperliquid' },
side: 'SELL', // SELL to close a LONG position
takeProfit: { triggerPrice: '100000.00' },
stopLoss: { triggerPrice: '90000.00', limitPrice: '89800.00' },
});
USER mode
const { actions } = await perps.buildTriggerOrder({
provider: 'hyperliquid',
address: userAddress,
asset: { assetId: 'BTC', market: 'hyperliquid' },
side: 'SELL',
takeProfit: { triggerPrice: '100000.00' },
});
// Sign and submit as usual...
buildTriggerOrder() and placeTriggerOrder() send a placeTriggerOrder action type, which creates standalone trigger orders on existing positions.
API Reference: POST /actions