Research project · Open source

I built a system to test prediction-market arbitrage

I built a cross-venue trading system to find out whether price gaps between Kalshi and Polymarket could actually be traded for profit. After fees, liquidity, latency, and contract differences, they couldn’t. The project became less about finding arbitrage than about building something I could trust to tell me when there wasn’t any.

The research platform is now open source. github.com/frahank/prediction-market-arbitrage

See the repo as an interactive diagram → Read the source on GitHub →

Diagram generated with archify by tt-a1i (MIT).

97 Reviewed pairs
2.9M Order-book rows / day
52.3 ms Median leg skew
879 Tests
3 Independent services
No-go No viable arbitrage found

The question

Prediction markets are new, volatile, and growing fast. I wanted to know whether a solo trader could make money on price mismatches between the two biggest prediction-market exchanges.

Fees, latency, liquidity, resolution conditions, and the risk of only one leg filling all get in the way, and I tested the idea against each one. The answer was no. None of the pairs I tested stayed profitable once real fees and available order-book depth were counted. That held even on a low-latency setup I tested, which captured quotes from servers a few miles from the exchanges’ own to cut round-trip time.

What I built

A trading system that became a research platform

It started as a real trading bot that could authenticate against Kalshi, price a trade, and place live orders. When the results came back negative, I retired the order path and kept the rest as a research platform that reads markets and never trades.

The system is three independent services on a small message bus. They talk only through versioned messages, never by reaching into each other’s state, so one service can restart or fall behind without corrupting the others. A malformed message is quarantined, not replayed. That boundary kept a one-person project predictable under real market timing instead of letting it turn into one fragile script.

Diagram of the platform's data path: Kalshi and Polymarket order books are captured, paired behind a skew gate, and priced through fees and depth. None of the 97 reviewed pairs cleared one cent.
The data path, simplified. Quotes that look like an edge (the moving blue dot) go into the fee and depth model and come out without one. None of the 97 reviewed pairs cleared one cent.

Architecture: outbox → router → inbox.

  • Concurrent Kalshi and Polymarket order-book capture over REST and WebSocket feeds on asyncio, sustaining roughly 2.9M rows per day at 52 ms median cross-venue leg skew.
  • RSA-PSS signed Kalshi authentication and a kill-switch-gated order path, since retired to read-only, paper-only operation.
  • Contract-equivalence review, quote normalization, freshness and skew gates, and depth-aware pricing, with pgvector similarity search behind the equivalence screen.
  • Fee, VWAP, slippage, collateral-carry, and failed-leg modeling, so a displayed spread is never mistaken for money I could actually take.
  • State and the pair registry in PostgreSQL through SQLAlchemy 2.0, with append-only capture and a Parquet and DuckDB layer for querying order-book history.
  • Testing and deployment: mypy --strict across 26K lines, 879 tests (532 unit, 347 PostgreSQL integration), checks that run in order (lint, then types, then tests), and a multi-stage non-root Docker image with healthchecks.
The access and safety tab, showing paper runtime mode, real orders disabled, a clear kill switch, and storage-only credential fields.
The safety controls: runtime mode, all three real-order gates, the global kill switch, and a storage-only credential store wired to no trading path. A real order needs all three independent gates and is denied by default if any one is missing.

The speed limit

Every price in this project had to travel. Polymarket’s order books are served from London, Kalshi’s from the Chicago area, and the system comparing them ran in New York. Light in optical fiber is about a third slower than in a vacuum: it covers roughly 127 miles every millisecond. That puts a hard floor under every quote, however fast the code is.

The speed limitLight in fiber ≈ 127 mi per ms

Where each price starts and how fast it can possibly reach me. Distances are great-circle; the times are the floor for light in fiber, which real cables only add to. Hover or tap a stop to see its route.

Route by route, the floor looks like this:

  • London → New York: 3,460 miles, at least 27 ms one way (18.6 ms even in a vacuum). Acting on a price there means a round trip, at least 54 ms.
  • Chicago area → New York: 710 miles, at least 5.6 ms one way and 11 ms round trip.
  • London ↔ Chicago: 3,950 miles between the exchanges themselves, at least 31 ms.

That floor hurts an arbitrage in two ways. First, the two prices never arrive together: even at the limit, a Polymarket quote reaches New York more than 20 ms after a Kalshi quote from the same instant. Second, acting on a gap takes a round trip, so by the time an order reaches London, the price it was based on is at least 54 ms old. Anyone with a server next to the exchange has had that whole window to take the gap first.

