Polymarket CLOBClient V2
raw JSON → 1.0.0 verified Sat May 09 auth: no python
Python client for interacting with the Polymarket CLOB (Central Limit Order Book) V2 API. Version 1.0.0 is the latest stable release, with a release candidate 1.0.1rc1 available. Requires Python >=3.9.10. Maintained actively on GitHub.
pip install py-clob-client-v2 Common errors
error AttributeError: module 'py_clob_client' has no attribute 'ClobClient' ↓
cause Incorrect import path. `ClobClient` is under `py_clob_client.client`.
fix
Use
from py_clob_client.client import ClobClient. error py_clob_client.client.Credentials.__init__() got an unexpected keyword argument 'private_key' ↓
cause Passing private_key directly to ClobClient constructor (old style) instead of creating a Credentials object.
fix
Create a Credentials object first:
creds = Credentials(private_key=key, chain_id=137) then pass to ClobClient. error requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://clob.polymarket.com/... ↓
cause Invalid or missing credentials (private key not set, incorrect chain_id, or expired signature).
fix
Check that environment variable PRIVATE_KEY is set correctly and chain_id is 137 for Polygon Mainnet.
Warnings
gotcha The library's release versions do not follow strict semver; 1.0.1rc1 is a pre-release and may contain breaking changes. ↓
fix Pin to 1.0.0 for production unless you need the features in 1.0.1rc1.
gotcha Private key must be in hex format without 0x prefix. Incorrect formatting will cause silent failures. ↓
fix Ensure private key is a hex string (64 characters) without '0x'.
deprecated The `getHeartbeat()` method (camelCase) is deprecated in v1.0.0; use `get_heartbeat()` instead. ↓
fix Replace `getHeartbeat()` with `get_heartbeat()`.
breaking In v1.0.0, the `Credentials` class was introduced and the constructor changed. Passing a raw private key string directly is no longer supported. ↓
fix Use from py_clob_client.clob_types import Credentials and pass Credentials object.
Imports
- ClobClient
from py_clob_client.client import ClobClient - PolymarketCredentials
from py_clob_client.client import Credentials
Quickstart
import os
from py_clob_client.client import ClobClient
from py_clob_client.clob_types import Credentials
host = "https://clob.polymarket.com"
key = os.environ.get('PRIVATE_KEY', '')
creds = Credentials(private_key=key, chain_id=137)
client = ClobClient(host=host, credentials=creds)
print(client.get_heartbeat())