Skip to main content
Before committing to a firm RFQ quote, it’s often worth knowing roughly what a specific size would execute at. The depth carried on the price stream is enough to compute a volume-weighted average price (VWAP) on your side - a dependable indicative number for any trade size, calculated locally and instantly.
Typical scenario: you’re deciding whether an intent is worth bidding on. Rather than burning a rate-limited firm quote that expires in seconds, you derive the likely execution price straight from the live stream and only go firm when the trade clears your bar.

The Idea

Stream levels arrive as (price, size) pairs, best price first. Pricing a target size means consuming those levels in order - best to worst - until the target is covered. The VWAP is then simply total quote spent over total base received: the blended price of everything you’d have eaten through.

Walking the Book

The Four Moves

1

Order the levels

Buying? Consume asks, cheapest first. Selling? Consume bids, richest first.
2

Consume level by level

A level’s capacity is price × size. Fill from it up to whatever target remains - the final level usually gets consumed only partially.
3

Blend the totals

Keep running sums of base filled and quote spent; dividing one by the other yields the VWAP.
4

Notice when depth runs out

A positive remainder after the last level means the stream can’t absorb your size - go straight to a firm quote, or split the trade across sources.

Putting It on the Stream

Wire the estimator into the WebSocket connection from the Quickstart and it re-prices on every snapshot:
A $250,000 WETH/USDC run prints something like:
A streamed VWAP is an estimate, nothing more. The firm quote you eventually request can land elsewhere - LP inventory shifts, time passes, and quote-level parameters apply. Treat it as a filter, not a promise.

Watch-outs

  • A leftover means the book is too thin. When unfilled > 0, the streamed depth can’t take your size - request a firm quote or break the trade up instead of trusting the partial number.
  • Size is what separates VWAP from top-of-book. Tiny clips track the best level closely; real size digs into worse levels, and quantifying exactly how much worse is why you’re computing this at all.
  • Depth profiles differ pair to pair. Identical top-of-book prices can hide wildly different books underneath - always estimate at your true size instead of extrapolating.
  • Never reuse an old estimate. The stream refreshes constantly; recompute on every message rather than holding onto a number that’s already stale.