Tutorial July 23, 2026

Your first Polymarket trading bot: from account to copying a whale

Set up a Polymarket account, export your Magic wallet key, and build a primitive Python bot that watches the live feed and copies a whale's trades.

To build your first Polymarket trading bot, you need three pieces: a funded Polymarket account whose wallet key your bot can use, py-clob-client to place orders, and a real-time trade feed to react to. This tutorial wires all three into a primitive but working whale-copy bot in Python.

“Primitive” is the point. This is the smallest bot that actually closes the loop — see a trade, decide, place an order — and it’s the scaffold every fancier strategy grows from. If you’re still weighing whether to automate at all, read manual vs. automated trading first; if you want the conceptual background on where the data comes from, see what the Polymarket mempool is.

Step 1 — Create a Polymarket account

Go to polymarket.com and sign up. Two options:

  • Email sign-up (what most people use). Polymarket creates a wallet for you behind the scenes using Magic — you log in with your email, no seed phrases. Your funds live in a Polymarket-managed proxy wallet on Polygon.
  • Connect your own wallet (MetaMask etc.) if you already live on-chain.

Either works for a bot; this guide assumes the email / Magic wallet path since it’s the common case. Then deposit some USDC — every market is collateralized in USDC on Polygon (see how Polymarket works for the mechanics). Keep it small; this is a learning build.

Step 2 — Export your wallet key

Your bot needs to sign orders on your behalf. In Polymarket’s settings, export your wallet’s private key, and note your deposit address (the proxy wallet that actually holds your USDC) — you’ll need both.

Two rules, non-negotiable:

  1. Never put the key in code or a git repo. Use an environment variable.
  2. This key controls real money. Use a dedicated account with a small balance for bot experiments.
export POLY_PRIVATE_KEY="0x..."   # exported from Polymarket settings
export POLY_PROXY_ADDRESS="0x..." # your Polymarket deposit address

Step 3 — Install the libraries

Two well-known libraries do all the heavy lifting:

pip install websockets py-clob-client
  • websockets — the standard async WebSocket client, for reading the trade feed.
  • py-clob-client — Polymarket’s official Python client for its central limit order book (CLOB). It handles order signing and placement.

Initializing the CLOB client for a Magic-wallet account looks like this — signature_type=1 tells it you’re an email account, and funder is your deposit address:

import os
from py_clob_client.client import ClobClient

client = ClobClient(
    "https://clob.polymarket.com",
    key=os.environ["POLY_PRIVATE_KEY"],
    chain_id=137,                              # Polygon
    signature_type=1,                          # email / Magic wallet account
    funder=os.environ["POLY_PROXY_ADDRESS"],   # where your USDC lives
)
client.set_api_creds(client.create_or_derive_api_creds())

Step 4 — Subscribe to live trades with Polyflux

A copy bot is only as fast as its data — react to on-chain confirmations and you’re seconds behind. Polyflux streams every Polymarket trade from the mempool, the millisecond it happens and ~3 seconds before it confirms. One WebSocket, no infrastructure:

import asyncio, json, websockets

FEED = "wss://stream.polyflux.io/polymarket/<your_key>"

async def watch():
    async with websockets.connect(FEED) as ws:
        async for raw in ws:
            msg = json.loads(raw)
            if msg.get("type") != "events":
                continue
            for t in msg["events"]:
                if t.get("event_type") != "trade":
                    continue
                handle(t)   # our bot logic goes here

Each trade event gives you wallet_address, size, price (odds, 0.00–1.00), operation_type (buy/sell), and a millisecond timestamp — plus the full details of the market being traded. Print one raw event with print(json.dumps(t, indent=2)) when you first connect — thirty seconds of looking at real payloads teaches you more than any docs page, and you’ll see exactly where the outcome-token identifier lives (you pass it to orders as token_id below). This is the same five-line pattern from our Python streaming guide.

Step 5 — Detect the whale and copy the trade

Pick a whale. Watch the live feed for a while — big size values stand out immediately — or use the Polyflux dashboard leaderboard and the Wallet Profile tool to find consistently large, sharp wallets.

Then the “strategy” is just a filter plus an order:

from py_clob_client.clob_types import OrderArgs
from py_clob_client.order_builder.constants import BUY

WHALE = "0xabc123...".lower()   # the wallet you're copying
MIN_WHALE_SIZE = 500            # ignore their small probes
MY_SIZE = 5                     # your mirrored size — keep it small

def handle(t):
    if t["wallet_address"].lower() != WHALE:
        return
    if t["operation_type"] != "buy" or float(t["size"]) < MIN_WHALE_SIZE:
        return
    copy_trade(t)

def copy_trade(t):
    token_id = ...  # the outcome token from the event — see step 4
    resp = client.create_and_post_order(OrderArgs(
        token_id=token_id,
        price=float(t["price"]),   # take the same odds the whale took
        size=MY_SIZE,
        side=BUY,
    ))
    print("copied whale:", t["size"], "@", t["price"], "→", resp)

asyncio.run(watch())

That’s the whole bot: whale buys big → you buy small, at their price, seconds before their trade even confirms on-chain. While confirmation-based watchers are still waiting to learn the whale moved, your order is already on the book.

Honest caveats before you run it

  • This is a scaffold, not a money printer. Whales are wrong plenty. You enter after them (even if only by milliseconds), and you exit on your own judgment — this bot doesn’t even sell yet.
  • Trade small until measured. Run it with tiny MY_SIZE, log every copied trade, and evaluate over weeks, not hours.
  • Add your own filters. Obvious next steps: track multiple wallets, require the whale’s price to be within a band, mirror sells to exit when they do, and cap total exposure.

Where to go next

You now have the full loop — account, keys, feed, order. Everything else is strategy:

The only piece above you can’t build yourself in an afternoon is the real-time feed. Start a Polyflux trial, drop your key into FEED, and your bot is reading the mempool — seeing every whale ~3 seconds before the chain does.

Frequently asked questions

Can I use my Polymarket email (Magic wallet) account with a trading bot?
Yes. Export the private key of your Magic wallet from Polymarket settings, then initialize py-clob-client with signature_type=1 and your Polymarket deposit address as the funder. The bot can then sign and place orders for your account.
What Python libraries do I need for a Polymarket bot?
Two: websockets (to read a real-time trade feed) and py-clob-client (Polymarket's official Python client for placing orders on the CLOB). Both install with pip.
How do I copy a whale's trades on Polymarket?
Subscribe to a real-time trade feed, filter for the whale's wallet_address, ignore trades below a size threshold, and when they buy, place your own smaller order in the same market at the same price using py-clob-client.
How do I find whale wallets to copy?
Watch the live feed sorted by size — large trades stand out immediately — or use tools like the Polyflux dashboard leaderboard and Wallet Profile to see which wallets trade big and how they've performed.
Is copy-trading whales on Polymarket profitable?
Not automatically. A whale can be wrong, and you always enter slightly after them. Copy-trading is a starting scaffold for a strategy — trade small, measure results, and add your own filters before trusting it.
← All articles