Back to Blog

Polymarket vs Kalshi API: Beginner Tutorial (2025)

10 minPredictEngine TeamTutorial
# Polymarket vs Kalshi API: Beginner Tutorial (2025) If you want to automate trades on prediction markets, **Polymarket** and **Kalshi** are the two most important platforms to understand — and both offer public APIs you can start using today. Polymarket is a decentralized crypto-based market running on Polygon, while Kalshi is a regulated US exchange offering federally legal event contracts. This guide walks you through both APIs from scratch, comparing authentication, endpoints, and practical use cases so you can start building in under an hour. --- ## Why Use APIs for Prediction Market Trading? Manual trading on prediction markets works fine when you're placing a handful of bets per week. But the moment you want to **monitor dozens of markets simultaneously**, react to price changes in real time, or run systematic strategies, you need programmatic access. APIs give you: - Real-time market data without refreshing a browser - The ability to place and cancel orders automatically - Historical data for backtesting strategies - Integration with external signals (news feeds, sports APIs, financial data) Platforms like [PredictEngine](/) are built on top of exactly this kind of API access — aggregating data, running models, and executing trades faster than any human could manually. Whether you're building a simple price monitor or a full [AI trading bot](/ai-trading-bot), understanding the raw API layer is essential. Let's start with the basics of each platform. --- ## Polymarket API: How It Works Polymarket operates on the **Polygon blockchain**, which means its API architecture is different from traditional financial APIs. There are actually two layers you interact with: 1. **The CLOB (Central Limit Order Book) API** — for placing and managing orders 2. **The Gamma API** — for fetching market metadata, prices, and outcomes ### Polymarket Authentication Polymarket uses **API keys tied to an Ethereum-compatible wallet**. Here's how to get started: 1. Create a wallet (MetaMask or similar) and fund it with USDC on Polygon 2. Visit `clob.polymarket.com` and generate API credentials 3. You'll receive an **API key**, **secret**, and **passphrase** 4. All authenticated requests use HMAC-SHA256 signing A basic Python setup looks like this: ```python import requests import hmac import hashlib import time API_KEY = "your_api_key" SECRET = "your_secret" PASSPHRASE = "your_passphrase" def get_headers(method, path, body=""): timestamp = str(int(time.time())) message = timestamp + method + path + body signature = hmac.new(SECRET.encode(), message.encode(), hashlib.sha256).hexdigest() return { "POLY-API-KEY": API_KEY, "POLY-SIGNATURE": signature, "POLY-TIMESTAMP": timestamp, "POLY-PASSPHRASE": PASSPHRASE } ``` ### Fetching Markets on Polymarket The **Gamma API** (public, no auth required) is the easiest entry point: ```python response = requests.get("https://gamma-api.polymarket.com/markets?limit=20") markets = response.json() ``` Each market object includes: - `conditionId` — unique identifier - `question` — the yes/no question text - `outcomePrices` — current bid/ask prices (expressed as probabilities, e.g., `0.72` = 72%) - `volume` — total trading volume in USD - `endDate` — resolution date ### Placing a Trade on Polymarket Orders go through the CLOB API. You specify the **token ID** (YES or NO side), the **price** (0 to 1), and the **size** in USDC. ```python order = { "tokenId": "your_token_id", "price": 0.65, "size": 10, "side": "BUY", "type": "GTC" # Good Till Cancelled } headers = get_headers("POST", "/order", str(order)) response = requests.post("https://clob.polymarket.com/order", json=order, headers=headers) ``` One important note: Polymarket orders are **on-chain**, so there's a small gas fee for each transaction, usually a fraction of a cent on Polygon. --- ## Kalshi API: How It Works **Kalshi** is a CFTC-regulated prediction market exchange based in the US. Its API is much closer to a traditional brokerage API — REST-based, JSON responses, and standard OAuth-style authentication. ### Kalshi Authentication Kalshi uses **RSA key authentication** for production and a simple email/password flow for the demo environment. 1. Create an account at `kalshi.com` 2. Navigate to Account Settings → API Access 3. Generate an RSA key pair and upload your public key 4. Use your private key to sign requests ```python from cryptography.hazmat.primitives import hashes, serialization from cryptography.hazmat.primitives.asymmetric import padding import base64 def sign_request(private_key_path, timestamp, method, path): with open(private_key_path, "rb") as f: private_key = serialization.load_pem_private_key(f.read(), password=None) message = f"{timestamp}{method}{path}".encode() signature = private_key.sign(message, padding.PKCS1v15(), hashes.SHA256()) return base64.b64encode(signature).decode() ``` ### Fetching Markets on Kalshi ```python headers = { "KALSHI-ACCESS-KEY": "your_key_id", "KALSHI-ACCESS-TIMESTAMP": timestamp, "KALSHI-ACCESS-SIGNATURE": signature } response = requests.get( "https://trading-api.kalshi.com/trade-api/v2/markets", headers=headers, params={"limit": 20, "status": "open"} ) ``` Kalshi market objects include: - `ticker` — e.g., `INXD-23DEC31-T4500` - `title` — human-readable question - `yes_bid` / `yes_ask` — prices in cents (50 = $0.50) - `volume` — number of contracts traded - `close_time` — expiration ### Placing a Trade on Kalshi ```python order_payload = { "ticker": "INXD-23DEC31-T4500", "action": "buy", "side": "yes", "type": "limit", "count": 10, "yes_price": 65 } response = requests.post( "https://trading-api.kalshi.com/trade-api/v2/portfolio/orders", json=order_payload, headers=headers ) ``` Unlike Polymarket, Kalshi settles in **USD (not crypto)** and is subject to standard US financial regulations, including position limits and KYC requirements. --- ## Polymarket vs Kalshi API: Side-by-Side Comparison Here's a direct comparison to help you decide where to start: | Feature | Polymarket | Kalshi | |---|---|---| | **Regulation** | Decentralized (no US regulation) | CFTC-regulated US exchange | | **Currency** | USDC (crypto) | USD (fiat) | | **Auth Method** | HMAC with wallet keys | RSA key signing | | **API Style** | REST + blockchain interaction | Pure REST | | **Order Book** | Central Limit Order Book (CLOB) | Central Limit Order Book | | **Gas Fees** | Yes (tiny, ~$0.001) | No | | **US Residents** | Restricted (geoblocked) | Fully available | | **Market Types** | Crypto, politics, sports, misc | Politics, economics, weather, sports | | **Price Format** | 0.00–1.00 (probability) | 1–99 (cents per contract) | | **Liquidity** | Higher (especially politics) | Growing, especially for regulated users | | **Rate Limits** | 10 req/sec (public), 5 req/sec (private) | 10 req/sec standard | | **WebSocket Support** | Yes (price feeds) | Yes (order book updates) | For algorithmic traders, the biggest decision is usually about **jurisdiction and currency**. If you're a US resident who wants clean USD accounting, Kalshi is the straightforward choice. If you want higher liquidity on political markets and you're comfortable with crypto, Polymarket wins. For strategies like those covered in our [mean reversion strategies via API guide](/blog/mean-reversion-strategies-via-api-best-approaches-compared), both platforms work — but you'll need to account for Polymarket's decimal pricing vs. Kalshi's cents-based system. --- ## Building Your First Dual-Platform Market Monitor Let's put both APIs together in a simple script that monitors the same event across both platforms and flags **pricing discrepancies** (the foundation of arbitrage). ### Step-by-Step: Price Monitor 1. **Identify a shared market topic** — e.g., "Will the Fed cut rates in 2025?" 2. **Pull current prices from both APIs** using the GET endpoints above 3. **Normalize prices** to the same format (convert Kalshi cents to 0–1 decimal) 4. **Calculate the spread** — if Polymarket shows 0.72 and Kalshi shows 0.68, that's a 4-point gap 5. **Set a threshold** — only flag gaps above 2–3 points (to account for transaction costs) 6. **Log or alert** when the threshold is crossed 7. **Optionally auto-trade** by buying the cheaper side and selling (or shorting) the expensive side ```python def normalize_kalshi_price(cents_price): return cents_price / 100 def check_spread(poly_price, kalshi_price, threshold=0.03): spread = abs(poly_price - normalize_kalshi_price(kalshi_price)) if spread >= threshold: print(f"Arbitrage opportunity: {spread:.2%} spread detected") return spread ``` This is exactly the kind of logic that powers more advanced [polymarket arbitrage](/polymarket-arbitrage) strategies. Even a 2–3% edge, captured consistently across many markets, compounds into significant returns. For a deeper dive into portfolio-level thinking with these strategies, the [momentum trading in prediction markets guide](/blog/momentum-trading-in-prediction-markets-a-small-portfolio-guide) covers position sizing and risk management that applies directly to API-based approaches. --- ## Common Beginner Mistakes to Avoid When you're first connecting to these APIs, a few mistakes will cost you time (and sometimes money): **On Polymarket:** - Forgetting to approve the USDC spend limit on-chain before placing orders - Using mainnet credentials on testnet endpoints (or vice versa) - Ignoring token ID — each YES/NO outcome has a *different* token ID, not just one per market - Not handling the `allowances` check — if your wallet allowance is zero, orders silently fail **On Kalshi:** - Sending prices as decimals instead of integers (65 not 0.65) - Missing the `count` field (number of contracts) and defaulting to 0 - Not refreshing auth tokens — Kalshi tokens expire and need renewal - Exceeding position limits on regulated contracts (Kalshi enforces these strictly) These issues mirror broader patterns described in our piece on [common market making mistakes on prediction markets](/blog/common-market-making-mistakes-on-prediction-markets-explained) — most beginner errors are structural, not analytical. Also worth reviewing: [common mistakes in earnings surprise markets](/blog/common-mistakes-in-earnings-surprise-markets-and-how-to-fix-them) covers how data normalization errors (exactly like the cents vs. decimal issue) can silently destroy your edge. --- ## Rate Limits, Costs, and Scaling Considerations Both platforms impose rate limits that matter once you start running automated systems: - **Polymarket**: Public endpoints allow ~10 requests/second; private (authenticated) endpoints are limited to ~5 requests/second. For high-frequency monitoring, use **WebSocket subscriptions** instead of polling. - **Kalshi**: Standard accounts get 10 requests/second. Enterprise API access is available for institutional users with higher throughput needs. **Cost structure:** - Polymarket charges a **trading fee of 0% to 2%** depending on market and maker/taker status. Makers (limit orders that add liquidity) often pay 0%. - Kalshi charges fees in the range of **$0.03 per contract** on most markets, plus potential exchange fees. For context, if you're trading 100 contracts at $0.65 each on Kalshi ($65 notional), you're paying roughly $3 in fees — about **4.6% of capital**. This makes small positions expensive; efficient API trading on Kalshi generally requires position sizes above $50 per trade to keep fees under 3%. --- ## Frequently Asked Questions ## Is Polymarket legal for US users? Polymarket is technically geoblocked for US residents due to its unregulated status, though VPN usage is common. US residents who want a legally compliant option should use Kalshi, which is fully regulated by the CFTC and explicitly available to American traders. ## Do I need crypto to use the Polymarket API? Yes — Polymarket settles in **USDC on the Polygon network**. You'll need a funded Polygon wallet to place any trades. Funding typically requires buying USDC on a centralized exchange and bridging it to Polygon, which can take 10–30 minutes if you're doing it for the first time. ## Can I use the same strategy on both platforms? Most strategies — including momentum, mean reversion, and arbitrage — transfer between platforms conceptually. However, you'll need to adapt your code for the different authentication systems, price formats, and order schemas. Some traders run the same core logic with platform-specific adapters for each API. ## How do I handle WebSockets for real-time data? Both Polymarket and Kalshi support WebSocket connections for streaming order book updates and price changes. Polymarket's WebSocket endpoint is at `wss://ws-subscriptions-clob.polymarket.com/ws/market`; Kalshi's is at `wss://trading-api.kalshi.com/trade-api/ws/v2`. Subscribe to specific market channels to avoid receiving all market data at once. ## What programming language works best for these APIs? **Python** is the most common choice due to the availability of libraries like `requests`, `cryptography`, and `web3.py`. JavaScript/TypeScript also works well, especially for frontend dashboards. Kalshi has an unofficial Python SDK on GitHub that simplifies authentication significantly for beginners. ## How much money do I need to start API trading on these platforms? You can technically start with as little as **$10–$20** on either platform, but realistic testing with meaningful position sizes typically requires $100–$500. Keep in mind Kalshi's per-contract fees make very small trades inefficient. For Polymarket, gas fees are negligible on Polygon, so even small USDC amounts work fine for testing. --- ## Get Started with Smarter Prediction Market Trading You now have everything you need to make your first API calls on both Polymarket and Kalshi — from authentication to order placement to spotting price discrepancies across platforms. The next step is putting these building blocks together into a systematic strategy that runs automatically. [PredictEngine](/) is built for exactly this — combining real-time data from prediction markets with AI-driven signals and execution tools, so you can focus on strategy rather than infrastructure. Whether you're exploring [swing trading prediction outcomes](/blog/swing-trading-prediction-outcomes-risk-analysis-made-simple) or want to explore our ready-to-deploy [Polymarket bot](/polymarket-bot), PredictEngine gives you the edge that manual traders simply can't match. Check out our [pricing page](/pricing) to find the plan that fits your trading style, and start building smarter today.

Ready to Start Trading?

PredictEngine lets you create automated trading bots for Polymarket in seconds. No coding required.

Get Started Free

Continue Reading