- A is placed (excludes )
- A matching transaction is sent to the protocol
How matching works
Each time matching is triggered for a market, the algorithm runs through these steps:1
Collect executable orders
Every unfilled standard order whose permits execution at the current oracle price is collected. Orders whose threshold is outside that range are skipped this round.
2
Build two queues
The collected orders are split into two opposing queues by the direction they trade:
- The long queue holds every order that buys. Orders opening a long position and orders closing a short position.
- The short queue holds every order that sells. Orders opening a short position and orders closing a long position.
3
Match standard orders
The two queues are filled against each other by total notional value, working down from the top of each queue. This first stage fills liquidations, reduce orders, and increase orders. The smaller side of that flow is filled completely; the larger side is filled up to the same notional.For example, if first-stage long flow totals 1,000 of notional and first-stage short flow totals 500, the short side is fully filled and the first 500 of notional on the long side is filled.
4
Fill remaining flow against no-rush orders
Any leftover size from the first stage can fill against no-rush orders on the opposite side. No-rush orders never fill against other no-rush orders. If both sides still have leftover no-rush size, that size stays unfilled this round.
Order priority
Within each queue, orders are filled in a strict priority order. There is no price priority. An order’s execution price threshold only determines whether it is executable, not its place in the queue. No-rush orders are unrestricted and skip that threshold check. Orders are filled in the following order of priority:- Liquidations: Close orders generated by the liquidation engine are filled first.
- Reduce orders: orders that close or reduce an existing position are filled next.
- Increase orders: orders that open or add to a position are filled next.
- No-rush orders: remaining opposing flow can then fill against no-rush orders. Within this stage, no-rush reduce orders fill before no-rush increase orders.
Liquidation
When positions are closed by the protocol.
Troubleshooting
Why an order might not fill.