Documentation Index
Fetch the complete documentation index at: https://docs.swarms.world/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This tutorial shows how to build autonomous prediction market agents using Swarms with the Polymarket and Kalshi APIs. You will build agents that discover markets, estimate probabilities, find edges against market odds, and execute trades programmatically. We cover a single-agent pattern for simple market analysis and a multi-agent swarm pattern with specialized research, analysis, risk, and execution agents.Prerequisites
Dependencies
API Keys & Accounts
Polymarket Setup
Polymarket Setup
- Create a wallet on Polymarket and fund it with USDC on Polygon
- Export your private key from your wallet
- Derive API credentials using the py-clob-client SDK (shown below)
- Set environment variables:
Kalshi Setup
Kalshi Setup
LLM API Key
LLM API Key
Set your OpenAI key (or any provider supported by Swarms):
Part 1: Market Discovery Tools
Before building agents, we need tools that can fetch market data from both platforms.Polymarket Market Discovery
Polymarket uses three APIs: Gamma (market discovery), CLOB (pricing/trading), and Data (positions).Kalshi Market Discovery
Kalshi uses RSA-PSS signature authentication. Market discovery endpoints are public (no auth needed).Part 2: Single-Agent Pattern
A single agent that discovers markets, reasons about probability, and identifies edges.Part 3: Multi-Agent Swarm Pattern
For serious trading, use a multi-agent swarm with specialized roles. Each agent has a focused responsibility, and they work together in a sequential pipeline.Execution Tools
First, build the tools for actually placing trades (with dry-run support):Agent Definitions
Running the Swarm
- Research Agent discovers markets and gathers context
- Analyst Agent estimates probabilities and identifies edges
- Risk Agent filters, sizes positions, and enforces limits
- Execution Agent places the approved orders (dry-run by default)
Part 4: Guardrails & Best Practices
Dry-Run Mode
TheDRY_RUN = True flag at the top of the execution tools prevents any real orders from being placed. Set it to False only when you are confident in the system.
Position Limits
The risk agent enforces these limits, but you should also add hard-coded checks:Logging
Log every agent decision and trade for audit purposes:Demo / Paper Trading
- Kalshi: Use the demo environment at
https://demo-api.kalshi.co/trade-api/v2with a separate demo account. ChangeKALSHI_BASEtoKALSHI_DEMO_BASE. - Polymarket: There is no official testnet. Use
DRY_RUN = Truefor simulation, or trade with very small sizes ($1-5) on mainnet.
Next Steps
Financial Analysis System
Multi-agent market analysis with MixtureOfAgents.
Gold ETF Research
Research swarm with web search tools.