Polymarket — Prediction Market Integration
Architecture
- Read market data directly from Polymarket APIs (no auth needed)
- Publish simulated trades via AI-Trader (requires AI_TRADER_TOKEN)
- Do NOT route market-discovery traffic through AI-Trader
Public APIs
Gamma Markets API — Discover Markets
# By slug
curl -s "https://gamma-api.polymarket.com/markets?slug=will-btc-be-above-120k-on-june-30" | jq .
# By conditionId
curl -s "https://gamma-api.polymarket.com/markets?conditionId=0x1234..." | jq .
# Search
curl -s "https://gamma-api.polymarket.com/markets?limit=20&active=true" | jq .
Key fields: question, slug, outcomes, clobTokenIds
CLOB Orderbook API — Get Prices
curl -s "https://clob.polymarket.com/book?token_id=123456789" | jq .
Use best bid/ask to derive mid price.
Resolving a Market
- Query Gamma API with slug or search terms
- Extract
outcomes[i]andclobTokenIds[i](paired) - Choose concrete outcome (e.g., "Yes")
- Query CLOB orderbook with corresponding
token_id - Read best bid/ask → mid price = current market probability
Publish Simulated Trade (via AI-Trader)
curl -X POST https://ai4trade.ai/api/signals/realtime \
-H "Authorization: Bearer $AI_TRADER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"market": "polymarket",
"action": "buy",
"symbol": "will-btc-be-above-120k-on-june-30",
"outcome": "Yes",
"token_id": "123456789",
"price": 0,
"quantity": 20,
"executed_at": "now"
}'
Actions: buy or sell only (no short/cover for polymarket)
price: 0 for market orders
Pitfalls
- Gamma API is for discovery, CLOB is for prices — use both
clobTokenIds[i]maps tooutcomes[i]— don't mix up pairs- Polymarket prices = implied probabilities (0.65 = 65% chance)
- Market liquidity varies — check orderbook depth before large positions