> ## 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.

# OrdersService

> Order entry, cancellation, replacement, batch operations, and order lookup

Package: `monaco.api.orders`

Source: `protos/api/orders.proto`

Use `OrdersService` for authenticated order management.

```protobuf theme={null}
service OrdersService {
  rpc CreateOrder(CreateOrderRequest) returns (CreateOrderResponse);
  rpc CancelOrder(CancelOrderRequest) returns (CancelOrderResponse);
  rpc BatchCancelOrders(BatchCancelOrdersRequest) returns (BatchCancelOrdersResponse);
  rpc BatchCancelAll(BatchCancelAllRequest) returns (BatchCancelAllResponse);
  rpc BatchCancelAllByPair(BatchCancelAllByPairRequest) returns (BatchCancelAllResponse);
  rpc BatchCreateOrders(BatchCreateOrdersRequest) returns (BatchCreateOrdersResponse);
  rpc BatchReplaceOrders(BatchReplaceOrdersRequest) returns (BatchReplaceOrdersResponse);
  rpc ReplaceOrder(ReplaceOrderRequest) returns (ReplaceOrderResponse);
  rpc GetOrder(GetOrderRequest) returns (GetOrderResponse);
  rpc ListOrders(ListOrdersRequest) returns (ListOrdersResponse);
  rpc CancelConditionalOrder(CancelConditionalOrderRequest) returns (CancelConditionalOrderResponse);
  rpc ListConditionalOrders(ListConditionalOrdersRequest) returns (ListConditionalOrdersResponse);
  rpc GetConditionalOrder(GetConditionalOrderRequest) returns (GetConditionalOrderResponse);
  rpc CreateTwapOrder(CreateTwapOrderRequest) returns (CreateTwapOrderResponse);
  rpc CancelTwapOrder(CancelTwapOrderRequest) returns (CancelTwapOrderResponse);
  rpc GetTwapOrder(GetTwapOrderRequest) returns (TwapOrder);
  rpc ListTwapOrders(ListTwapOrdersRequest) returns (ListTwapOrdersResponse);
  rpc GetTwapOrderTca(GetTwapOrderTcaRequest) returns (GetTwapOrderTcaResponse);
  rpc ListTwapOrderSlices(ListTwapOrderSlicesRequest) returns (ListTwapOrderSlicesResponse);
}
```

## Notes

* Order creation, cancellation, replacement, and listing require authentication.
* Batch RPCs are the preferred path for multi-order workflows.
* Attach TP/SL through order placement or `PositionsService.AttachPositionTpSl`.
* `GetConditionalOrder` fetches a single TP/SL order by UUID — the same IDs returned as `take_profit_order_id` and `stop_loss_order_id` in `CreateOrderResponse`.
* A trigger and the order it fires into are linked in both directions, and both reads are owner-scoped. `GetConditionalOrder` and `ListConditionalOrders` carry `triggered_order` — the close's current status, filled quantity, average fill price, taker fees, fill time and terminal reason, read from that order at request time — present only once `state` is TRIGGERED and the close can be read, never on a FAILED conditional, and never on the `conditional_orders` WebSocket frames. `GetOrder` / `ListOrders` carry the reverse pointer `conditional_order_id` on a close the engine placed for a trigger; it is absent on client-placed orders, on TWAP children (they carry `parent_order_id`), and on closes older than the field, which are not backfilled.
* `ListOrders` returns book orders only (`LIMIT` and `MARKET`): TWAP parents and conditional (TP/SL) orders are not rows of it under any `status` or `trading_mode` filter and are not counted in `total`; list them with `ListTwapOrders` and `ListConditionalOrders`. A TWAP's slices — the child orders it places, which carry `parent_order_id` — are not rows of it either, resting or finished, and are not counted: read them with `ListTwapOrderSlices`. The close a trigger fired into is a book order and is listed as its own row carrying `conditional_order_id`.
* `ReplaceOrder` and `BatchReplaceOrders` carry an entry order's pending take-profit and stop-loss legs onto the replacement and re-check them as placement would: a fixed trigger on the wrong side of the replacement's expected entry fails a single `ReplaceOrder` with `INVALID_ARGUMENT`, and in `BatchReplaceOrders` the RPC returns `OK` with that item's `results[].error.code` set to `INVALID_ORDER`; either way the original keeps resting. A replacement that fills on arrival arms the carried legs — a fixed TP/SL on any fill, a trailing stop on a full fill.
* `ReplaceOrder` and `BatchReplaceOrders` refuse to replace the LIMIT leg a TP/SL fired into — an order carrying `conditional_order_id` — the way a passive TWAP child is refused: a replacement rests under a new order id the conditional does not point at, which would sever the link both ways. The refusal names the conditional order and the original leg stays resting; in a batch the refused item's original is never cancelled. Cancelling a triggered leg is unchanged.
* TWAP parent orders execute a large order as scheduled market child orders across a time window. `CreateTwapOrder`, `CancelTwapOrder`, `GetTwapOrder`, and `ListTwapOrders` manage the parent lifecycle; `GetTwapOrder` returns the `TwapOrder` read model directly. Delegated-agent sessions are rejected for all TWAP RPCs. See [TWAP Orders](/trading-mechanics/twap-orders) for the execution model.
* `GetTwapOrderTca` returns the post-execution transaction cost analysis report for a **terminal** TWAP parent (`COMPLETED` or `CANCELLED`). A non-terminal parent is `INVALID_ARGUMENT`; another user's parent is `NOT_FOUND`, indistinguishable from an unknown ID. The six analytics fields are optional and absent when they cannot be computed honestly.
* `ListTwapOrderSlices` lists one TWAP parent's child orders (its slices), each a `GetOrderResponse` exactly as `GetOrder` returns it with `parent_order_id` set to the parent, resting and finished alike. `order_by` is `ASC` (the default, oldest slice first) or `DESC` by `created_at`; `page_size` is 1-1000 (default 20) and `next_page_token` is minted only while a further page exists, pinned to the parent and `order_by` that minted it. A `PASSIVE` parent's reprices and deadline sweeps are child orders too, so a parent can have more slices than `slices_placed`. Another user's parent is `NOT_FOUND`, indistinguishable from an unknown ID.


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