Initialize a fully-authenticated ClobClient
mainAuthentication in the CLOB client occurs in two levels:
- L1 (Wallet Signature): Uses your private key (EIP-712) to create or derive API credentials.
- L2 (HMAC): Uses the derived
ApiCreds(API Key, Secret, and Passphrase) for performing actions like order placement, cancellation, and accessing account data.
To use the client for trading, you must first perform L1 authentication to get credentials, then re-initialize the client with those credentials for L2 authentication.
import os
from py_clob_client_v2 import ClobClient, ApiCreds
host = "<polymarket-clob-host>"
chain_id = 137 # or 80002 for Amoy testnet
# Step 1: L1 Auth - Obtain API credentials using your wallet
client = ClobClient(host=host, chain_id=chain_id, key=os.environ["PK"])
creds = client.create_or_derive_api_key()
# Step 2: L2 Auth - Initialize fully-authenticated client
client = ClobClient(host=host, chain_id=chain_id, key=os.environ["PK"], creds=creds)