This guide takes you from zero to a working Polymarket trading bot. No prior prediction market experience required — just basic Python skills and a willingness to learn.
By the end, you will have a funded wallet, working API credentials, a minimal bot that can fetch markets and place orders, and the knowledge to extend it into whatever strategy you want to pursue.
What You Will Learn
- How to create and fund a Polygon wallet for Polymarket
- How to generate CLOB API credentials
- How to install and configure py-clob-client
- How to write a minimal bot that fetches markets and places an order
- How to test safely before risking real money
- How to go live and set up basic monitoring
Prerequisites
- Python 3.10 or later installed on your machine
- Basic Python knowledge — you should be comfortable with pip, environment variables, and JSON
- $10-50 in USDC for initial funding (you can start very small)
- A terminal (macOS Terminal, Windows Terminal with WSL, or Linux shell)
No Polymarket account is needed in advance. The wallet you create acts as your identity on the platform.
Step-by-Step Instructions
Step 1: Create a Dedicated Wallet
Polymarket runs on the Polygon network. Your wallet is your account — there is no traditional username/password signup.
Create a new wallet specifically for your bot. Never use an existing personal wallet that holds other assets:
# Install eth-account to generate a wallet
pip install eth-account
python -c "
from eth_account import Account
acct = Account.create()
print(f'Address: {acct.address}')
print(f'Private Key: {acct.key.hex()}')
print()
print('SAVE THESE SECURELY. The private key controls your funds.')
print('Never share your private key or commit it to git.')
"
Save the address and private key securely. The private key is the only way to access this wallet — there is no recovery process.
Create a .env file in your project directory to store credentials:
# .env — never commit this file to version control
POLYMARKET_PRIVATE_KEY=0xyour_private_key_here
Add .env to your .gitignore immediately:
echo ".env" >> .gitignore
Step 2: Fund Your Wallet with USDC
Polymarket trades in USDC on Polygon. You need to get USDC into your new wallet. There are several paths:
Option A: Bridge from Ethereum (if you already have USDC on Ethereum)
Use the Polygon Bridge at bridge.polygon.technology to send USDC from Ethereum mainnet to Polygon. This costs Ethereum gas fees ($2-10 depending on network congestion).
Option B: Direct on-ramp with Coinbase or MoonPay
Buy USDC on Polygon directly through an on-ramp service. Coinbase Agentic Wallets can fund your bot wallet directly — see the Coinbase Agentic Wallets guide for details. MoonPay integration is covered in the MoonPay vs Coinbase comparison.
Option C: Send from an exchange
Buy USDC on Coinbase, Kraken, or another exchange and withdraw it to your wallet address on the Polygon network. Make sure you select Polygon as the withdrawal network — sending on Ethereum will work but costs more and requires bridging.
Verify your balance:
from web3 import Web3
POLYGON_RPC = "https://polygon-rpc.com"
USDC_ADDRESS = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"
WALLET_ADDRESS = "your_wallet_address"
w3 = Web3(Web3.HTTPProvider(POLYGON_RPC))
# USDC has 6 decimals
usdc_abi = [{"constant":True,"inputs":[{"name":"account","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"type":"function"}]
usdc = w3.eth.contract(address=USDC_ADDRESS, abi=usdc_abi)
balance = usdc.functions.balanceOf(WALLET_ADDRESS).call()
print(f"USDC Balance: ${balance / 1e6:.2f}")
Step 3: Install py-clob-client and Generate API Credentials
Polymarket’s official Python SDK handles authentication, order signing, and API communication:
pip install py-clob-client python-dotenv
Generate your CLOB API credentials. This is a one-time operation — the credentials are derived from your private key:
import os
from dotenv import load_dotenv
from py_clob_client.client import ClobClient
load_dotenv()
client = ClobClient(
host="https://clob.polymarket.com",
key=os.getenv("POLYMARKET_PRIVATE_KEY"),
chain_id=137 # Polygon mainnet
)
# Generate or derive API credentials
api_creds = client.create_or_derive_api_creds()
print(f"API Key: {api_creds.api_key}")
print(f"API Secret: {api_creds.api_secret}")
print(f"API Passphrase: {api_creds.api_passphrase}")
print()
print("Add these to your .env file.")
Add the credentials to your .env:
# .env
POLYMARKET_PRIVATE_KEY=0xyour_private_key
POLYMARKET_API_KEY=your_api_key
POLYMARKET_API_SECRET=your_api_secret
POLYMARKET_API_PASSPHRASE=your_api_passphrase
Step 4: Verify Connectivity by Fetching Markets
Before writing trading logic, confirm everything works by fetching live market data:
import os
from dotenv import load_dotenv
from py_clob_client.client import ClobClient
from py_clob_client.clob_types import ApiCreds
load_dotenv()
client = ClobClient(
host="https://clob.polymarket.com",
key=os.getenv("POLYMARKET_PRIVATE_KEY"),
chain_id=137,
creds=ApiCreds(
api_key=os.getenv("POLYMARKET_API_KEY"),
api_secret=os.getenv("POLYMARKET_API_SECRET"),
api_passphrase=os.getenv("POLYMARKET_API_PASSPHRASE"),
),
)
# Fetch active markets
markets = client.get_markets()
print(f"Found {len(markets)} active markets\n")
# Display first 5 markets
for market in markets[:5]:
print(f" {market['question']}")
print(f" Condition ID: {market['condition_id']}")
print(f" Active: {market['active']}")
print()
If this prints a list of markets, your setup is working correctly.
Step 5: Write Your Minimal Trading Bot
Here is a complete minimal bot that fetches a specific market, checks the price, and places a limit order:
import os
import time
from dotenv import load_dotenv
from py_clob_client.client import ClobClient
from py_clob_client.clob_types import ApiCreds, OrderArgs
from py_clob_client.order_builder.constants import BUY, SELL
load_dotenv()
client = ClobClient(
host="https://clob.polymarket.com",
key=os.getenv("POLYMARKET_PRIVATE_KEY"),
chain_id=137,
creds=ApiCreds(
api_key=os.getenv("POLYMARKET_API_KEY"),
api_secret=os.getenv("POLYMARKET_API_SECRET"),
api_passphrase=os.getenv("POLYMARKET_API_PASSPHRASE"),
),
)
# Configuration
TOKEN_ID = "your_target_token_id" # YES or NO token for a specific market
MAX_PRICE = 0.55 # only buy if price is at or below this
ORDER_SIZE = 10 # number of contracts (each worth up to $1)
PAPER_MODE = True # set to False when ready to trade for real
def get_best_ask(token_id):
"""Get the current best ask price for a token."""
book = client.get_order_book(token_id)
if book.asks:
return float(book.asks[0].price)
return None
def place_buy_order(token_id, price, size):
"""Place a limit buy order."""
order_args = OrderArgs(
price=price,
size=size,
side=BUY,
token_id=token_id,
)
signed_order = client.create_order(order_args)
response = client.post_order(signed_order)
return response
def run():
print("Bot starting...")
while True:
try:
best_ask = get_best_ask(TOKEN_ID)
if best_ask is None:
print("No asks available. Waiting...")
elif best_ask <= MAX_PRICE:
print(f"Opportunity: best ask {best_ask} <= max price {MAX_PRICE}")
if PAPER_MODE:
print(f" [PAPER] Would buy {ORDER_SIZE} @ {best_ask}")
else:
resp = place_buy_order(TOKEN_ID, best_ask, ORDER_SIZE)
print(f" Order placed: {resp}")
else:
print(f"Price too high: {best_ask} > {MAX_PRICE}")
except Exception as e:
print(f"Error: {e}")
time.sleep(30) # check every 30 seconds
if __name__ == "__main__":
run()
Step 6: Test in Paper Mode
Run the bot with PAPER_MODE = True:
python bot.py
Watch the output for several hours. Confirm that:
- The bot fetches prices correctly
- It identifies opportunities when the price drops below your threshold
- The paper trade logging works as expected
- No authentication errors occur
- The bot handles network errors gracefully
Check the Polymarket rate limits guide to make sure your polling frequency stays within allowed limits. Every 30 seconds is safe for most use cases.
Step 7: Place Your First Live Trade
When you are confident in the bot’s behavior, set PAPER_MODE = False and run with a small order size (5-10 contracts):
# Go live
PAPER_MODE=False python bot.py
Monitor the first few trades closely. Verify on the Polymarket web interface that your orders appear correctly and fills match what the bot reports.
Step 8: Set Up Monitoring and Auto-Restart
For production operation, wrap your bot with basic monitoring:
# Install supervisor for auto-restart
pip install supervisor
# Or use a simple bash wrapper
cat > run_forever.sh << 'SCRIPT'
#!/bin/bash
while true; do
echo "[$(date)] Starting bot..."
python bot.py
echo "[$(date)] Bot exited. Restarting in 10 seconds..."
sleep 10
done
SCRIPT
chmod +x run_forever.sh
For more robust deployment, see the production deployment section of our Polymarket trading bot quickstart.
Common Mistakes and How to Avoid Them
Committing your private key to git. This is the most expensive mistake you can make. Always use .env files and add them to .gitignore before your first commit. If you accidentally commit a key, consider that wallet compromised and move funds immediately.
Using your personal wallet. Create a dedicated wallet for each bot. If the bot is compromised, only the bot wallet is at risk.
Ignoring rate limits. Polymarket limits API requests per second. Polling every 1 second will get you rate-limited. Start at 30-second intervals and optimize from there. See the rate limits guide.
Not testing in paper mode first. Even a simple bot can have bugs that cause unintended orders. Always run in paper mode for at least 24 hours before going live.
Funding the wallet with too much capital. Start with $10-50 for your first bot. You can always add more later. Do not fund the bot wallet with capital you cannot afford to lose.
Cost Breakdown
| Cost Category | Typical Range | Notes |
|---|---|---|
| Wallet creation | Free | Just a key generation |
| USDC funding | $10-50 to start | Bridge or on-ramp fees apply |
| Bridge/gas fees | $2-10 | One-time, depends on network |
| py-clob-client | Free | Open-source SDK |
| VPS (optional) | $5-10/month | For 24/7 operation |
| Polymarket trading fees | 0-2% per trade | Maker: 0%, Taker: up to 2% |
| Total first-month cost | $15-70 | Including initial funding |
This is the lowest-cost path to automated prediction market trading. The only ongoing cost is VPS hosting if you want 24/7 operation.
Next Steps and Related Guides
- Polymarket Trading Bot Quickstart — Build a production-grade bot with market scanning, signal generation, and risk management.
- Polymarket API Guide — Complete API reference for advanced usage.
- How to Automate Prediction Market Trading — Platform-agnostic overview of all automation approaches.
- Polymarket Rate Limits Guide — Avoid getting rate-limited.
- Prediction Market API Reference — Cross-platform API comparison.
- Polymarket Bots Platform Guide — Everything about the Polymarket bot ecosystem.