Overview
The DLOB (Decentralized Limit Order Book) is Drift’s on-chain order matching system. It aggregates all user orders and provides efficient access to market liquidity, order matching, and L2/L3 order book views.DLOB Class
Constructor
Creates a new DLOB instance.Optional map of protected maker parameters by market.
initFromUserMap
Initializes the DLOB from a UserMap.Map of user accounts containing orders.
Current blockchain slot number.
insertOrder
Inserts an order into the DLOB.The order to insert.
User account public key as string.
Current slot number.
Whether user has protected maker status.
Base asset amount for the order.
Optional callback executed after insertion.
clear
Clears all orders from the DLOB.Order Book Queries
getL2
Returns an L2 (aggregated by price level) view of the order book.Market index to query.
Market type (PERP or SPOT).
Current slot number.
Oracle price data for the market.
Number of price levels to return on each side.
Additional liquidity sources (e.g., vAMM, OpenBook).
Array of bid levels sorted by price (descending).
Array of ask levels sorted by price (ascending).
Slot number when the book was generated.
Price level in PRICE_PRECISION (1e6).
Total size at this price level.
Map of liquidity sources to sizes.
getL3
Returns an L3 (individual orders) view of the order book.Market index to query.
Market type (PERP or SPOT).
Current slot number.
Oracle price data for the market.
Individual bid orders sorted by price (descending).
Individual ask orders sorted by price (ascending).
Slot number when the book was generated.
Order price in PRICE_PRECISION (1e6).
Order size (remaining).
Public key of the order maker.
Order ID.
getBestBid / getBestAsk
Get the best bid or ask price for a market.Market index to query.
Current slot number.
Market type.
Oracle price data.
Order Matching
findNodesToFill
Finds orders that can be filled, considering both maker-taker matching and fallback liquidity.Market index.
Fallback bid price (e.g., from vAMM).
Fallback ask price (e.g., from vAMM).
Current slot.
Current timestamp.
Market type.
Oracle price data.
State account.
Market account.
The taker order node to fill.
Array of maker nodes that can fill the taker. Empty if filling against fallback liquidity.
findNodesToTrigger
Finds trigger orders (stop loss / take profit) that should be activated.Market index.
Current slot.
Current oracle price to check against.
Market type.
State account.
The trigger order that should be activated.
Trigger Orders
getStopLosses
Get all stop loss orders for a position direction.Market index.
Market type.
Position direction to get stop losses for.
getTakeProfits
Get all take profit orders for a position direction.Market index.
Market type.
Position direction to get take profits for.
DLOBSubscriber
The DLOBSubscriber automatically updates the DLOB in the background.Constructor
The Drift client instance.
Source for DLOB data (typically UserMap).
Source for current slot (typically UserMap).
Update frequency in milliseconds.
Enable protected maker view.
subscribe / unsubscribe
getL2 / getL3
Convenience methods for getting order book views.Market name (e.g., “SOL-PERP” or “SOL”). Alternative to marketIndex + marketType.
Market index (required if marketName not provided).
Market type (required if marketName not provided).
Number of levels to return (L2 only).
Include vAMM liquidity (L2 only, perp markets only).
Number of vAMM orders to generate (L2 only).
Additional liquidity sources (L2 only).
Latest slot for accurate vAMM quotes (L2 only).
DLOBNode Types
The DLOB uses different node types for different order categories:- RestingLimitOrderNode - Limit orders past auction period
- TakingLimitOrderNode - Limit orders in auction period
- FloatingLimitOrderNode - Orders with oracle price offset
- MarketOrderNode - Market orders
- TriggerOrderNode - Trigger orders (stop loss / take profit)
- SignedMsgOrderNode - Off-chain signed message orders
Example: Market Making Bot
See Also
- OrderParams - Configure orders
- Position Management - Track positions