in-solana by Supanode

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

AccountDescription
MarketMarket configuration: base/quote mints, fees, lot sizes
BidsSlab data structure storing buy orders
AsksSlab data structure storing sell orders
Event heapQueue of trade and cancel events for cranking
Base vaultSPL Token account for the base token
Quote vaultSPL Token account for the quote token
Open orders accountPer-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

TypeDescription
LimitPlace an order at a specific price
MarketExecute immediately at best available price
Immediate-or-cancel (IOC)Fill what is available, cancel the rest
Post-onlyAdd to orderbook only if it won’t match immediately

Key instructions

InstructionDescription
CreateMarketCreates a new orderbook market
PlaceOrderPlaces a buy or sell order
CancelOrderCancels an existing order
ConsumeEventsCranks the event heap to settle trades
SettleFundsWithdraws settled funds to user’s wallet
CreateOpenOrdersAccountCreates 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: