Order Structure
Every order in Drift has a comprehensive structure tracking its state and parameters:sdk/src/types.ts
Order Types
Drift supports several order types with different execution characteristics:sdk/src/types.ts
Market Orders
Market orders execute immediately at the best available price:- Fill against the AMM or matching limit orders
- May use Dutch auction for better price discovery
- No price limit (except max slippage from auction)
- Default auction duration: configured per market
Market orders use a brief Dutch auction by default, starting at a premium/discount to the oracle price and converging toward the oracle price over time.
Limit Orders
Limit orders specify a maximum/minimum price:- Long: Fill at
priceor better (lower) - Short: Fill at
priceor better (higher) - Rest on the orderbook if not immediately fillable
- Can be maker or taker depending on execution
Trigger Orders
Trigger orders activate when a condition is met: Trigger Market: Becomes a market order when triggered Trigger Limit: Becomes a limit order when triggeredsdk/src/types.ts
Oracle Orders
Oracle orders use an offset from the oracle price:oraclePrice + oraclePriceOffset
This allows orders to automatically track the oracle price.
Order Parameters
When placing an order, you specify parameters:sdk/src/types.ts
Post-Only Orders
sdk/src/types.ts
- MUST_POST_ONLY: Transaction fails if order would immediately fill
- TRY_POST_ONLY: Order is skipped if it would immediately fill
- SLIDE: Price is adjusted to guarantee maker execution
Reduce-Only Orders
Reduce-only orders can only decrease position size:- Cannot open a new position
- Cannot increase existing position
- Cannot flip position direction
- Commonly used for stop-loss and take-profit orders
Immediate-or-Cancel (IOC)
IOC orders attempt to fill immediately and cancel any unfilled portion:sdk/src/types.ts
immediateOrCancel: true or in bitFlags.
Time-in-Force
Orders can have an expiration time:Order Status
sdk/src/types.ts
Order Execution
Dutch Auction Mechanism
Most orders use a Dutch auction for better price discovery:- Auction Start: Order starts at a premium (buy) or discount (sell)
- Price Improvement: Price moves toward oracle price over time
- Auction End: After
auctionDurationslots, fills at oracle price - Early Fill: Can fill at improved price during auction
sdk/src/math/auction.ts
auctionStartPrice and auctionEndPrice based on slots elapsed.
Order Matching
Orders can be filled through multiple sources:- DLOB Matching: Against resting limit orders
- AMM Fill: Against the protocol AMM
- JIT (Just-in-Time) Auction: Keeper provides liquidity during auction
- External DEX: Through Serum, Phoenix, or OpenBook v2
sdk/src/types.ts
Fill Price Priority
When matching orders, the best price for the taker is selected:- For buys: lowest price wins
- For sells: highest price wins
- Considers all available liquidity sources
- Auction mechanism provides time for price competition
Scale Orders
Place multiple orders across a price range:sdk/src/types.ts
Order Events
Order actions emit events:sdk/src/types.ts
Order Management
Modifying Orders
Orders can be modified with certain constraints:sdk/src/types.ts
- MustModify: Transaction fails if order cannot be modified
- ExcludePreviousFill: Ignore fills that occurred in the same slot
Cancelling Orders
Orders can be cancelled:- By the user at any time
- Automatically when expired (
maxTsreached) - When user is liquidated (risk-increasing orders)
- When reduce-only conditions are violated
Protected Maker Mode
Markets can enable protected maker mode for certain users:sdk/src/types.ts
Next Steps
Positions
See how orders create and modify positions
Markets
Understand market mechanics for order execution
Margin System
Learn margin requirements for orders
SDK Guide
Implementation guide for placing orders