DEV Community

Cover image for Building a Polymarket TWAP Breakout Detection Bot
Polymarket Trader & Web3 Dev
Polymarket Trader & Web3 Dev

Posted on

Building a Polymarket TWAP Breakout Detection Bot

Explore how a Polymarket TWAP breakout bot detects crypto momentum, TWAP divergence, probability changes, liquidity conditions, and false breakouts.

A crypto market can move sharply while a time-weighted average moves much more gradually.


About the Author

Soulcrancerdev specializes in the engineering and quantitative research behind automated prediction-market trading.

Get in touch:
Github: https://github.com/thesoulcrancerdev/poly-trading-strategies
X: https://x.com/soulcrancerdev
Community: https://t.me/+SxEC7bVXYyphNzI5
Telegram: https://t.me/soulcrancerdev
Gmail: mailto:misssilverbeauty0927@gmail.com
Youtube: https://youtube.com/@soulcrancerdev


That difference is easy to overlook. But for short-duration Polymarket crypto markets, it creates an interesting research problem: can a trader detect a breakout in the underlying market before the TWAP-based reference fully reflects it?

The answer is not simply “build a faster bot.” The difficult part is determining whether the movement is a genuine regime change or merely a short-lived price shock.

The Core Question

Can a Polymarket TWAP breakout bot identify statistically meaningful price acceleration before the corresponding TWAP and prediction-market probability fully adjust?

That requires monitoring three things simultaneously:

Spot movement → TWAP response → Polymarket market response

The interesting signal exists in the relationship between them.

Why TWAP Changes the Problem

Polymarket's current documentation provides Chainlink-computed 30-second and 60-second TWAP prices, available through Polymarket RTDS. The documentation explicitly describes these as lookback windows rather than publication cadences. ([Polymarket Documentation][1])

That distinction matters.

A 60-second TWAP is not simply “the price from one minute ago.” It represents a time-weighted value across a window. Therefore, a sudden underlying price movement does not instantly translate into the same-sized TWAP movement.

For example:

Hypothetical example

Suppose BTC moves rapidly from $100,000 to $101,000.

A breakout detector should not ask only:

“Did BTC rise?”

It should ask:

“How large is the current move relative to the movement already incorporated into the TWAP?”

A useful normalized measure is:

D_t = \frac{P_t - T_t}{T_t}
Enter fullscreen mode Exit fullscreen mode

where:

  • (P_t) = current reference/spot price
  • (T_t) = current TWAP
  • (D_t) = normalized spot-TWAP divergence

A large positive (D_t) means the current price has moved substantially above the TWAP.

But divergence alone is not a breakout signal.

Breakout Detection Needs Momentum

A better framework combines level, velocity, and persistence.

Define:

M_t = \frac{P_t-P_{t-k}}{P_{t-k}}
Enter fullscreen mode Exit fullscreen mode

and:

D_t = \frac{P_t-T_t}{T_t}
Enter fullscreen mode Exit fullscreen mode

Then the detector can require:

Breakout = Momentum + TWAP Divergence + Persistence

The third component is critical.

A single large price update could represent temporary volatility. A breakout becomes more interesting when subsequent observations continue moving in the same direction.

This creates a simple research state machine:

NORMAL
   ↓
ACCELERATION
   ↓
TWAP DIVERGENCE
   ↓
PERSISTENCE CHECK
   ↓
BREAKOUT CANDIDATE
   ↓
LIQUIDITY / EXECUTION CHECK
Enter fullscreen mode Exit fullscreen mode

The bot should therefore detect conditions, not blindly generate trades.

The Data Architecture

Polymarket's real-time market feed exposes order-book events including bids, asks, price changes and last-trade information. ([Polymarket Documentation][2])

Meanwhile, the Chainlink TWAP documentation describes RTDS as the recommended production integration for consuming Chainlink-computed TWAP updates. RTDS provides 30-second and 60-second windows and exposes the Chainlink observation timestamp separately from the timestamp when the update was submitted to RTDS. ([Polymarket Documentation][1])

That gives the detector two independent streams:

flowchart LR
    SPOT[Underlying Crypto Price] --> SIGNAL[Breakout Detector]
    TWAP[Chainlink TWAP] --> SIGNAL
    BOOK[Polymarket Order Book] --> EXEC[Execution Filter]
    SIGNAL --> CONFIRM[Signal Validation]
    CONFIRM --> EXEC
    EXEC --> MONITOR[Monitoring]

The timestamps should be preserved rather than replaced with the time the application happened to receive the message.

That distinction becomes especially important when measuring signal-to-market reaction.

What Most Traders Get Wrong

1. A large TWAP divergence is not automatically an edge

The divergence may already be reflected in the Polymarket price.

2. Faster is not automatically better

A fast detector operating on noisy data can generate more false breakouts.

3. The TWAP is not the spot market

Polymarket's market pages explicitly state that certain crypto Up/Down markets resolve using Chainlink TWAP data rather than arbitrary spot-market prices. ([Polymarket][3])

Therefore, comparing the wrong external price source against the settlement reference can produce a misleading signal.

4. The prediction-market price is part of the signal

A breakout in BTC does not automatically imply that buying “Up” is attractive.

The relevant question is whether the Polymarket probability has already incorporated the information.

Measuring the Signal

