Guide July 22, 2026

How to stream live Polymarket trades in Python

Connect to the Polymarket mempool over WebSocket and read every trade the millisecond it happens — a complete Python example in five lines.

To stream live Polymarket trades in Python, connect a WebSocket to wss://stream.polyflux.io/polymarket/<your_key> and read each JSON message as it arrives. A full working client is five lines, shown below.

Most Polymarket data sources show you trades after they’ve settled on-chain — seconds late. If you’re building a bot, copy-trading whales, or hunting for an edge, those seconds are the whole game. This guide shows you how to stream every trade from the mempool, the millisecond it happens.

The five-line client

Once you have an API key, connecting is trivial. Open a standard WebSocket and read the feed:

import asyncio, json, websockets

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

async def main():
    async with websockets.connect(URL) as ws:
        async for raw in ws:
            t = json.loads(raw)
            print(t["wallet_address"], t["size"], t["price"])

asyncio.run(main())

That’s it. Every trade — buy or sell, taker or maker — arrives as a JSON message before it’s confirmed on-chain.

What each message looks like

Each event carries the fields you need to act on a trade:

  • wallet_address — who is trading
  • size — position size
  • price — the odds they’re taking (0.00–1.00)
  • operation_typebuy or sell
  • event_typetrade, or redeems / splits / merges you can skip
  • timestamp — millisecond precision

The timestamp is the point of the whole thing: you’re seeing this before the chain does. That’s your latency edge.

Filtering to just the trades

The feed includes non-trade events (redeems, splits, merges). Skip them:

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
        # act on the trade here
        print(t["wallet_address"], t["size"], t["price"])

Where to go from here

From this stream you can build:

  • Whale alerts — fire when size crosses a threshold
  • Copy-trading — mirror a set of known-sharp wallets
  • Signals — aggregate flow into a real-time sentiment view

The feed is the same one that powers the Polyflux live dashboard. Grab a key, paste the snippet above, and you’re reading the mempool in under a minute.

Frequently asked questions

Is there a real-time Polymarket API?
Yes. Polyflux exposes a WebSocket endpoint (wss://stream.polyflux.io/polymarket/<key>) that streams every Polymarket trade as JSON in real time, before it confirms on-chain.
What language can I use to stream Polymarket data?
Any language with a WebSocket client works — Python, Node.js, Rust, Go, or even a browser. This guide uses Python with the websockets library.
What fields does each Polymarket trade message contain?
wallet_address (who traded), size (position size), price (odds, 0.00–1.00), operation_type (buy or sell), event_type (trade, redeem, split, merge), and a millisecond timestamp.
How much faster is mempool data than the on-chain data?
Mempool trades typically appear about 3 seconds before they are confirmed into a block, which is the window traders use to act ahead of slower participants.
← All articles