I spent the last three weeks migrating my Polymarket trading system to the official US API. Here's the full walkthrough - KYC, Ed25519 credentials, Python SDK setup, and the compliance framework that keeps your bot on the right side of the CFTC.
The Regulatory Reality in March 2026
Polymarket operates under a CFTC no-action letter. That means it's legal for US persons to trade on the platform, but only through the official channels with proper KYC. The unofficial workarounds that worked in 2024 - VPNs, non-KYC wallets, frontend scraping - those are now actively monitored. Palantir's surveillance platform (announced March 10) makes enforcement real, not theoretical.
If you're building a bot for Polymarket in 2026, compliance isn't optional. It's the foundation.
Step 1: KYC Registration
Polymarket's KYC process runs through their iOS app. You'll need:
- Social Security Number (US persons only for the US API)
- Government-issued photo ID (driver's license or passport)
- Proof of address (utility bill, bank statement, or government document dated within 90 days)
The verification typically takes 24-48 hours. You can't skip this. No KYC, no API access.
Download the Polymarket iOS app, go to Settings > Verification, and follow the prompts. The app uses a third-party identity verification service - expect to take a selfie matching your ID photo.
Once verified, you'll see "Verified" status in your profile. This unlocks the developer portal.
Step 2: Generate Ed25519 API Credentials
Polymarket uses Ed25519 key pairs for API authentication - not API keys, not OAuth. This is a deliberate choice: Ed25519 signatures are fast, compact, and tied to a specific key pair rather than a session token.
From the Polymarket developer portal (accessible after KYC):
- Navigate to API Credentials
- Click Generate New Key Pair
- The portal generates an Ed25519 private key - download it immediately. It won't be shown again.
- The corresponding public key is registered with your account
Store the private key securely. I use an encrypted file on disk with restricted permissions:
# Store the key file
chmod 600 ~/.polymarket/ed25519_private.key
# Never commit this to git
echo "*.key" >> .gitignore
Your API requests get signed with this private key. Polymarket's server verifies the signature against your registered public key. No bearer tokens flying around in headers.
Step 3: Python SDK Setup
Polymarket's official Python SDK wraps all 23 REST endpoints and both WebSocket feeds. Install it:
pip install polymarket-sdk
Basic setup:
from polymarket import PolymarketClient
import os
client = PolymarketClient(
private_key_path=os.path.expanduser("~/.polymarket/ed25519_private.key")
)
# Verify connection
account = client.get_account()
print(f"Connected: {account.address}, Balance: {account.balance}")
The SDK handles Ed25519 request signing automatically. Every request includes a timestamp and signature - replay attacks are mitigated by the server rejecting signatures older than 30 seconds.
Key Endpoints You'll Use
Market data (no auth required):
# Get active markets
markets = client.get_markets(status="active", limit=50)
# Get orderbook for a specific market
orderbook = client.get_orderbook(market_id="1480650")
print(f"Best bid: {orderbook.best_bid}, Best ask: {orderbook.best_ask}")
# Get market history/candles
candles = client.get_candles(
market_id="1480650",
interval="1h",
limit=24
)
Trading (auth required):
# Place a limit order
order = client.place_order(
market_id="1480650",
side="NO",
price=0.95,
size=40.0 # in USD
)
print(f"Order ID: {order.id}, Status: {order.status}")
# Get open positions
positions = client.get_positions()
for pos in positions:
print(f"{pos.market_title}: {pos.side} @ {pos.entry_price}, shares: {pos.shares}")
# Cancel an order
client.cancel_order(order_id=order.id)
WebSocket feeds for real-time data:
import asyncio
async def stream_orderbook():
async for update in client.stream_orderbook(market_id="1480650"):
print(f"Bid: {update.best_bid}, Ask: {update.best_ask}, Spread: {update.spread}")
asyncio.run(stream_orderbook())
Step 4: Building a CFTC-Compliant Trading Loop
Here's where most bot tutorials stop at "place orders in a loop." That's not enough anymore. A compliant bot needs audit trails, risk controls, and explainable logic.
import json
import time
import logging
from datetime import datetime, timezone
from pathlib import Path
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("polymarket_bot")
class ComplianceMixin:
"""Adds audit logging and risk controls to any trading strategy."""
def __init__(self, daily_loss_limit: float = 50.0, max_position_pct: float = 0.15):
self.daily_loss_limit = daily_loss_limit
self.max_position_pct = max_position_pct
self.daily_pnl = 0.0
self.trade_log = []
self.halted = False
def log_trade(self, trade: dict):
"""Log every trade with full context for audit."""
entry = {
"timestamp": datetime.now(timezone.utc).isoformat(),
"market_id": trade["market_id"],
"side": trade["side"],
"price": trade["price"],
"size": trade["size"],
"strategy": trade.get("strategy", "unknown"),
"edge_estimate": trade.get("edge", 0),
"reason": trade.get("reason", ""),
}
self.trade_log.append(entry)
logger.info(f"TRADE: {json.dumps(entry)}")
# Persist to disk
log_path = Path(f"trade_log_{datetime.now().strftime('%Y-%m-%d')}.jsonl")
with open(log_path, "a") as f:
f.write(json.dumps(entry) + "\n")
def check_risk_limits(self, proposed_size: float, balance: float) -> bool:
"""Return False if trade would violate risk limits."""
if self.halted:
logger.warning("HALTED: Daily loss limit hit. No trades until reset.")
return False
if proposed_size / balance > self.max_position_pct:
logger.warning(f"BLOCKED: Position size {proposed_size} exceeds "
f"{self.max_position_pct:.0%} of balance {balance}")
return False
if self.daily_pnl <= -self.daily_loss_limit:
self.halted = True
logger.warning(f"HALT TRIGGERED: Daily P&L {self.daily_pnl} hit limit {self.daily_loss_limit}")
return False
return True
def update_pnl(self, realized_pnl: float):
"""Track daily P&L for kill switch."""
self.daily_pnl += realized_pnl
if self.daily_pnl <= -self.daily_loss_limit:
self.halted = True
logger.critical(f"KILL SWITCH: Daily loss {self.daily_pnl} exceeded limit")
The ComplianceMixin gives you three things regulators and surveillance systems care about:
- Full trade audit trail - every order logged with timestamp, strategy attribution, and reasoning
- Position sizing limits - no single trade exceeds 15% of balance (configurable)
- Daily loss kill switch - hard stop when cumulative losses hit the threshold
Step 5: Migrating from py_clob_client
If you're on the legacy py_clob_client library, here's the migration path:
| py_clob_client | Official SDK |
|---|---|
ClobClient(host, key) |
PolymarketClient(private_key_path) |
client.get_markets() |
client.get_markets() |
client.create_order() |
client.place_order() |
| API key in header | Ed25519 signature per request |
| No KYC required | KYC mandatory |
| CLOB-specific endpoints | Full 23-endpoint REST API |
The biggest change: authentication moves from simple API keys to Ed25519 signatures. The SDK handles this transparently, but your deployment needs to manage the private key securely.
What Compliance Looks Like Day-to-Day
Running a compliant bot isn't a one-time setup. Here's what ongoing compliance means:
Daily: Check trade logs for anomalies. Verify kill switches haven't been triggered by bugs. Review any new market categories your bot entered.
Weekly: Audit position concentration. Make sure you're not accidentally correlated across multiple markets in ways that look like manipulation.
Monthly: Review strategy performance. Update risk parameters. Check for Polymarket API changelog updates or new compliance requirements.
Immediately when news breaks: The Palantir announcement is a perfect example. New surveillance capability means re-auditing your trading patterns against what's now being monitored.
The Institutional Shift
Polymarket and Kalshi are both seeking $20 billion valuations. That kind of money doesn't come without institutional credibility. I expect a formal "algorithmic trading" tier within 8 weeks - higher position limits, compliance requirements, and probably minimum capital thresholds.
Bot developers who build compliance infrastructure now will be ready. Everyone else will be scrambling to retrofit it after getting flagged.
The prediction market bot space went from gray-zone hobby to regulated industry in about 90 days. Treat it accordingly.
This article was written with AI assistance. All technical claims, code, and architectural decisions were validated by the author.
Top comments (0)