DEV Community

Benjamin-Cup
Benjamin-Cup

Posted on

Building a TWAP-Aware Polymarket Bot with Coinbase Market Data

Short-duration prediction markets are extremely sensitive to timing.

A few seconds of difference between two price feeds can sometimes become an interesting signal for an automated trading system.

Before Polymarket introduced its 60-second TWAP mechanism for crypto markets, I built several trading bots around a relatively simple idea:

Use a faster external exchange price to detect movements before they were reflected on Polymarket.

You can view a real-time video of a currently active Polymarket momentum arbitrage bot at this link.

My main external data sources were Coinbase and Binance.

During fast BTC movements, I observed Coinbase moving roughly 2–3 seconds before the corresponding price movement was reflected on Polymarket.

For a short-duration market, that timing difference can be significant.

But the introduction of TWAP changed the architecture completely.


What Changed With TWAP?

Before TWAP, it was possible to think about the strategy approximately like this:

Coinbase / Binance
        ↓
   BTC spot price
        ↓
   Polymarket
        ↓
   Trade
Enter fullscreen mode Exit fullscreen mode

The external exchange price could be compared relatively directly with what was happening on Polymarket.

After the TWAP mechanism was introduced, the settlement process became more time-dependent.

The simplified flow is now:

Coinbase / Binance
        ↓
   Market movement
        ↓
     Chainlink
        ↓
   60-second TWAP
        ↓
 Polymarket outcome
Enter fullscreen mode Exit fullscreen mode

This creates an important distinction.

If BTC suddenly moves on Coinbase, the Polymarket settlement price does not necessarily move to the same price immediately.

The TWAP incorporates price information over a time window.

So a bot needs to understand both:

  • the current market price
  • how the TWAP is likely to evolve

Coinbase Is Still Useful

The TWAP upgrade did not make Coinbase data irrelevant.

It changed how I use it.

I no longer treat Coinbase as a replacement for the settlement price.

Instead, I use Coinbase as an early market signal.

During fast market movements, Coinbase can still move before the corresponding Chainlink/TWAP-related value fully reflects the movement.

In my observations, this difference can be around 2–3 seconds.

That gives the strategy a different objective.

Instead of:

Coinbase price
      ≠
Polymarket price

→ Arbitrage
Enter fullscreen mode Exit fullscreen mode

the idea becomes:

Coinbase momentum
        ↓
Expected Chainlink movement
        ↓
Expected TWAP movement
        ↓
Polymarket market state
        ↓
Trade decision
Enter fullscreen mode Exit fullscreen mode

This is the foundation of my Momentum Arbitrage Bot.


From Price Arbitrage to Momentum Arbitrage

The original strategy was closer to:

Coinbase moved
      ↓
Polymarket hasn't reacted
      ↓
Trade the difference
Enter fullscreen mode Exit fullscreen mode

The newer strategy is more like:

Coinbase is moving
      ↓
Chainlink should follow
      ↓
TWAP will gradually incorporate the movement
      ↓
Analyze the expected effect
      ↓
Evaluate Polymarket pricing
      ↓
Trade if the conditions are favorable
Enter fullscreen mode Exit fullscreen mode

This is not simply arbitraging two prices.

The bot is looking for a timing and information gap between several systems:

  • Coinbase market data
  • Chainlink price updates
  • 60-second TWAP
  • Polymarket order book
  • market strike
  • time remaining until resolution

That last variable is especially important.

The same BTC movement can have completely different implications depending on whether there are:

10 minutes remaining
        ↓
5 minutes remaining
        ↓
60 seconds remaining
        ↓
10 seconds remaining
        ↓
Resolution
Enter fullscreen mode Exit fullscreen mode

What Does the Bot Monitor?

A useful implementation needs more than a Coinbase WebSocket.

The trading engine should maintain several pieces of state.

1. Coinbase Price Feed

Coinbase provides the fast external market signal.

The bot can track:

BTC/USD
Current price
Price change
Short-term momentum
Update frequency
Enter fullscreen mode Exit fullscreen mode

The purpose is to detect sudden market movements as early as possible.


2. Chainlink / TWAP State

The bot also needs settlement-related information.

For example:

Chainlink price
TWAP value
TWAP direction
TWAP change
Distance from strike
Enter fullscreen mode Exit fullscreen mode

Coinbase provides the early signal.

Chainlink/TWAP provides the settlement context.

The two should not be treated as interchangeable.


3. Polymarket Order Book

A directional signal by itself is not enough.

The bot also needs to understand the actual trading environment.

For example:

YES price
NO price
Bid depth
Ask depth
Spread
Liquidity
Order-book imbalance
Available size
Enter fullscreen mode Exit fullscreen mode

A strong momentum signal with poor liquidity may not be worth trading.

Execution quality matters just as much as signal quality.


4. Time Remaining

Time is one of the most important variables in a short-duration market.

For example:

Market starts
     ↓
10 minutes
     ↓
5 minutes
     ↓
1 minute
     ↓
10 seconds
     ↓
Resolution
Enter fullscreen mode Exit fullscreen mode

A BTC movement early in the market may not have the same effect as the same movement close to resolution.

Therefore, the strategy needs to be time-aware.


A Simple Example

Imagine a BTC Up/Down market.

Suppose Coinbase shows:

BTC = $100,000
Enter fullscreen mode Exit fullscreen mode

Then BTC suddenly moves:

