OpenBook V2 — Program ID & Overview
opnb2LAfJYbRMAHHvqQ9zMZehFSABFig61s9JbLLaZc OpenBook V2 is a decentralized central limit orderbook (CLOB) on Solana. It is the successor to Serum/OpenBook V1 and provides on-chain matching of limit and market orders. AMMs like Raydium AMM V4 integrate with OpenBook markets for hybrid liquidity.
Program ID
opnb2LAfJYbRMAHHvqQ9zMZehFSABFig61s9JbLLaZc
Market structure
| Account | Description |
|---|---|
| Market | Market configuration: base/quote mints, fees, lot sizes |
| Bids | Slab data structure storing buy orders |
| Asks | Slab data structure storing sell orders |
| Event heap | Queue of trade and cancel events for cranking |
| Base vault | SPL Token account for the base token |
| Quote vault | SPL Token account for the quote token |
| Open orders account | Per-user account tracking their open orders |
Key concepts
Lot sizes: Prices and quantities are expressed in lots. The base lot size determines the minimum quantity increment, and the quote lot size determines the minimum price increment.
Cranking: OpenBook uses an event heap to record matches. Events must be “cranked” (consumed) by a separate transaction to finalize settlements and update user balances.
Order types
| Type | Description |
|---|---|
| Limit | Place an order at a specific price |
| Market | Execute immediately at best available price |
| Immediate-or-cancel (IOC) | Fill what is available, cancel the rest |
| Post-only | Add to orderbook only if it won’t match immediately |
Key instructions
| Instruction | Description |
|---|---|
CreateMarket | Creates a new orderbook market |
PlaceOrder | Places a buy or sell order |
CancelOrder | Cancels an existing order |
ConsumeEvents | Cranks the event heap to settle trades |
SettleFunds | Withdraws settled funds to user’s wallet |
CreateOpenOrdersAccount | Creates a user’s open orders account |
FAQ
What is the difference between OpenBook V1 and V2? V2 is a full rewrite built with Anchor. It uses an event heap instead of a request queue, supports Token-2022, has improved permissioning, and is more gas-efficient. V1 (originally Serum) is deprecated.
Why is cranking necessary? Cranking separates trade matching from settlement. The event heap records matches during order placement. A separate crank transaction processes these events to update balances. This design allows higher throughput.
Can I build a trading bot on OpenBook? Yes. You need to create an open orders account, then place and manage orders through the program. The main challenge is managing the cranking mechanism and monitoring the orderbook state for price updates.
Updated: