Typical scenario: a WETH/WBTC swap lands on your desk, and no direct pair exists on the stream - but both legs against USDC do. Deriving the cross rate from streamed depth tells you whether the route is competitive before you spend a firm quote on it.
Two Legs, One Rate
To price a WBTC purchase paid in WETH when only the USDC pairs stream, split the trade conceptually:- Leg one: WETH out - your WETH sells into the WETH/USDC bids
- Leg two: WBTC in - the resulting USDC buys from the WBTC/USDC asks
The Recipe
1
Map what's streaming
Index every pair in the snapshot, then intersect: which quote tokens do both of your base tokens trade against? (
find_common_quotes below.)2
Choose your bridge
Several candidates? Take the one with real depth on both sides - in practice that’s usually a major stablecoin, but let the data decide.
3
Price each leg on its own
Run the VWAP walk per leg: bids for the leg where you’re selling, asks where you’re buying.
4
Divide
Leg-one VWAP over leg-two VWAP - that quotient is your size-aware cross rate.
Discovering Bridge Tokens
Every pair on the network rides the same stream, so bridge discovery is a set intersection over the snapshot you already have. Don’t bake assumptions in: which tokens serve as common quotes differs chain to chain. Stablecoins show up often, but the snapshot itself is the only reliable answer.Deriving the Cross Rate
With a bridge chosen, price both legs and take the ratio:On the Live Stream
Plugged into the WebSocket connection from the Quickstart, the whole pipeline re-derives the cross rate on every snapshot:Watch-outs
- Per-leg VWAP or nothing. The two books almost never share a depth profile, so top-of-book ratios mislead exactly when size matters - blend each leg at your true notional.
- A thin leg poisons the whole number. Any unfilled remainder on either side makes the cross rate unreliable at that size; treat it as no-quote.
- Bridge quality is depth on both sides. Given multiple shared tokens, the right bridge is the one that absorbs your size twice - once per leg.
- Rediscover bridges from the data. The set of shared quote tokens shifts by chain and by snapshot; recompute it rather than pinning yesterday’s answer.