Explore how a Polymarket TWAP arbitrage bot detects price discrepancies, evaluates execution risk, and tests trading signals against oracle data.
A price discrepancy is not automatically an arbitrage opportunity.
Suppose Bitcoin moves sharply on a major exchange, but a short-duration Polymarket contract barely reacts. A bot comparing the two might interpret that delay as free money.
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
It isn't necessarily.
The contract could already reflect the expected settlement price. The displayed quote might lack executable liquidity. Or the underlying signal might have arrived too late.
The interesting question is not whether two prices differ. It's whether the difference remains economically meaningful after accounting for contract settlement, execution costs, and information timing.
The Core Question
Can a Polymarket TWAP arbitrage bot systematically identify temporary mispricing between external price information and prediction-market probabilities?
The answer depends on three clocks: the reference-price clock, the market-repricing clock, and the execution clock.
1. TWAP Is a Measurement, Not a Prediction
A time-weighted average price (TWAP) measures an asset's average price over a specified interval.
For evenly spaced observations:
A 60-second TWAP smooths brief price movements, but it also introduces a delay relative to the latest spot price.
That distinction matters.
A bot observing a sudden Bitcoin rally might estimate that a prediction contract is undervalued. But if settlement depends on a reference price at a particular time, the current spot price alone cannot establish the contract's fair value.
There is another complication: Chainlink TWAP is not a universal settlement mechanism for Polymarket markets. The exact market rules and designated price source determine what matters. A locally calculated Chainlink-based TWAP may be useful as a research signal without being the official resolution value.
Before developing the strategy, inspect the specific market's resolution conditions.
2. Where the Apparent Arbitrage Comes From
Consider a hypothetical binary contract paying $1 if Bitcoin finishes above a specified threshold.
The apparent seven-cent edge looks attractive. However, it is only a model-based opportunity, not risk-free arbitrage.
For a YES contract purchased at price q, with estimated settlement probability p:
Here, c represents expected per-share execution costs, including applicable fees and slippage.
If the probability estimate is wrong, the edge disappears.
A useful distinction is between settlement arbitrage, where payoffs can be locked in under defined conditions, and statistical arbitrage, where a model predicts that prices are temporarily inconsistent.
Most TWAP-based directional signals belong to the second category.
3. The Three-Clock Problem
A trading system must distinguish:
- Reference time: When the underlying price observation becomes relevant.
- Repricing time: When prediction-market participants incorporate that information.
- Execution time: When the bot's order actually becomes executable or fills.
A signal can be mathematically correct and commercially useless.
If the market reprices before the bot receives a fill, the opportunity was visible but not capturable.
That is why timestamp quality matters as much as model sophistication.
4. Engineering the Bot
A practical architecture separates observation from decision-making and execution.
The bot needs more than two WebSocket subscriptions.
It must maintain synchronized market observations, reconstruct available order-book depth, estimate fill prices, enforce position limits, and record why individual opportunities were accepted or rejected.
Its execution layer should also handle partial fills, stale quotes, reconnects, order-status uncertainty, and duplicate submission prevention.
Official API behavior, authentication, order types, and applicable fees must be checked against current documentation rather than assumed.
5. Testing Whether the Edge Survives
The first experiment should use historical or paper-trading data, not live capital.
Record the reference-price timestamp, local receipt timestamp, market bid/ask, available depth, model probability, estimated costs, and eventual settlement outcome.
Measure three quantities:
- Signal decay: How quickly does the apparent edge disappear?
- Fill-adjusted edge: Does the signal survive realistic executable prices?
- Calibration: When the model predicts 70%, does the event occur approximately 70% of the time across comparable observations?
Avoid reconstructing historical trades using quotes observed after the signal. That introduces look-ahead bias.
6. What Most Traders Get Wrong
A faster price feed is not automatically a better trading signal.
Chainlink Data Feeds, for example, can update according to heartbeat and deviation thresholds rather than continuously streaming every market tick. The observation timestamp and feed type must therefore be understood before computing an average.
Other overlooked problems include model overconfidence near settlement, disappearing order-book depth, and selecting only successful historical signals.
A backtest without realistic fills measures prediction quality, not executable trading performance.
7. Advanced Engineering Insights
Three details deserve particular attention.
First, signal age is a risk variable. A discrepancy observed 500 milliseconds ago and one observed several seconds ago should not necessarily receive identical execution treatment.
Second, model uncertainty should influence position size. A seven-cent estimated edge with substantial probability uncertainty may be less attractive than a smaller but more reliable edge.
Third, rejected trades are valuable data. Recording stale signals, insufficient liquidity, and failed risk checks helps identify whether the bottleneck is the model or the execution system.
8. Frequently Asked Questions
Is TWAP arbitrage risk-free? No. A directional probability estimate is not a guaranteed payoff.
Can Chainlink provide the reference data? Yes, where an appropriate feed exists, but the market's official resolution rules take precedence.
Is Python fast enough? Python can support research and prototyping. Production suitability depends on measured end-to-end latency and workload.
Should the bot use 30-second or 60-second TWAP? Compare both out of sample. Neither interval is universally superior.
Does a larger discrepancy mean greater profit? Not necessarily. It may indicate stale data, thin liquidity, or a mistaken probability model.
Conclusion
A Polymarket TWAP arbitrage bot is best understood as a probability-estimation and execution system, not simply a script comparing prices.
The difficult part is proving that a discrepancy exists at an executable price before the information advantage disappears.
Build the data recorder first. Validate the signal second. Connect live execution only after the evidence supports it.
Disclaimer: All numerical examples are hypothetical. Trading involves risk, and liquidity, fees, slippage, model errors, and changing market conditions can materially affect results. Past observations do not guarantee future performance.


Top comments (0)