Order Flow
This document details the lifecycle of orders in the CLOB system, from placement through matching to settlement.Order Placement
Limit Order Flow
Market Order Flow
Order Types
Limit Orders
Place an order at a specific price. The order rests in the book until filled or cancelled.Market Orders
Execute immediately at the best available prices.Time In Force Options
TheTimeInForce parameter controls how long an order remains active:
| Type | Behavior |
|---|---|
| GTC (Good Till Cancel) | Order remains open until filled or explicitly cancelled |
| IOC (Immediate or Cancel) | Execute what’s possible immediately, cancel the rest |
| FOK (Fill or Kill) | Execute entire quantity or cancel completely |
| PostOnly | Only add liquidity; cancel if would take liquidity |
TimeInForce Sequence
Order Matching
Matching Sequence
Price-Time Priority
Orders are matched following strict price-time priority:-
Price Priority: Best prices match first
- Highest bid vs lowest ask
- Time Priority: At the same price level, earlier orders fill first (FIFO)
Order Cancellation
Single Order Cancellation
Batch Cancellation
Self-Trade Prevention
The system prevents users from trading against their own orders using configurable STP modes:| Mode | Behavior |
|---|---|
| None | Allow self-trades |
| CancelTaker | Cancel incoming order if it would match own order |
| CancelMaker | Cancel resting order if incoming order would match |
| CancelBoth | Cancel both orders |
Batch Operations
Batch Order Placement
| Mode | Behavior |
|---|---|
atomic = true | All orders succeed or all fail |
atomic = false | Each order processed independently |
Benefits of Batching
- Gas savings: Amortize fixed transaction costs
- Atomic updates: Update multiple price levels together
- Market making: Place bid/ask pairs in single transaction
Error Handling
| Error | Cause | Resolution |
|---|---|---|
InsufficientBalance | Not enough funds for order | Deposit more funds |
InvalidPrice | Price is zero or exceeds limits | Use valid price |
InvalidPriceIncrement | Price not on valid tick | Round to valid tick |
OrderTooSmall | Below minimum order size | Increase quantity |
OrderTooLarge | Exceeds maximum order size | Reduce quantity |
PostOnlyWouldTake | Post-only order would cross | Use different price |
FillOrKillNotFulfilled | FOK order can’t fully fill | Use IOC or adjust size |
SlippageExceeded | Execution worse than limit | Increase slippage tolerance |