> For the complete documentation index, see [llms.txt](https://quantinfra.gitbook.io/quantinfra-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantinfra.gitbook.io/quantinfra-docs/strategies/orders-and-trades.md).

# Orders and trades

## Supported order types

| OrdType             | Execution on strategy subaccounts and broker accounts                                                                           | Execution on virtual accounts                                                                  |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| Market              | Sent directly to broker                                                                                                         | Executed by the next tick price                                                                |
| Limit               | Sent directly to broker                                                                                                         | Executed by the limit price                                                                    |
| Stop Market         |                                                                                                                                 |                                                                                                |
| Market If Touched\* | Triggering checked against the next tick price internally. Once triggered, is converted a market order and sent to the broker   | Triggering checked against the next tick price. Once triggered, is executed by the tick price. |
| Stop Limit          | Triggering checked against the next tick price internally. Once triggered, is converted to a limit order and sent to the broker | Triggering checked against the next tick price. Once triggered, converts to the limit order.   |

\* — Market if Touched behaves like a stop order, but the triggering conditions are those of a limit order.

## Order IDs

There are 3 fields responsible for identification of an order:

* ClOrdId — an arbitrary string provided by the strategy when placing an order. If provided, and another order with the same ClOrdId exists on the strategy’s account, the new order will be rejected.
* OrderId — the primary identifier of the order, assigned once the order is recorded by the Accounts Service. This ID is unique within the AS (so, if there several AS in your installation, order IDs may overlap).
* ExternalId — string, the ID assigned to the order by the broker.

## Linked orders (OCO and OTO)

When submitting an order, it can be linked to other orders. There are two link types: One-Triggers-Other and One-Cancels-Other. The reference to the order is by ClOrdId.

* OTO: usually, a main order is submitted along with suspended linked orders. When the main order gets filled (partially or fully), linked orders are activated. If there are no orders with the given ClOrdId, nothing happens.
* OCO: once the order gets executed (partially or fully), the linked orders are canceled.

## Time in force

There are two options:

* GoodTillCancel (default)
* GoodTillTime

## Suspended orders

If an order is placed as suspended, it will not be sent for execution or triggered (for limit and stop orders) until activated. The order is activated:

* Either by ActivationDt
* Or by another order with a One-Triggers-Other link to the suspended order being executed (partially or fully)

## Order updates

Any changes to an order's status are recorded in Execution Reports (similar to the FIX protocol). The tables below show the order status matrices for different scenarios.

### Place a new order

| Event                                                    | OrdStatus       | ExecType   | ExecTypeReason       | Comments                                                               |
| -------------------------------------------------------- | --------------- | ---------- | -------------------- | ---------------------------------------------------------------------- |
| Strategy places an order                                 |                 |            |                      |                                                                        |
| Order is recorded on the account                         | PendingNew      | PendingNew | OrderChangeInitiated |                                                                        |
| Order is placed to the broker or to the virtual executor | New             | New        |                      | ExternalId is populated                                                |
| Order is partially executed                              | PartiallyFilled | Fill       |                      | LastPx, LastQty, CumQty, LeavesQty, CalculatedCcyLastQty are populated |
| Order is executed                                        | Filled          | Fill       |                      |                                                                        |

Note that after a fill, a Trade is booked to the account, and the strategy's respective callback (OnTrade) is invoked.

### Place a new suspended order

| Event                                                    | OrdStatus  | ExecType   | ExecTypeReason               | Comments                |
| -------------------------------------------------------- | ---------- | ---------- | ---------------------------- | ----------------------- |
| Strategy places an order                                 |            |            |                              |                         |
| Order is recorded on the account                         | Suspended  | PendingNew | OrderChangeInitiated         |                         |
| Order is activated                                       | PendingNew | PendingNew | TriggeredOrActivatedBySystem |                         |
| Order is placed to the broker or to the virtual executor | New        | New        |                              | ExternalId is populated |

### Cancel an order

| Event                                           | OrdStatus     | ExecType      | ExecTypeReason       | Comments |
| ----------------------------------------------- | ------------- | ------------- | -------------------- | -------- |
| Strategy requests cancellation of an order      |               |               |                      |          |
| Order Cancel Request is recorded on the account | PendingCancel | PendingCancel | OrderChangeInitiated |          |
| Order is canceled                               | Canceled      | Canceled      |                      |          |

### Replace an order

| Event                                                   | OrdStatus                      | ExecType       | ExecTypeReason       | Comments |
| ------------------------------------------------------- | ------------------------------ | -------------- | -------------------- | -------- |
| Strategy requests replacement of an order               |                                |                |                      |          |
| Order Cancel Replace Request is recorded on the account | PendingReplace                 | PendingReplace | OrderChangeInitiated |          |
| Order is replaced                                       | New / PartiallyFilled / Filled | Replaced       |                      |          |

### Quantities

There are 4 fields in every execution report that denote the executed and remaining quantity:

<table><thead><tr><th width="168.45703125">Field</th><th>Description</th></tr></thead><tbody><tr><td>OrderQty</td><td>The quantity of the order</td></tr><tr><td>LastQty</td><td>In execution reports with ExecType = Fill: contains the quantity of this fill</td></tr><tr><td>CumQty</td><td>Total executed quantity for the current and all previous fills</td></tr><tr><td>LeavesQty</td><td>Remaining quantity</td></tr></tbody></table>

## Order objects

### New order single

<table><thead><tr><th width="218.26953125">Property</th><th>Description</th></tr></thead><tbody><tr><td>AccountId</td><td></td></tr><tr><td>ClOrdId</td><td>Client-provided identifier of an order.<br><br>If there is an active order with the same ClOrdId on the account, the incoming order will be rejected.</td></tr><tr><td>ContractId</td><td></td></tr><tr><td>StrategyPositionId</td><td>Used for Hedged accounting — client-provided identifier of the position</td></tr><tr><td>PositionEffect</td><td>Used for Hedged accounting — whether the order must open or close the position.<br><br>On virtual accounts the following logic exists: if an order with PositionEffect = Open is executed, and there is already a position with the same StrategyPositionId, the order gets canceled. The same happens for PositionEffect = Close and a non-existing position.</td></tr><tr><td>OrdType</td><td>Order type</td></tr><tr><td>Side</td><td></td></tr><tr><td>OrderQty</td><td>Unsigned quantity</td></tr><tr><td>Price</td><td>Limit order price</td></tr><tr><td>StopPx</td><td>Stop price for StopMarket, StopLimit, MarketIfTouched orders</td></tr><tr><td>TimeInForce</td><td></td></tr><tr><td>IsSuspended</td><td>Set to true to create a suspended order</td></tr><tr><td>ActivationDt</td><td>Activation timestamp for suspended orders</td></tr><tr><td>ExpireDt</td><td>Expiration timestamp for Good Till Time orders</td></tr><tr><td>LinkedOrders</td><td>List of ClOrdId of OCO/OTO orders</td></tr><tr><td>TradingSessionsIds</td><td>Use for backtesting or for orders bound to the virtual executor (virtual accounts and stop orders). If provided, the execution/triggering of the order will be checked only inside the given trading sessions.</td></tr></tbody></table>

### Order

All fields from NewOrderSingle plus:

<table><thead><tr><th width="218.10546875">Property</th><th>Description</th></tr></thead><tbody><tr><td>OrderId</td><td>Note that the order ID is unique only within one instance of the Accounts Service</td></tr><tr><td>AccountServiceName</td><td></td></tr><tr><td>BrokerAccountId</td><td>For orders places on Strategy Subaccounts (SSAs), contains the ID of the broker account to which the order has been forwarded</td></tr><tr><td>ExternalId</td><td>After transmitted to the broker, contains the ID assigned to the order by the broker</td></tr><tr><td>IsVirtual</td><td>Virtual orders are not sent to the broker and are processed internally. Virtual are all orders coming from virtual accounts, orders for synthetic contracts, and stop and market-if-touched orders.</td></tr><tr><td>CreatedAt</td><td>Timestamp of recording the order in the Accounts Service</td></tr></tbody></table>

### OrderStatus

All fields from Order plus:

<table><thead><tr><th width="217.5859375">Property</th><th>Description</th></tr></thead><tbody><tr><td>OrdStatus</td><td>Current status of the order</td></tr><tr><td>CumQty</td><td>Total filled quantity</td></tr><tr><td>LeavesQty</td><td>Remaining quantity</td></tr><tr><td>TransactTime</td><td>Last update timestamp</td></tr><tr><td>RejectReason</td><td></td></tr><tr><td>RejectText</td><td></td></tr></tbody></table>

### ExecutionReport

All fields from OrderStatus plus:

<table><thead><tr><th width="218.47265625">Property</th><th>Description</th></tr></thead><tbody><tr><td>ExecId</td><td>Unique (within Accounts Service instance) identifier of the execution report.</td></tr><tr><td>LastPx</td><td>When ExecType = Fill, the fill price for this fill</td></tr><tr><td>LastQty</td><td>When ExecType = Fill, the filled quantity (unsigned) for this fill</td></tr><tr><td>SignedLastQty</td><td></td></tr><tr><td>CalculatedCcyLastQty</td><td>Value of the trade in the settlement/quote currency (LastPx * LastQty, for futures and inverse contracts is calculated in accordance with their specification)</td></tr><tr><td>ExecType</td><td>Type of the event</td></tr><tr><td>ExecTypeReason</td><td></td></tr></tbody></table>

## Trade object

<table><thead><tr><th width="218.015625">Property</th><th>Description</th></tr></thead><tbody><tr><td>AccountServiceName</td><td></td></tr><tr><td>AccountId</td><td></td></tr><tr><td>TradeId</td><td>Unique (within Account Service instance) trade identifier</td></tr><tr><td>OrigTradeId</td><td>For allocations — reference to the originating trade</td></tr><tr><td>OrderId</td><td>Reference to the order that caused the trade</td></tr><tr><td>ExecId</td><td>Reference to the particular execution report</td></tr><tr><td>ClOrdId</td><td>ClOrdId of the order</td></tr><tr><td>ContractId</td><td></td></tr><tr><td>StrategyPositionId</td><td></td></tr><tr><td>SignalGroupId</td><td></td></tr><tr><td>PositionEffect</td><td></td></tr><tr><td>Side</td><td></td></tr><tr><td>Volume</td><td>Unsigned quantity</td></tr><tr><td>SignedVolume</td><td></td></tr><tr><td>Price</td><td></td></tr><tr><td>Commission</td><td></td></tr><tr><td>Dt</td><td>For external trades received from the broker — the timestamp provided by the broker</td></tr><tr><td>ExternalTradeId</td><td>TradeId provided by the broker</td></tr><tr><td>Commissions</td><td>For trades executed inside the platform (on virtual accounts or during the backtest) contains exact amounts for each commission</td></tr><tr><td>PaymentCurrencyId</td><td></td></tr><tr><td>FxRate</td><td>When the contract settlement (quote) currency differs from the account currency, contains the FX rate as of the moment of booking the trade</td></tr><tr><td>CalculatedCcyLastQty</td><td>Value of the trade in the settlement/quote currency (LastPx * LastQty, for futures and inverse contracts is calculated in accordance with their specification)</td></tr><tr><td>ParentPositionId</td><td>For trades that happen in the result of filling the legs of a position in a synthetic contract — the reference to the synthetic position</td></tr><tr><td>IsSynthetic</td><td>If the contract is synthetic</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantinfra.gitbook.io/quantinfra-docs/strategies/orders-and-trades.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
