Getting Started
This guide will help you set up gRPC streaming with Python and connect to your first data stream in minutes.Prerequisites
Before you begin, ensure you have:- API Credentials: Username and password for the Polymarket Exchange
- Python 3.7+: Python development environment
- Network Access: Ability to connect to
traderapi.us-east-1.privatelink.preprod.polymarketexchange.com:443
Step 1: Install Python gRPC Libraries
grpcio: gRPC runtime librarygrpcio-tools: Tools for generating Python code from proto filesprotobuf: Protocol buffer runtimerequests/httpx: For REST API authentication
Step 2: Obtain Protocol Buffer Definitions
Proto files define the gRPC service interfaces and message structures. You can obtain them in two ways:Option A: Download Proto Files
Download the complete proto package: trading-gateway-protos.zip This package contains all proto files needed for gRPC streaming:connamara/ep3/v1beta1/market_data.protoconnamara/ep3/v1beta1/order_entry.protoconnamara/ep3/orders/v1beta1/orders.protoconnamara/ep3/instruments/v1beta1/instruments.protoconnamara/ep3/type/v1beta1/common.proto
Option B: Use Server Reflection
Server reflection allows you to discover service definitions at runtime without proto files. This is useful for dynamic clients and debugging.
Step 3: Generate Python Client Code
Once you have the proto files, generate Python client code:*_pb2.pyfiles: Message definitions*_pb2_grpc.pyfiles: Service stubs
Step 4: Authenticate via REST API
Obtain a JWT token from the REST API (curl example):Step 5: Connect to Market Data Stream
Create your first streaming connection:Price Representation: All prices are
int64 values. Divide by the instrument’s price_scale to get the decimal price.price_scale varies by instrument. Get it from:- Instrument metadata via
list_instrumentsorget_instrument_metadata - The
price_scalefield in order responses
Common Setup Issues
Connection Refused
- Cause: Firewall blocking outbound gRPC connections
- Solution: Ensure port 443 is open for outbound connections
Authentication Failed
- Cause: Invalid or expired access token
- Solution: Verify token from REST login, check expiration time
Import Errors
- Cause: Generated proto files not in Python path
- Solution: Ensure proto files are generated in the correct directory, or add to
PYTHONPATH:
Module Not Found: connamara
- Cause: Proto files not generated or in wrong location
- Solution: Re-run the
protoccommand from step 3, ensure you’re in the correct directory
Next Steps
Authentication Guide
Deep dive into authentication and token management
Market Data Streaming
Learn about all market data streaming features
Order Streaming
Subscribe to order execution updates
Need Help?
If you encounter issues during setup:- Check the Error Handling Guide
- Review the Market Data Stream or Order Stream pages for complete implementations
- Contact support@qcex.com for assistance

