What you’ll build: A WebSocket client that receives and decodes real-time pricing data.Time required: 10-15 minutesPrerequisites: Python 3.10+, uv (or pip), and an API key from Bebop.
1. Set Up Protobuf
The Price API encodes messages using Protocol Buffers for compact, low-latency delivery. You’ll need to generate Python bindings from the schema.Define the Schema
Createbebop.proto:
PriceUpdate contains:
| Field | Description |
|---|---|
base | Base token contract address (raw bytes) |
quote | Quote token contract address (raw bytes) |
last_update_ts | Timestamp of the last price update (milliseconds) |
bids | Flat array of floats: [price₁, size₁, price₂, size₂, ...] |
asks | Flat array of floats: [price₁, size₁, price₂, size₂, ...] |
Generate Python Bindings
Install the protobuf compiler tools and generate the Python module:bebop_pb2.py - the module you’ll import to decode messages.
2. Connect to the WebSocket
The pricing stream is available at:Connection Parameters
| Parameter | Required | Description |
|---|---|---|
format | Yes | Set to protobuf |
name | Yes | Your integration name (for identification) |
authorization | Yes | Your API key |
gasless | No | false for self-execution quotes (default), true for gasless quotes |
expiry_type | No | short or standard (default) - controls quote expiry window |
Open the Connection
3. Decode the Price Data
Each message contains updates for multiple trading pairs. To extract pricing for a specific pair, match on thebase and quote addresses.
Resolve Token Addresses
(optional) First, look up the contract addresses for the tokens you want:Parse Bids and Asks
Thebids and asks fields are flat float arrays encoding (price, size) pairs:
Understanding the Levels
Bids are ordered best (highest) first, asks are ordered best (lowest) first. Each level represents a price point with available size in base token units. For example, ifbids = [2450.50, 1.5, 2449.80, 3.0], that means:
| Level | Price | Size |
|---|---|---|
| 1 | 2450.50 | 1.5 WETH |
| 2 | 2449.80 | 3.0 WETH |
4. Full Example
Putting it all together - a complete script that connects, resolves a trading pair, and prints live pricing:Prices are indicative. The Price API streams real-time market data for monitoring and pre-trade analysis. To get firm, executable quotes, use the RFQ API.
Next Steps
RFQ API Quickstart
Execute trades against the prices you’re streaming.
Price API Reference
Message types, connection limits, and coverage details.