Sample Code
This section provides complete, working Python code samples to help you test trading functionality using the Polymarket Trading Gateway pre-production environment.About the Trading Gateway
The Trading Gateway provides core trading functionality. It uses:- Username/password authentication (not API keys)
- Token-based authorization with access_token and refresh_token
- REST API for trading operations
- gRPC streaming for real-time market data and order updates
These samples are for the Trading Gateway (core trading APIs). For the Exchange Gateway (comprehensive trading and non-trading functionality including payments, KYC, and broader account management), visit apidocs.polymarketexchange.com.
Available Samples
REST API Client
polymarketus_client.py - Complete REST API client with interactive CLI
Features:
- Username/password authentication
- Account management
- Order placement and cancellation
- Order queries
- Bulk operations
gRPC Streaming Clients
market_data_stream.py - Stream real-time market data
- Order book updates
- Trade data
- Instrument statistics
order_stream.py - Stream order and execution updates
- New order confirmations
- Fill notifications
- Order state changes
Prerequisites
Install Dependencies
Download Proto Files
Download the protocol buffer definitions: Download trading-gateway-protos.zip Extract and generate Python code:Pre-Production Endpoints
All sample code connects to the pre-production testing environment: REST API:These samples are configured for pre-production testing only. Contact your account manager for production credentials and endpoints when you’re ready to go live.

