Hybrid CLOB + AMM market

An AMM guarantees liquidity but charges slippage on every trade; a limit order book offers zero-slippage fills but only when a counterparty happens to be resting. A hybrid takes both: match a taker against resting limit orders first, and route only the unmatched remainder to the AMM backstop: the book removes the spread that deters size; the AMM removes the empty-book problem.

Complementary matching in a binary market

For a binary outcome the matchable counterparties are complementary. A buyer of YES at price $a$ and a buyer of NO at price $b$ can be paired whenever

$a + b \ge 1,$

because together they fund the mint of one YES+NO pair, which costs \$1 and always settles to \$1, each receiving the side they wanted, with no AMM involvement and no slippage. A YES taker matched against a resting NO bid at price $b$ therefore pays $1 - b$ per share. Whatever the book cannot fill is routed to an LMSR backstop, which always quotes a price. Because the two sides are complementary, taking the short side of one outcome is just buying the other, so the book needs only buy orders on each side.

Why the split matters

A large taker against an AMM alone walks up the curve, paying a rising average price and dragging the quote against itself. With a resting complementary book the same order is mostly filled at a fixed price and the AMM is barely disturbed. In the demo a 150-share YES buy costs an average $0.67$ and moves the AMM from $0.50$ to $0.82$ on its own, versus $0.49$ and a move to $0.57$ through the hybrid, most of the flow absorbed P2P at zero slippage. This is the architecture of on-chain venues that layer a P2P order book over an AMM (e.g. PulsePlay over Yellow Network state channels).

In this repo

mechanisms/hybrid_market.py provides HybridBinaryMarket(b) with rest(side, price, size) to post resting buy orders and market_buy(side, qty), which returns the P2P/AMM split, the average price, and the AMM price before and after. The demo examples/sim_hybrid_market.py contrasts an AMM-only fill with the hybrid.

Try it

Buy YES shares: the matcher first pairs you with resting NO bids (complementary, zero slippage, a NO bid at $b$ funds a YES fill at $1-b$), then routes the remainder to the LMSR backstop. Book: NO bids 2@0.40, 3@0.30. Small orders fill peer-to-peer; large ones spill into the AMM.

Code: mechanisms/hybrid_market.py · Demo: examples/sim_hybrid_market.py · Related: CFMMs, LMSR, continuous double auction · Research: gaps-and-roadmap.md