$100,000 → $100,150
Enter fullscreen mode Exit fullscreen mode

Coinbase can reflect this movement almost immediately.

The Chainlink/TWAP-related value does not necessarily jump to $100,150 at the same time.

Instead, the new information gradually affects the 60-second TWAP.

Conceptually:

T0
Coinbase moves
      ↓
T1
Chainlink begins reflecting the movement
      ↓
T2
TWAP incorporates the new price information
      ↓
T3
Polymarket settlement-related state changes
Enter fullscreen mode Exit fullscreen mode

The trading engine is therefore trying to answer:

Can the Coinbase movement provide enough information about the future TWAP movement to justify a position before the market fully incorporates it?

That is the core question behind the strategy.


The Signal

A simplified version of the decision model looks like this:

Fast Market Movement
        +
TWAP Lag
        +
Time Remaining
        +
Distance From Strike
        +
Polymarket Liquidity
        ↓
   Trade Decision
Enter fullscreen mode Exit fullscreen mode

The bot should not simply buy whenever BTC moves.

Instead, it needs to evaluate questions such as:

  1. How large is the Coinbase movement?
  2. How quickly did the movement happen?
  3. Is momentum continuing?
  4. Is the market reversing?
  5. What is the current TWAP?
  6. Where is BTC relative to the strike?
  7. How much time remains?
  8. How much of the movement has already reached the TWAP?
  9. What are the current YES/NO prices?
  10. Is there enough liquidity for execution?
  11. Does the expected edge justify fees, slippage, and risk?

This transforms a simple price-feed bot into a market-state-aware trading system.


System Architecture

A simplified architecture looks like this:

                  ┌───────────────┐
                  │    Coinbase   │
                  │  Price Feed   │
                  └───────┬───────┘
                          │
                          ▼
                  ┌───────────────┐
                  │   Momentum    │
                  │    Engine     │
                  └───────┬───────┘
                          │
                          ▼
┌──────────────┐   ┌───────────────┐   ┌──────────────┐
│  Chainlink   │──▶│ Signal Engine │◀──│  Polymarket  │
│   / TWAP     │   │               │   │ Order Book   │
└──────────────┘   └───────┬───────┘   └──────────────┘
                           │
                           ▼
                    ┌────────────┐
                    │ Risk Engine│
                    └─────┬──────┘
                          │
                          ▼
                    ┌────────────┐
                    │ Execution  │
                    │   Engine   │
                    └────────────┘
Enter fullscreen mode Exit fullscreen mode

Each component has a specific responsibility.

Coinbase

Provides the fast external market signal.

Momentum Engine

Processes price updates and detects short-term momentum.

Chainlink / TWAP

Provides settlement-related context.

Polymarket

Provides the prediction-market state and order book.

Risk Engine

Determines whether a potential trade satisfies the strategy's risk constraints.

Execution Engine

Handles order submission, monitoring, and execution.


What We'll Build

In the next parts of this tutorial, I'll go deeper into the implementation.

The project will cover:

  • Connecting to Coinbase's real-time price feed
  • Processing BTC price updates
  • Calculating short-term momentum
  • Tracking Chainlink/TWAP-related state
  • Reading Polymarket market data
  • Comparing external momentum with Polymarket pricing
  • Building the momentum-arbitrage signal
  • Adding risk controls
  • Designing the execution layer
  • Testing the strategy with live and historical data

The goal is not to create a guaranteed-profitable bot.

Trading strategies can stop working as market conditions change.

Latency, liquidity, fees, slippage, execution quality, TWAP behavior, and market structure all matter.

The goal is to understand how to build the system and how the different data sources interact.


Source Code

I've published a public repository with examples and educational material related to my Polymarket trading-bot development:

GitHub logo Benjam1nCup / Polymarket-trading-bot-python-V2

polymarket trading bot polymarket bot polymarket twap bot polymarket arbitrage bot polymarket trading bot polymarket bot polymarket twap bot polymarket arbitrage bot polymarket trading bot polymarket bot polymarket twap bot polymarket arbitrage bot polymarket trading bot polymarket bot polymarket twap bot polymarket arbitrage bot polymarket bot

Polymarket Trading Bot | Polymarket Arbitrage Bot | Polymarket TWAP Trading Bot

An open-source and Strong Strategy collection of Polymarket trading bot and Polymarket arbitrage bot and Polymarket TWAP trading bot in Python for high-performance automated trading on polymarket crypto 5min and 15min markets.

Polymarket-benjamincup-bot-dashboard

This repository is primarily intended for educational and research purposes. It includes strategy concepts, implementation approaches, and selected performance screenshots to help developers understand how different automated trading strategies can be designed and tested.

The repository does not provide a complete production-ready trading bot source code. Instead, it provides strategy descriptions and research materials that you can use as a foundation for developing your own system.

If you are interested in building a Polymarket Trading Bot, you can follow my tutorials and use the concepts in this repository to develop your own implementation.

For users who prefer a ready-to-deploy solution or require custom strategy development, commercial…




The repository is intended for educational purposes.

For questions, collaboration, or custom trading-bot development:

Telegram: https://t.me/BenjaminCup


What's Next?

In the next part, we'll start with the most important component:

Building a real-time Coinbase price feed and converting raw BTC price updates into a short-term momentum signal.

From there, we'll connect that signal to the Polymarket market state and start building the actual decision engine.

Top comments (0)