A useful research dataset should capture:

  • Chainlink TWAP value
  • Chainlink observation timestamp
  • underlying reference price
  • Polymarket bid
  • Polymarket ask
  • spread
  • order-book depth
  • trade price
  • signal timestamp
  • signal direction
  • subsequent TWAP movement

Then measure:

\Delta P_{\tau}=P_{t+\tau}-P_t
Enter fullscreen mode Exit fullscreen mode

for several future horizons (\tau).

This allows the researcher to ask a much better question:

After a breakout signal appears, does the TWAP continue moving in the predicted direction?

That is measurable.

Whether it creates executable trading value is a separate question.

The Most Important Filter: Execution

Suppose a breakout detector identifies a strong signal.

The market may already have repriced before an order can execute.

A useful decision chain is:

Signal → Information → TWAP reaction → Probability reaction → Liquidity → Execution

The final two stages are where many theoretical strategies disappear.

A wide spread, thin depth, adverse price movement, or stale data can turn an apparently strong signal into an unusable one.

A Better Experiment

Before deploying a live Polymarket breakout strategy, record signals without trading.

For every detected breakout, store:

  1. signal timestamp
  2. divergence
  3. momentum
  4. TWAP window
  5. Polymarket probability
  6. bid-ask spread
  7. available depth
  8. future TWAP direction
  9. future market-price movement

Then divide signals into buckets:

  • weak divergence
  • medium divergence
  • strong divergence
  • short persistence
  • long persistence

This reveals whether the signal is actually informative or merely correlated with volatility.

Most importantly, use only information available at the signal timestamp. Otherwise, look-ahead bias can make a useless detector appear predictive.

What This Means for Polymarket Developers

The strongest architecture is not a “buy when BTC pumps” bot.

It is a measurement system that continuously reconstructs the relationship between:

crypto price → TWAP → prediction probability → order book

The detector should first produce research events. Only after those events survive out-of-sample testing should execution logic become relevant.

Polymarket's RTDS documentation also notes that RTDS subscriptions begin with the next update and do not provide snapshot, history, or replay after a disconnect. A production system therefore needs its own persistent event storage and explicit gap detection. ([Polymarket Documentation][1])

Advanced Insights

1. The TWAP is both a reference and a filter.
It suppresses some instantaneous noise, meaning the divergence between spot and TWAP contains information about recent price acceleration—but not necessarily direction after costs.

2. Breakout magnitude should be normalized.
A fixed percentage threshold behaves differently across BTC, ETH, DOGE, and other assets. Volatility-adjusted thresholds are more defensible.

3. Persistence may matter more than the first spike.
The first movement identifies acceleration. Subsequent observations determine whether the acceleration survived.

4. Market probability is another state variable.
A strong underlying move with an unchanged prediction probability is structurally different from the same move after the market has already repriced.

5. Data integrity is part of the strategy.
A missing stream update can look like a flat market. A delayed event can look like an early signal. Timestamp quality is therefore a trading variable, not merely an engineering detail.

Failure Modes

A TWAP breakout detector can fail through:

  • temporary crypto volatility
  • stale or missing data
  • false breakout signals
  • Polymarket spread expansion
  • insufficient liquidity
  • adverse selection
  • execution delay
  • changing market regimes
  • overfitted thresholds
  • incorrect settlement assumptions

The biggest conceptual failure is confusing prediction with execution value.

Detecting a movement correctly does not prove that the movement could have been traded profitably.

Practical Engineering Takeaways

A serious implementation should:

  • store raw real-time events
  • preserve source timestamps
  • calculate spot-TWAP divergence
  • measure momentum and persistence
  • monitor Polymarket order-book conditions
  • detect data gaps
  • separate signal generation from execution
  • backtest without look-ahead bias
  • evaluate out-of-sample behavior
  • record every rejected and accepted signal

The objective is not simply to build a faster crypto breakout bot.

It is to determine whether the temporary disagreement between market price, TWAP, and prediction probability contains repeatable information.

That is the real research question.

Frequently Asked Questions

What is a Polymarket TWAP breakout bot?

It is an automated system that monitors rapid underlying-price movement relative to a Chainlink TWAP and evaluates whether the resulting divergence represents a potential breakout condition.

Is TWAP divergence itself a trading signal?

No. Divergence is an observation. Momentum, persistence, market probability, liquidity and execution conditions are needed to determine whether it is informative.

What data should a breakout detector store?

At minimum: TWAP values, source timestamps, reference prices, Polymarket prices, spreads, order-book depth and subsequent price movement.

Why monitor the Polymarket order book?

Because identifying a breakout does not guarantee that the corresponding market can be entered at a useful price.

Should breakout thresholds be fixed?

Not necessarily. Volatility-adjusted thresholds can reduce the problem of treating small and highly volatile assets identically.

Can this strategy guarantee profits?

No. Signal quality, liquidity, execution, market conditions and model error can materially change outcomes.

Conclusion

The interesting opportunity in a TWAP breakout system is not simply detecting that crypto is moving.

It is detecting when the underlying market, the TWAP reference, and the prediction-market probability temporarily disagree.

That disagreement can be measured. Whether it represents a durable trading signal must then be demonstrated through timestamped, out-of-sample research.

The practical next step is therefore simple: build the event recorder before building the trader.

Trading & Financial Disclaimer

Examples in this article are hypothetical. Past observations do not guarantee future results. Trading involves risk, and execution, liquidity, fees, model error, data quality, and changing market conditions can materially affect outcomes.

Top comments (0)