Developer guidePolymarket APIPython · WebSocket

Polymarket API: a live trade feed that gets 99% of fills within 2.4 seconds

Every Polymarket trade settles on Polygon. We built a feed that prints each fill, result and payout straight from the chain, timed it, and found the trap that makes a naive feed count every trade twice.

Cover Image for Polymarket API: Build a Live Trade Feed That Gets 99% of Fills Within 2.4 Seconds

Every Polymarket trade settles on Polygon. Bitquery's API decodes those trades and streams them over a socket. We built a feed on that stream in one Python file. It prints every fill with its market, outcome, price and size. It also marks each market when it resolves, and prints each payout.

On 2 December 2026, we ran it for an hour on a small server in Singapore. A fill reached our code a median of 0.86 seconds after its Polygon block, and 99 in 100 arrived within 2.4 seconds. If you run a trading bot, an alert channel or a live odds page, that gap is the time you have to act.

At a glance
The feed opens one socket to the Bitquery API and asks for three datasets: fills, market results and payouts. It prints each trade once, works out the price itself, and fills any gap after a dropped connection. We ran it for an hour and timed every fill from its Polygon block to our code. Then we checked a day of data for the traps that break a feed like this.
0.86 s
Median time from Polygon block to our code
99%
Fills that arrived within 2.4 seconds
2.0×
Shares counted if you sum every row
51,003
Fills timed in one hour
Key findingsEach line has its own share link
  1. 0.86 s

    Median time from a fill's Polygon block to our code, over 51,003 fills in one hour. 99% arrived within 2.4 seconds.

  2. 3.1×

    Slower to poll. Asking the HTTP API once a second saw a new block a median 2.62 seconds after it was made.

  3. 2.0×

    Shares you count if you sum every trade row. On 1 December 2026 the rows held 262.4 million shares; the trades held 131.2 million.

  4. 75%

    Trades in our hour in which the taker and the resting orders bought opposite outcomes. A "Yes" chart built from every row jumps between two prices.

  5. 16 s

    Slowest fill, at 09:37 UTC. Most late blocks landed just after a five-minute mark, and no fill was lost.

  6. 28%

    Payout events on 1 December 2026 that paid $0. 211 markets resolved with no single winner and paid both sides half.

What the Polymarket trade feed prints

The feed prints one line per trade, one per market result and one per payout. This is our terminal on 2 December, in two short excerpts from the same run:

Terminal output of feed.py on 2 December 2026: five Polymarket fills with trader, side, outcome, price, shares, USDC value, fee, maker count and lag, then seven results for one Counter-Strike match, two of them split payouts, and the first payouts six seconds later

Read a FILL line from left to right. Take the second FILL line. Its market, cut short in the image, is "Exact Score: Jeonbuk FC 3 - 3 Gamba Osaka?". A wallet bet against that score: it bought "No" at 98.7 cents a share. It bought 77.9 shares for $76.90 and filled two resting orders, the makers. lag is the time from the Polygon block to the moment the line reached us.

A RESOLVED line names the winning outcome. Here, seven markets on one Counter-Strike match settled in the same block, and two of them had no single winner. A PAYOUT line is winning shares cashed in for USDC. The first payouts on that match arrived six seconds after its result.

The code is on GitHub, bitquery/polymarket-trade-feed. Run it in four commands:

git clone https://github.com/bitquery/polymarket-trade-feed && cd polymarket-trade-feed
pip install -r requirements.txt
echo 'BITQUERY_TOKEN=your_access_token' > .env
python feed.py

To get an access token, sign up for Bitquery and create one under API access tokens, as the token guide shows. The free trial allows two streams at once, so start with python feed.py --no-payouts, which needs two.

How the feed works

Polymarket is a prediction market. Each market asks a question, such as "Bitcoin above 61,600 on December 2?", and sells shares in each answer. A share pays $1 if its answer wins and $0 if it loses, so its price, between 0 and 1, reads as the crowd's odds.

People trade those shares on an order book. When two orders match, the trade settles on Polygon, and the exchange contract emits one OrderFilled event for each order in the match. Bitquery decodes those events, ties each one to its market question and outcome, and serves them in three datasets, which Bitquery calls cubes:

CubeWhat it holdsWhat the feed does with it
PredictionTradesEvery OrderFilled event, with market, outcome, shares and cashPrints each trade once
PredictionManagementsMarkets created and markets resolved, with the winning outcomeMarks the market as resolved
PredictionSettlementsSplits, merges and redemptions of outcome sharesPrints each payout

The feed sends one query with all three cubes over wss://streaming.bitquery.io/graphql. Each cube counts as a separate stream for billing, which the cost section covers. The Polymarket API page lists the same three datasets, and the docs have a page for each: trades, market results and payouts.

Step 1: subscribe to fills, results and payouts

Open a socket with your token in the URL and the graphql-ws protocol, as the socket docs describe. Then send the query. This is the part for fills; queries.py holds all three cubes:

subscription PolymarketFeed {
  EVM(network: matic) {
    PredictionTrades(
      where: {
        TransactionStatus: {Success: true}
        Trade: {Prediction: {Marketplace: {ProtocolName: {is: "polymarket"}}}}
      }
    ) {
      Block { Time Number }
      Transaction { Hash To }
      Log { Index SmartContract }
      Trade {
        OutcomeTrade {
          Buyer Seller IsOutcomeBuy
          Amount CollateralAmount CollateralAmountInUSD
          Price Fee { AmountInUSD }
        }
        Prediction {
          ConditionId
          Question { Title }
          Outcome { Label }
        }
      }
    }
  }
}

network: matic is Polygon. The ProtocolName filter drops other betting markets on Polygon. Transaction.To and Log.SmartContract look like extras, but step 2 needs both.

The connection takes a few lines of Python:

async with websockets.connect(f"wss://streaming.bitquery.io/graphql?token={token}",
                              subprotocols=["graphql-ws"], max_size=None) as ws:
    await ws.send(json.dumps({"type": "connection_init"}))
    await ws.send(json.dumps({"id": "1", "type": "start",
                              "payload": {"query": feed_subscription()}}))
    while True:
        raw = await asyncio.wait_for(ws.recv(), timeout=10)
        received = time.time()          # stamp first, parse later
        queue.put_nowait((received, raw))

Each message holds every new row from one Polygon block. A separate task reads the queue and prints, so a slow terminal never delays the arrival time, which the lag is measured from.

Step 2: print each trade once

One trade comes back as several rows. When a taker's order crosses the book, it can fill many resting orders, called maker orders, at once. The exchange emits one OrderFilled event for each maker order and one more for the taker's order. All of them land in PredictionTrades.

On the taker's own row, the other side is a Polymarket contract. It is either the exchange that emitted the event, or a router contract that passed the trade to the exchange. The feed keeps that row and counts the others:

def is_taker(row):
    o = row["Trade"]["OutcomeTrade"]
    contracts = {row["Log"]["SmartContract"].lower(), row["Transaction"]["To"].lower()}
    return o["Buyer"].lower() in contracts or o["Seller"].lower() in contracts

On 1 December, this rule found exactly one taker row in every trade of the day, more than a million of them. Checking the exchange contract alone is not enough. Most trades on exchange 0x862f…4e55 route through 0xe333…00aa, and the other side on their taker row is that router. The first trap below shows what happens if you skip this step.

On the taker's row, IsOutcomeBuy is the taker's direction: true means the taker bought the outcome named in Outcome.Label. The wallet that is not the contract is the taker.

Step 3: work out the price yourself

Price is null on the stream. In a 40-second capture on 2 December, every one of 952 streamed rows came back with Price: null. The same field is filled in the HTTP query.

Compute it from the two amounts instead. The price of an outcome share is the cash paid divided by the shares:

price = o["Price"] if o["Price"] is not None else float(o["CollateralAmount"]) / float(o["Amount"])

We checked the formula on every row of an HTTP sample, where Price is filled. It matched each one to the last decimal.

Step 4: mark results and payouts

When a market resolves, PredictionManagements returns a Resolved row with the winning outcome in Outcome.Label. The feed stores the result under the market's ConditionId, the on-chain ID of the question, and tags later fills on that market:

def on_resolution(self, m):
    p = m["Management"]["Prediction"]
    winner = p["Outcome"]["Label"] or "no single winner (split payout)"
    self.resolved[p["Condition"]["Id"]] = winner

An empty label is a real result. The fourth trap below explains it.

Payouts come from PredictionSettlements rows whose EventType is Redemption. A holder redeems outcome shares after the result, and the contract pays $1 for each winning share. The stream query drops redemptions that pay nothing, on the server, with Amounts: {CollateralAmount: {gt: "0"}}.

Step 5: recover fills after a dropped socket

A socket can go quiet without closing. Bitquery sends keep-alive messages between data messages, so the feed treats 10 seconds of silence as a dead connection, as the reconnect guide suggests. It then opens a new socket.

