import os from py_clob_client.client import ClobClient HOST = "https://clob.polymarket.com" CHAIN_ID = 137 # Polygon chain ID def get_client(): """Return an authenticated Polymarket CLOB client.""" private_key = os.getenv("POLYMARKET_PRIVATE_KEY") proxy_address = os.getenv("POLYMARKET_PROXY_ADDRESS") if not private_key or not proxy_address: raise EnvironmentError("POLYMARKET_PRIVATE_KEY and POLYMARKET_PROXY_ADDRESS must be set in Secrets.") client = ClobClient( HOST, key=private_key, chain_id=CHAIN_ID, signature_type=2, # 2 means proxy wallet (standard for Polymarket accounts) funder=proxy_address # Your Profile address – where your funds are held ) # Automatically derive L2 API credentials from your private key api_creds = client.create_or_derive_api_creds() client.set_api_creds(api_creds) return client