Use case: You’re a solver or aggregator routing a WETH/WBTC swap. The Price API stream doesn’t have a direct WETH/WBTC pair, but it does have WETH/USDC and WBTC/USDC. Instead of requesting a firm quote blind, you estimate the synthetic price from streamed depth to decide if Bebop is competitive for this route.
How It Works
Say you want an indicative price for buying WBTC with WETH, but the stream only has WETH/USDC and WBTC/USDC. You construct the synthetic rate in two legs:- Sell WETH for USDC - use the WETH/USDC bids (you’re selling the base)
- Buy WBTC with USDC - use the WBTC/USDC asks (you’re buying the base)
Step-by-Step Breakdown
Scan the stream for common quote tokens
Build a map of all pairs in the stream. For the two base tokens you care about, find quote tokens they both share using
find_common_quotes.Pick the best routing token
If multiple common quotes exist, prefer the one with the deepest liquidity on both legs. Stablecoins like USDC tend to have the most depth.
Estimate VWAP on each leg
Use the VWAP algorithm on each leg independently. For a buy, consume bids on leg 1 (selling your input token) and asks on leg 2 (buying your target token).
Finding the Common Quote Token
The Price API streams all available pairs on the network. To find routing opportunities, scan the stream for pairs that share a common quote token. Common quote tokens vary by chain - look at what’s actually in the stream rather than hardcoding assumptions. On most EVM chains, stablecoins like USDC tend to appear frequently as quote tokens, but the stream is the source of truth.Calculating the Synthetic Price
Once you’ve identified a common quote token, estimate the VWAP on each leg and combine them.Full Example
Combining synthetic pair estimation with the Price API stream from the Quickstart:Key Considerations
- Use VWAP on each leg. Top-of-book prices can be misleading because tier cadence (the size available at each level) often differs between pairs. VWAP gives you a size-aware estimate.
- Check for sufficient depth on both legs. If either leg returns unfilled notional, the synthetic estimate is unreliable at that size.
- Pick the deepest routing token. When multiple common quotes exist, prefer the one with the most liquidity on both sides.
- The stream is the source of truth for available pairs. Common quote tokens vary by chain - discover them from the data rather than hardcoding.