Fills that settled while the socket was down never arrive on the new one. So the feed asks the HTTP API for every fill from the last block it printed, and skips the ones it already has:

query Backfill($since: String!, $limit: Int!) {
  EVM(network: matic) {
    PredictionTrades(
      limit: {count: $limit}
      orderBy: [{ascending: Block_Number}, {ascending: Log_Index}]
      where: {
        TransactionStatus: {Success: true}
        Trade: {Prediction: {Marketplace: {ProtocolName: {is: "polymarket"}}}}
        Block: {Number: {ge: $since}}
      }
    ) { ...same fields as the subscription... }
  }
}

We tested it by cutting the socket for eight seconds. The backfill recovered 85 fills, with no duplicates and no missing blocks.

Step 6: measure the lag

The feed writes each fill's lag to a CSV file with --log. Lag is the time the message arrived minus the time of the Polygon block that holds the fill. latency.py reads the file:

python feed.py --log data/fills.csv --minutes 60
python latency.py data/fills.csv

How fast is the Polymarket stream?

The feed timed every fill for an hour on 2 December, from a server in Singapore. The median fill, the one in the middle when you line up all the lags, arrived 0.86 seconds after its block. Seven in ten arrived within a second, and 96% within a second and a half. The table below has the rest.

MeasureMedian90% within99% withinSlowest
Stream, per fill0.86 s1.26 s2.41 s16.43 s
Stream, first fill of each block0.76 s1.16 s
HTTP polling once a second, per new block2.62 s3.15 s
Most fills reach your code in under a second2 December 2026, 60 minutes from 09:16 UTC
SHARE OF FILLS (STREAM) OR NEW BLOCKS (POLLING) BY LAG0%10%20%30%40%50%0 s1 s2 s3 s4 s +0.6%stream median 0.86 spolling median 2.62 sWebSocket stream, per fillHTTP polling every second, per blockLag = arrival time minus the block's timestamp. 0.25-second bins.
51,003 fills over the WebSocket stream, 166 new blocks seen by polling. 90% of streamed fills arrived within 1.26 s; 90% of polled blocks within 3.15 s.

For comparison, poll_compare.py asked the HTTP API once a second for the newest fill, for the first five minutes of the same run. It saw each new block a median of 2.62 seconds after the block was made. A poller also needs a request every second, and each request costs API points.

The median stayed under a second in 59 of 60 minutesLag per minute and late blocks
LAG PER MINUTE OF THE RUN, SECONDS0 s1 s2 s3 s4 smin 0min 5min 10min 15min 20min 25min 30min 35min 40min 45min 50min 5509:37 UTC: slowest fill 16.4 smedian90th percentilefill over 3 s lateEach point is one minute of fills, from 09:16 UTC. Red marks above 4 s sit on the top line.
18 blocks arrived more than 3 seconds late. 12 of them landed 20 to 35 seconds after a five-minute mark on the clock. The socket never dropped, and every fill arrived.

The median held steady all hour, between 0.63 and 1.03 seconds in every minute. The slow tail came from a few late blocks. Of the 18 blocks that arrived more than 3 seconds late, 12 landed 20 to 35 seconds after a five-minute mark on the clock: 09:20, 09:25, 09:30 and so on. Polymarket's five-minute bitcoin and ether markets open and close on those marks. The slowest were three blocks at 09:37 UTC, 12 to 16 seconds late.

The socket stayed open the whole time, so the feed's silence check never fired, and every fill still arrived. Plan for late blocks like these. A bot that acts on a fill should compare the block time with the clock, and skip a signal that is already stale.

What breaks: four traps in Polymarket trade data

Four traps gave our feed wrong numbers on live data in late 2026. Each one below comes with the rows that show it.

1. Every trade shows up twice

PredictionTrades returns one row for each order in a match, so the taker's row and the maker rows describe the same shares. Here is one trade from 2 December, an NBA game:

One Polymarket trade comes back as several rowsPolygon block 98332074, 09:26:35 UTC
ONE TRADE, 4 ROWStransaction 0xce03…a0a2Grizzlies vs. PistonsROWWHOSE ORDERBOUGHTPRICESHARESUSDC1resting order 0x76b4…ca9bGrizzlies0.310039.67$12.302resting order 0xbd01…4f8fGrizzlies0.310025.00$7.753resting order 0xeb6f…4da4Grizzlies0.3100840.33$260.504taker 0x84cf…2f63Pistons0.6900905.00$624.45On the taker's row, the other side is the exchange contract 0xe111…996b. Its shares equal the sumof the resting orders above it. Count the trade once, from either side, never both.
From the HTTP query. The resting orders bought Grizzlies at 0.31 while the taker bought Pistons at 0.69: together they paid $1 a pair, and the trade created new shares.

