Skip to main content
Attach trigger orders to any order, or place standalone TP/SL on existing positions. Both flows are signed by the SDK-managed agent; the user’s wallet is not prompted.
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 on placeOrder:
await perps.placeOrder({
  provider: 'hyperliquid',
  address: userAddress,
  market: { marketId: 'BTC', categoryId: '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:
#ActionDescription
1updateLeverageSet leverage to 10 (if different from current)
2placeOrderBUY 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()).
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:
TriggerOrderTypeDescription
TAKE_PROFITTriggers when price moves in your favor
STOP_LOSSTriggers when price moves against you
TriggerOrderStatusDescription
WAITINGTrigger condition not yet met
TRIGGEREDCondition met, order executed
CANCELLEDTrigger order cancelled

Standalone Trigger Orders

Place standalone TP/SL orders on existing positions, separate from a main order, via placeTriggerOrder:
const result = await perps.placeTriggerOrder({
  provider: 'hyperliquid',
  address: userAddress,
  market: { marketId: 'BTC', categoryId: 'hyperliquid' },
  side: 'SELL',    // SELL to close a LONG position
  takeProfit: { triggerPrice: '100000.00' },
  stopLoss: { triggerPrice: '90000.00', limitPrice: '89800.00' },
});
placeTriggerOrder() sends a placeTriggerOrder action type, which creates standalone trigger orders on existing positions.
API Reference: POST /createAction · /executeAction