Prerequisites
Before you begin, ensure you have:- API Credentials: Client ID from authentication setup
- Python 3.7+: Python development environment
- Network Access: Ability to connect to
grpc-api.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. The downloadable bundle is the canonical client contract: Download the proto files directly: polymarket-protos.zipDo not make client startup depend on gRPC reflection. Reflection availability can differ by environment.
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
Auth Domains
Obtain a JWT token using Private Key JWT authentication:
access_token:
The
expires_in is 180 seconds (3 minutes). Implement automatic token refresh before expiration.See the Authentication Setup Guide for complete authentication details.
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 JWT, refresh token if expired (tokens expire every 3 minutes)
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: polymarket
- 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 onboarding@polymarket.us for assistance