Conditional & algorithmic orders
Conditional and algorithmic orders are executed by the protocol itself at the end of a block once their condition is met. Execution always goes through the book at the prices of its orders.
Conditional orders
| Order | Message | What it does |
|---|---|---|
| Stop-loss | MsgSetStopLoss | Closes the position when the oracle price reaches the trigger against the position |
| Take-profit | MsgSetTakeProfit | Closes the position when the oracle price reaches the trigger in the position's favour |
| Brackets | MsgSetBracketOrders | A stop-loss and take-profit pair. When one fires, the other is cancelled |
| Trailing stop | MsgSetTrailingStop | The trigger follows the best price at a set percentage distance. It can start only after an activation price |
| ENTRY | MsgSetEntryOrder | Opens a position when the oracle price reaches the trigger. It can set brackets at once and have an expiry |
How they work
- Trigger. The trigger is compared with the oracle price. For a long, a stop-loss fires at or below the trigger and a take-profit at or above it. For a short it is the reverse.
- Execution. The protocol sends a market reduce order through the book. With a limit price, the order never fills worse than that price. If only part fills, the rest waits for the next blocks.
- Share of the position.
- A partial percentage is taken from the position at the moment the order is created, so a 33/33/34 ladder closes the whole position.
- 100% means the whole position at the moment of firing.
- Brackets on an order.
MsgAttachOrderBracketsattaches a stop-loss and a take-profit to an order in the book. They take effect once it fills. - ENTRY.
- Opens a position of the set size and leverage, at market or at a limit price.
- Until the position is fully built, the rest is filled in the following blocks.
- If an expiry is set, an unfilled ENTRY is cancelled when it ends.
- Closing the position. All conditional orders of a position are cancelled together with it.
TWAP
TWAP splits a size into equal parts and executes them at a set block interval. Each part is a market order through the book.
| Variant | Message | What it does |
|---|---|---|
| Close | MsgCreateTwapOrder | Reduces a position. It finishes when the position is closed |
| Open | MsgCreateOpenTwapOrder | Opens a position with the set leverage |
An unfilled part of a single slice is not retried on its own; it moves into the last slice. From 2 to 100 slices, an interval from 1 to 100,000 blocks. Cancel with MsgCancelTwapOrder.
POV
POV executes a set share of market volume (from 1% to 30%) over a period. A POV whose largest slice is below 10 USDC is not accepted.
Chase
MsgSetChase makes a limit order in the book follow the market:
- Repricing. Every block the order moves to the best price of its side, shifted by
offset. - Limit. The order does not move further than
max_distancefrom the price at the moment chase was turned on. At the limit, chase stops. - Post-only. A post-only order does not cross the book when moved.
Turn chase off with MsgCancelChase.
When orders wait
While a market is paused, or its oracle pair is paused or under a circuit breaker, conditional and algorithmic orders for it do not execute and wait. During a trading halt, the ones that open a position wait.
Limits
| Limit | Value |
|---|---|
| Conditional orders per position | 10 |
| Conditional orders per user | 50 |
| Brackets waiting for an order to fill, per subaccount | 500 |
| Conditional order firings per block | 500, the rest in the next block |
| TWAP per user | 20 |
| Chase per user | 10 |
| POV per user | 5 |