Sum every row, and you count those shares twice. On 1 December, the rows held exactly twice the shares that traded:

Sum every row and a day of Polymarket trading doubles1 December 2026, 00:00 to 24:00 UTC
1 DECEMBER 2026, ALL POLYMARKET FILLS (MILLIONS)Shares, every row262.4MShares, one side131.2MUSD, every row$131.1MUSD, resting orders only$67.7MUSD, takers only$63.4M3,187,991 rows from 1,180,916 matches. Each match had exactly one taker row.
Share counts double exactly. Dollar totals differ by side because, in most matches, the two sides paid complementary prices for opposite outcomes.

In dollars, the two sides differ, so pick one and say which. Bitquery's Polymarket dataset in the Data Store counts volume from the maker rows. For a trade tape, print the taker's row, as the feed does.

2. The two sides often hold opposite outcomes

The trade in the figure above created new shares. The taker bought Pistons at 69 cents while the resting orders bought Grizzlies at 31 cents. Together they paid $1 a pair, and the exchange minted one share of each team for each dollar.

In our hour of fills, 75% of trades matched opposite outcomes this way. Build a Pistons price chart from every row, and the line jumps between 0.69 and 0.31 on the same trade. Chart one outcome's rows only, or turn the other outcome's price around with 1 − price. That works for markets with two outcomes.

3. One exchange sends no market ID

On 1 December, Polymarket fills came from three exchange contracts. On one of them, 0x862f…4e55, the Question.MarketId field is empty. That exchange carried about a fifth of the rows that day, and nearly two thirds of the rows in our hour a day later.

Code that groups trades by MarketId puts all of them in one bucket with no name. Key markets on ConditionId instead. All three cubes carry it: Trade.Prediction.ConditionId, Management.Prediction.Condition.Id and Settlement.Prediction.ConditionId hold the same value for the same market.

4. Payouts of $0 and results with no winner

On 1 December 2026, 28% of payout events paid nothing. A holder can redeem the losing side of a market, and the contract records a redemption of $0. A payout alert that prints every redemption is mostly noise.

The same day, about one resolved market in a hundred returned an empty winning outcome. We read the on-chain result of each one. All of them paid both sides half: their payoutNumerators were [1, 1]. Most were voided sports markets and over/under lines. Treat an empty label as a split result. The market has resolved.

A payout event can pay nothing, and a result can have no winner1 December 2026, UTC
1 DECEMBER 2026, POLYMARKET PAYOUTS AND RESULTSPayout eventspaid $0: 191,980 (27.9%)paid out: 496,555Resolved marketsno single winner: 211 (1.0%)one winner: 20,382
A $0 payout is a holder redeeming the losing side. The 211 markets with no single winner all paid both sides half, by their on-chain payout numbers.

Polymarket API pricing: streams, minutes and GB

Bitquery bills a stream on three meters: the number of streams, stream-minutes and the data pushed over the socket. Each cube in a stream query counts as one stream, so the full feed uses three.

We counted the data with feed.py itself, which adds up the size of every message it receives. Over the hour, the full feed received 116.7 MB, or 1.95 MB a minute. At that rate, the Pro plan's 5 GB lasts under two days. Traffic rises and falls with Polymarket's activity, so measure your own feed before you pick a plan.

On Pro and Scale, the data allowance runs out firstMeasured 2 December 2026, 09:16 to 10:16 UTC
DAYS OF INCLUDED STREAM DATA AT THE MEASURED RATETrial, 0.2 GB1.7 hoursPro, 5 GB1.8 daysScale, 50 GB17.9 daysFull feed, three streams: 116.7 MB in 60 minutes, 1.95 MB a minute.
Included stream data per plan, read from the pricing page on 2 December 2026. On the free trial, the 17 stream-minutes run out first: about 8 minutes of the feed. Extra data is sold in add-on packs.
RunStreamsStream-minutesStream dataPlan that covers it
Try it, --no-payouts216 for 8 minutesunder 0.02 GBFree trial: 17 stream-minutes, 0.2 GB
Full feed, all month3129,600about 84.0 GBScale, $299 a month: 2 million minutes and 50 GB, plus seven 5 GB packs at $50 each
Full feed on Pro3129,600, over Pro's 100,0005 GB lasts 1.8 daysPro, $99 a month, needs add-ons that cost more than Scale

