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:
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
Authenticate by sending your API key as a Bearer token in the
Authorization header on the connection handshake.
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:
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.