{"id":4380,"library":"py-clob-client","title":"Polymarket CLOB Python Client","description":"A Python client library for interacting with the Polymarket Central Limit Order Book (CLOB). It provides functionalities for trading, fetching market data, and managing orders on Polymarket's platform. The library is actively developed with frequent patch and minor releases, reflecting ongoing enhancements and bug fixes.","status":"active","version":"0.34.6","language":"en","source_language":"en","source_url":"https://github.com/Polymarket/py-clob-client","tags":["polymarket","clob","crypto","trading","client","web3","polygon"],"install":[{"cmd":"pip install py-clob-client","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"ClobClient","correct":"from py_clob_client.client import ClobClient"},{"symbol":"POLYGON_CHAIN_ID","correct":"from py_clob_client.constants import POLYGON_CHAIN_ID"}],"quickstart":{"code":"import os\nfrom py_clob_client.client import ClobClient\nfrom py_clob_client.constants import POLYGON_CHAIN_ID\nfrom eth_account import Account\n\n# WARNING: Store private keys securely, e.g., in environment variables.\n# DO NOT hardcode private keys in production code.\npk = os.environ.get('POLYMARKET_PRIVATE_KEY', '0x123...abc') # Replace with your actual private key or fetch from env\nrpc_url = os.environ.get('POLYMARKET_RPC_URL', 'https://rpc.ankr.com/polygon_mumbai') # Or your preferred RPC endpoint\n\nif not pk.startswith('0x'):\n    raise ValueError(\"Private key must start with '0x'\")\n\nwallet = Account.from_key(pk)\nclob_client = ClobClient(\n    wallet=wallet,\n    rpc_url=rpc_url,\n    chain_id=POLYGON_CHAIN_ID,\n)\n\ntry:\n    markets = clob_client.get_markets()\n    print(f\"Successfully fetched {len(markets)} markets:\")\n    for market in markets[:2]: # Print first 2 markets for brevity\n        print(f\"  - {market.title} (ID: {market.market_id})\")\nexcept Exception as e:\n    print(f\"Error fetching markets: {e}\")\n    print(\"Please ensure your RPC URL and private key are correct and active.\")\n","lang":"python","description":"Initializes the ClobClient with a private key (for signing transactions) and an RPC URL. It then fetches and prints the first two available markets. Remember to manage your private key securely, preferably via environment variables."},"warnings":[{"fix":"Update your code to use `get_rfq_requester_quotes()` or `get_rfq_quoter_quotes()` as appropriate for your application logic.","message":"The RFQ quotes endpoint was split into distinct requester and quoter views. Direct calls to the old unified endpoint for RFQ quotes will break.","severity":"breaking","affected_versions":">=0.34.5"},{"fix":"Review your RFQ requester order creation logic to account for the inverted price interpretation in `v0.34.0` and later versions. Incorrect price usage could lead to unintended trade execution.","message":"The logic for RFQ requester orders was changed to invert the price. This directly affects how prices are interpreted when a requester is creating an RFQ.","severity":"breaking","affected_versions":">=0.34.0"},{"fix":"Ensure your `POLYMARKET_PRIVATE_KEY` environment variable holds a valid, active private key for a Polygon wallet. Verify your `POLYMARKET_RPC_URL` points to a working Polygon RPC endpoint (e.g., Ankr, Alchemy, Infura).","message":"The `ClobClient` requires a valid private key (for transaction signing) and an RPC URL for the Polygon network. Using an incorrect private key, an inactive key, or an invalid/unresponsive RPC URL will lead to authentication or connection errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Regularly check the GitHub releases and changelog for significant updates, especially before upgrading across minor versions. Test your integration thoroughly after updates.","message":"The library undergoes frequent updates and bug fixes. While beneficial, this can occasionally introduce subtle behavioral changes or new requirements for certain API calls, especially for advanced features like 'Post Only Orders' or 'HeartBeats'.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}