We read these prices on the pricing page on 2 December 2026. A stream-minute is one stream connected for any part of a minute. The backfill and the polling script use API points instead. Each HTTP query costs points, and the trial includes 1,000.

For a feed that runs all day, the stream data runs out first. Three things cut it. Drop fields you do not print. Filter on the server, as the feed does for $0 payouts. Or subscribe to the markets you follow, with a ConditionId filter. For an unmetered firehose, Bitquery sells Kafka streams on Enterprise plans.

Limits

  • Polygon only. The feed reads Polygon and nothing else. Bitquery's Polygon API covers the rest of the chain.
  • Fills only, no order book. The feed sees trades after they settle. It does not see resting orders, cancelled orders or the book's depth. Polymarket's own order book API serves those.
  • About four days of history on the HTTP API. On 2 December, the oldest fill in the real-time dataset was from 28 November. The backfill is for dropped sockets. It cannot reach back months.
  • Older history is an add-on. The Polymarket history add-on starts on 1 September 2025 and costs $150 a month. The Data Store sells the same history as files, below.
  • No order placement. The code reads data only. It places no orders and holds no keys.
  • Lag depends on your network. We ran the feed on one server in Singapore. From another region, the network path to Bitquery's endpoint changes, and so does the lag.

How we tested

  • Latency. One run of feed.py for 60 minutes on 2 December, 09:16 to 10:16 UTC, on the live endpoint wss://streaming.bitquery.io/graphql. It ran on a small AWS server (t3.micro) in Singapore. Lag is arrival time minus block time. The server synced its clock to Amazon's time service, and the clock sat within a microsecond of it when the run began. Percentiles are exact, by nearest rank.
  • Polling. poll_compare.py, one request a second for the first five minutes of the same run, on the same server.
  • Completeness. We read every fill in the run's blocks again over HTTP later. The HTTP API returned 51,003 trades in those blocks. The stream had delivered every one of them, with none missing and none extra.
  • Spot check. For the 10 busiest markets of the run, nine of them five-minute bitcoin markets, we pulled every trade from Polymarket's own Data API and matched transaction hashes. Polymarket listed all 16,225 of our transactions and no others, and every one matched on the taker's price and size.
  • Day figures. Counts and sums for 1 December 2026, 00:00 to 24:00 UTC, from the HTTP API with exact unique counts.
  • Split results. We read the ConditionResolution event of each of the 211 markets with an empty winning outcome.

We used AI tools to write and run the test queries, and we checked each figure against the live API. The data behind every number and chart is saved with the article.

Polymarket history as files

The API keeps about four days of fills. For a backtest or a dashboard with months of history, use the Polymarket dataset in the Data Store. It has every fill, payout and market result since 1 September 2025 as Parquet files, with a free sample of each table. The latest month costs $400 and the full history $4,000.

FAQ

Is the Polymarket API free?

Polymarket's own APIs are free to read. The Bitquery API, which this guide uses, has a free trial for a week with two streams, enough to run this feed for a few minutes. Streaming after that needs the Pro plan at $99 a month, as read on 2 December 2026.

Does Polymarket have a WebSocket for trades?

Yes. Polymarket's own socket streams order book updates. The Bitquery stream sends trades after they settle on Polygon, with the market question, outcome, price, size and fee, plus market results and payouts. In our test, a fill reached our code a median of 0.86 seconds after its Polygon block, and 99% within 2.4 seconds.

How do I get Polymarket trade data in Python?

Open a socket to wss://streaming.bitquery.io/graphql with the graphql-ws protocol and subscribe to PredictionTrades on EVM(network: matic), filtered to Polymarket. Keep the taker's row of each trade, and compute the price as CollateralAmount / Amount. The repo bitquery/polymarket-trade-feed has the full code.

Why does my Polymarket volume look twice as high?

You are summing both sides of each trade. Every match returns a row for the taker and a row for each maker order, and they hold the same shares. On 1 December 2026, summing every row gave exactly twice the shares that traded.

How do I get Polymarket historical data?

The Bitquery HTTP API keeps about four days of fills in its real-time dataset. For older data, the Polymarket history add-on starts on 1 September 2025, and the Data Store sells the same history as Parquet files.

Related reading

Subscribe to our newsletter

Subscribe and never miss any updates related to our APIs, new developments & latest news etc. Our newsletter is sent once a week on Monday.