Larzscript Flagship Projects

LarzExchange — A Real Limit Order Book, Built in Larzscript

A resting order is a real commitment the instant it's placed — funds locked in escrow before any match happens. One incoming order can sweep through several resting orders at different prices in a single call, each fill settling at its own maker's price, not the taker's limit.

What LarzExchange actually does

Placing an order locks the money or inventory it could need immediately — the same escrow.open() shape as LarzBounty's post(). Matching always executes at whichever order was already resting in the book, the standard "maker sets the price" rule, which means a buy can fill at a genuinely better price than its own limit.

Every line below is the real output of a fresh run against the actual interpreter — re-run fresh for this page, not copied from documentation. Bob and carol rest sell orders at two different prices before alice's single buy call crosses both.

larzexchange sell $mid bob   5  9.00
larzexchange sell $mid carol 5  9.50
larzexchange buy  $mid alice 10 10.00   # one call, crosses BOTH
Output
alice: $907.5   (paid 9.00 + 9.50 - not her own 10.00 limit)
bob:   $1045    (sold 5 @ $9.00)
carol: $1047.5  (sold 5 @ $9.50)

Alice's own limit was $10.00 a unit, but she never pays it — she settles at bob's $9.00 and carol's $9.50, the makers' own resting prices. The leftover slack in her escrow (what she'd have paid at her own limit) is refunded immediately after the fill, not just on cancellation.

larzexchange sell   $mid bob   20 8.00
larzexchange buy    $mid alice 5  8.00   # partial fill
larzexchange buy    $mid alice 3  1.00   # too cheap to ever match
larzexchange cancel $mid $bid  buy
Output
book: bob  15 @ $8.00   (20 offered, 5 filled, 15 still resting)
alice: $864.5 -> $867.5   (full $3.00 refund on cancel)

Bob's 20-unit sell order was bigger than alice's next buy could take, so it partially fills — 15 units stay open, resting in the book. And alice's order at $1.00 was never going to match anything; cancelling it refunds the full $3.00 she'd escrowed, dollar for dollar.

Why it matters

Every project before this one in the series is built around one require gating a single transaction. LarzExchange is different in kind — the interesting part is a matching ALGORITHM, continuous price-time priority with partial fills, not one clever refusal. It still leans on the same escrow package the course's error-handling lesson and Money-Native Basics lesson cover — wallet, pay, and require composed into a real continuous market instead of one transaction's refusal logic.

View source on GitHubFlagship ProjectsLarzscript Course