> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xmonaco.com/llms.txt
> Use this file to discover all available pages before exploring further.

# V0.7.9

# Monaco Protocol SDK v0.7.9

## Parent TP/SL at Order Placement

You can now attach take-profit and stop-loss brackets directly when placing a
limit or market order. Previously, TP/SL required a separate
`createConditionalOrder` call after the order was open. With parent TP/SL, the
legs are submitted atomically with the entry order and the matching engine owns
their full lifecycle.

### Attaching brackets on placement

Pass `takeProfit` and/or `stopLoss` in the options of `placeLimitOrder` or
`placeMarketOrder`. Both are margin-only and cannot be combined with
`reduceOnly: true`.

```typescript theme={null}
const order = await sdk.trading.placeLimitOrder(tradingPairId, "BUY", "1.5", "2000", {
  tradingMode: "MARGIN",
  marginAccountId,
  positionSide: "LONG",
  leverage: "10",
  takeProfit: {
    triggerPrice: "2200",
    orderType: "MARKET",
  },
  stopLoss: {
    triggerPrice: "1900",
    orderType: "LIMIT",
    limitPrice: "1895",
    timeInForce: "IOC",
  },
});

// Conditional order IDs for the attached legs
order.take_profit_order_id;
order.stop_loss_order_id;
```

The same options are available on `placeMarketOrder`.

### Leg shape

```typescript theme={null}
interface ParentTpSlLegParams {
  triggerPrice: string;
  orderType: "MARKET" | "LIMIT";
  limitPrice?: string;              // required for LIMIT
  timeInForce?: "GTC" | "IOC";     // for LIMIT orders
  slippageToleranceBps?: number;    // for MARKET orders
  expiresAt?: string;               // ISO 8601 — auto-cancel if not triggered
}
```

The leg has no `quantity` field — it inherits the parent order's quantity.

### Lifecycle

If the parent fills immediately, the attached TP/SL legs move directly to
`ACTIVE`. If the parent rests on the book, the legs start as `PENDING_PARENT`
and activate once the parent fill creates or extends a position.

| State | Meaning |
| - | - |
| `PENDING_PARENT` | Parent order has not filled yet |
| `ACTIVE` | Waiting for trigger price to be crossed |
| `TRIGGERING` | Trigger fired, underlying order being submitted |
| `TRIGGERED` | Underlying order submitted |
| `CANCELLED` | Cancelled by user, OCO sibling, or parent cancellation |

**OCO behaviour:** when one leg triggers, the matching engine automatically
cancels the sibling. Cancelling the unfilled parent order also cancels any
`PENDING_PARENT` children.

### New `ConditionalOrder` fields

`listConditionalOrders` responses now include:

| Field | Description |
| - | - |
| `parent_order_id` | UUID of the parent order this leg is attached to |
| `association_type` | `"PARENT_ORDER"` for parent-attached legs, `"POSITION"` for position-attached |
| `linked_group_id` | Shared UUID across the TP and SL of the same parent — useful for rendering OCO pairs |
| `activated_at` | Timestamp when a `PENDING_PARENT` leg became `ACTIVE` |

### WebSocket changes

The `conditional_order_update` event gains matching fields and two new reason
values:

```typescript theme={null}
{
  // new fields
  parentOrderId?: string;
  associationType?: "POSITION" | "PARENT_ORDER";
  linkedGroupId?: string;
  activatedAt?: string;
  state: "PENDING_PARENT" | "ACTIVE" | "TRIGGERING" | "TRIGGERED" | "CANCELLED" | "EXPIRED" | "FAILED";
  reason: "created" | "activated" | "cancelled" | "parent_cancelled" | "triggered" | "failed" | "oco_cancelled";
}
```

New `reason` values:

* `activated` — `PENDING_PARENT` leg became `ACTIVE` after the parent filled
* `parent_cancelled` — parent order was cancelled before filling, leg was purged
* `oco_cancelled` — sibling leg triggered first, this leg was cancelled by OCO

### Deprecated: standalone `createConditionalOrder`

`sdk.trading.createConditionalOrder` is deprecated for TP/SL use. New
integrations should use parent TP/SL (this release) or
`sdk.positions.attachPositionTpSl` for existing positions. The method remains
available but will be removed in a future release.

***

## Migration

No breaking changes. All new fields are additive.

If you use `createConditionalOrder` today and want to migrate to parent TP/SL:

```diff theme={null}
- const order = await sdk.trading.placeLimitOrder(tradingPairId, "BUY", "1.5", "2000", {
-   tradingMode: "MARGIN",
-   marginAccountId,
-   positionSide: "LONG",
-   leverage: "10",
- });
-
- await sdk.trading.createConditionalOrder({
-   tradingPairId,
-   marginAccountId,
-   conditionType: "TAKE_PROFIT",
-   triggerPrice: "2200",
-   side: "SELL",
-   positionSide: "LONG",
-   orderType: "MARKET",
- });

+ const order = await sdk.trading.placeLimitOrder(tradingPairId, "BUY", "1.5", "2000", {
+   tradingMode: "MARGIN",
+   marginAccountId,
+   positionSide: "LONG",
+   leverage: "10",
+   takeProfit: { triggerPrice: "2200", orderType: "MARKET" },
+ });
```

***

## Upgrade

```bash theme={null}
npm install @0xmonaco/core@0.7.9 @0xmonaco/types@0.7.9 @0xmonaco/react@0.7.9
# or bun
bun add @0xmonaco/core@0.7.9 @0xmonaco/types@0.7.9 @0xmonaco/react@0.7.9
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.