PolyWatch: AI-Powered Insider Trading Detection for Prediction Markets Inspiration
Prediction markets like Polymarket have exploded in popularity, handling hundreds of millions in volume on events ranging from elections to geopolitics.
But with real money on the line and outcomes tied to real-world events, they're ripe for insider trading someone who knows the outcome of an event before it's public can quietly accumulate positions and profit enormously. Unlike traditional stock markets, there's no SEC watching. PolyWatch was built to fill that gap: an autonomous AI investigator that can analyze a Polymarket event and determine whether trading patterns suggest informed trading ahead of news.

How We Built It

The stack is Jaclang (a Python-superset with built-in React-like frontend support), backed by DeepSeek as the LLM reasoning engine.

The Investigation Engine

The core is a Tree-of-Thought DFS engine. Rather than a flat chain-of-thought, the AI builds a recursive investigation tree.

At each node, the LLM decides which of 26 specialized tools to call next, spanning 5 categories:

┌─────────────┬───────┬───────────────────────────────────────────────────────────────────┐ │ Category │ Tools │ What They Do │ ├─────────────┼───────┼───────────────────────────────────────────────────────────────────┤ │ Market │ 6 │ Trade data, price history, large trades, movers │ ├─────────────┼───────┼───────────────────────────────────────────────────────────────────┤ │ Statistical │ 6 │ Abnormal volume (z-scores), price run-ups, synchronized trading │ ├─────────────┼───────┼───────────────────────────────────────────────────────────────────┤ │ News │ 6 │ Timeline correlation, sentiment, pre-news trade detection │ ├─────────────┼───────┼───────────────────────────────────────────────────────────────────┤ │ Wallet │ 5 │ Profiling, PnL, win rates, first activity dating │ ├─────────────┼───────┼───────────────────────────────────────────────────────────────────┤ │ Network │ 3 │ Linked wallets, fund flows, co-occurrence graphs │ └─────────────┴───────┴───────────────────────────────────────────────────────────────────┘

The engine enforces coverage gates it won't close the root node until at least 3 categories are explored and 10+ tools have fired. This prevents shallow investigations. Confidence is computed through a gate system:

$$C = \begin{cases} \text{HIGH} & \text{if all } H_i \text{ met} \wedge |{M_j : M_j \text{ met}}| \geq 4 \ \text{MEDIUM} & \text{if } |H_{\text{met}}| \geq 2 \wedge |M_{\text{met}}| \geq 2 \ \text{LOW} & \text{otherwise} \end{cases}$$

The Dashboard

The frontend is a real-time investigation dashboard that polls every 2 seconds, showing:

  • Volume charts with automatic anomaly detection (days where $V_i > 2\bar{V}$ flagged red)
  • Price history with YES/NO lines rendered as SVG polylines
  • Suspect wallet table ranked by timing scores
  • Corroboration cards showing which evidence categories confirmed findings
  • A graph-based investigation tree showing the AI's reasoning path

Data Pipeline

All market data comes from Polymarket's CLOB API and Gamma Markets API. News is sourced from Google News RSS and Webz.io. The system cross-references trade timestamps against news publication times to detect the key signal: did someone trade profitably before the information was public?

Challenges

Jac's JSX compiler was the biggest technical hurdle. It doesn't support new keywords, the Python in operator compiles to JS's in (which checks object keys, not substrings), non-ASCII characters crash the parser, and deep conditional nesting silently breaks. Every frontend component had to be architected around these constraints helper functions for any logic, indexOf() instead of in, separate if/return blocks per tab.

Polling-induced UI flashing was another lesson — naively replacing the entire tree array every 2 seconds caused React to unmount and remount all nodes. The fix: diff by length before updating state, so re-renders only fire when data actually changes.

What We Learned

The biggest insight: autonomous AI investigation is only as good as its evidence coverage. Early versions would call 2-3 tools and declare "no insider trading found." The gate system - forcing breadth before allowing conclusions, dramatically improved investigation quality. The AI doesn't just answer
the question; it builds a case, with citations linking every claim to a specific evidence artifact.

Built With

  • deepseek
  • googlenewsrss
  • jaclang
  • polymarketapi
  • polymarketgammaapi
  • python
  • react
  • svg
  • tailwind
  • webz.ioapi
  • zod
Share this project:

Updates