Moving the computer only moves the limit. You can put a server beside each exchange, as the low-latency setup I tested did, but the decision still needs both prices in one place, and the exchanges are 3,950 miles apart. Even a computer floating in the middle of the Atlantic would see one of the two prices at least 15 ms late. Real networks are slower still: cables don’t follow the great circle, and every hop on the way adds time.

So the platform never treats two quotes as simultaneous. It measures the gap between the two legs it compares (a median 52.3 ms in the live soaks), and its freshness and skew gates reject any pair whose prices are too far apart in time to trust.

The result was a no-go.

Multiple live soaks of 24 hours or more averaged 2.9 million order-book rows per day across 97 reviewed cross-market pairs. At the median, the two legs of a trade were 52.3 ms apart. Even at that precision, no pair cleared a one-cent profit once real fees and order-book depth were counted.

The long story

This started as a do-first, think-later project. First I scraped every public resource I could find from people who had tried something similar and pulled out what was useful. It wasn’t much.

Then came research into exactly how Kalshi and Polymarket operate, down to their fee structures, APIs, rate limits, and settlement mechanics.

Only then did the real problem show up: finding contracts on the two venues that were actually equivalent. Plenty of pairs looked nearly identical, but a small difference in resolution rules could have left me holding two losing positions instead of a hedged trade. Getting equivalence right mattered more than anything else in the project, so pair selection ran through both an AI-assisted screen and a manual review of the actual contract language. Out of hundreds of candidates, 97 pairs survived and were cleared for testing.

The pairs registry tab, listing candidate market pairs with badges for settlement equivalence, strategy eligibility, and scan status.
Pair review. Each pair carries three independent states: settlement equivalence (verified_equivalent), strategy eligibility (excluded), and scan status (approved_for_paper). A pair can be verified equivalent and still be excluded from every reported metric. Keeping those states separate stops a similar-looking contract from quietly entering the results.

Testing almost lied to me. An early run looked profitable until I traced it to a bid/ask normalization bug that was quietly inflating the spread. I fixed the live data path, wrote an idempotent backfill to correct the rows it had already touched, and grew the regression suite to 879 tests (532 unit and 347 PostgreSQL integration) so the bug couldn’t come back unnoticed. With the fix in, the apparent profit disappeared. That was the correct outcome. The project was supposed to find the true number, not one I liked.

That bug is a fair summary of the whole project. The exciting result was wrong, and the boring, correct one was no. I’d rather build something that tells me the truth than something that tells me what I want to hear. The bot didn’t survive contact with real fees, latency, and fine print, but the platform underneath it did, and that’s the part worth carrying forward.

What’s public, and what isn’t

Three things on this page point at this project. They aren’t the same:

  • The original research system. Private. The full 97 reviewed pairs and the live-order path that could place real trades. Every result on this page comes from here.
  • The open-source release. Public, MIT, paper-only. A reduced build with 23 reviewed pairs, all excluded from strategy metrics, so a scan records real order-book data and produces no strategy result by design. Every screenshot on this page comes from here.
  • The interactive diagram. A read-only map of the open-source code, pinned to a commit, where each box links to the file it describes.
The paper-trading tab of the research cockpit, showing scanner controls, cadence, and a counter reading 23 scannable with 0 counting toward strategy metrics.
The paper-trading tab in the open-source release. The eligibility counter reads 0 count toward strategy metrics: every bundled pair was excluded from strategy metrics during review, so a scan captures real market data and reports no edge by design.

Where I’d take it next

The arbitrage result was a no-go, but most of the infrastructure is reusable. The capture pipeline, the fee and depth models, and the contract-equivalence review don’t care which strategy sits on top of them. The same pipeline can test ideas that don’t need two simultaneous fills: mean reversion on a single contract, correlated markets that tend to move together, or tracking where attention and volume shift inside one market. Those carry real directional risk instead of a locked-in spread. That’s the opposite trade-off from this project, and it’s why I want to test them next.

Update: that work has started. The platform now has a point-in-time backtester covering 10,000+ markets, with as-of data views and automated checks for future leaks. Before trusting it, I used it to reproduce a published Polymarket study: 99% of 54K quotes matched. The numbers above describe the arbitrage study as it ended.

Look at how it works

The diagram behind the button below maps the open-source platform as it runs, pinned to a specific commit. Every box links to the code it describes, down to the exact file and line on GitHub.

It follows one path end to end. Two public order books arrive, get paired with a measured capture skew, get priced through the real per-venue fee engine, and become a depth-adjusted edge row. The parts that make the negative result trustworthy are on it too: the pair registry, whose equivalence screen can flag a pair but never clear one, and the mode gates and kill switch that keep the whole thing read-only.

See the repo as an interactive diagram →

Diagram generated with archify by tt-a1i (MIT).