> ## Documentation Index
> Fetch the complete documentation index at: https://public-perps-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Trigger Orders

> Attach take profit and stop loss to orders, or place standalone trigger orders

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.

<Info>
  The examples on this page use **Hyperliquid** (`provider: 'hyperliquid'`). Replace the `provider` value with any supported DEX from `getProviders()`.
</Info>

## Take Profit & Stop Loss

Attach trigger orders to any order using the `takeProfit` and `stopLoss` fields on `placeOrder`:

```typescript theme={null}
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:

| # | 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()`).

<Info>
  If `limitPrice` is omitted from a trigger order, it executes as a market order when triggered.
</Info>

## 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, via `placeTriggerOrder`:

```typescript theme={null}
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' },
});
```

<Info>
  `placeTriggerOrder()` sends a `placeTriggerOrder` action type, which creates standalone trigger orders on existing positions.
</Info>

**API Reference:** [POST /createAction · /executeAction](/api-reference/actions)
