Short-duration crypto prediction markets are an interesting environment for automated trading.
A typical Polymarket 5-minute BTC Up/Down market asks a simple question:
Will BTC be higher or lower at the end of the 5-minute interval?
The challenge is that the prediction market price changes continuously while the underlying BTC market is moving much faster.
This creates an opportunity for a trading bot to combine:
- Real-time BTC momentum
- Prediction-market pricing
- TWAP execution
- Dynamic risk management
Instead of immediately buying the entire position when BTC starts moving, the bot gradually accumulates the predicted outcome while momentum remains favorable.
The basic architecture looks like this:
BTC / Crypto Market
│
▼
Real-Time Market Data
│
┌───────────┴───────────┐
│ │
▼ ▼
Price Momentum Order Book Data
│ │
└───────────┬───────────┘
▼
Momentum Model
│
▼
UP Probability
│
▼
Entry Condition
│
▼
TWAP Engine
│
┌──────────┴──────────┐
▼ ▼
Buy UP Stop / Exit
What Is the Strategy?
The strategy combines momentum trading with TWAP execution.
Suppose BTC starts moving upward rapidly during a 5-minute Polymarket market.
A simple directional model might determine:
BTC momentum = positive
Estimated probability of UP = 72%
Polymarket UP price = $0.61
The bot sees a potential difference between its estimated probability and the market price.
If the model estimates a 72% probability while the market is pricing UP at only 61%, there may be positive expected value.
Instead of buying the entire position immediately, the bot uses TWAP.
For example:
Target position = 1,000 UP shares
TWAP duration = 60 seconds
Number of executions = 12
Order size = ~83 shares
The bot then executes approximately every 5 seconds.
0s → 83 UP
5s → 83 UP
10s → 83 UP
15s → 83 UP
...
55s → 83 UP
However, there is an important difference from traditional TWAP.
The bot should not blindly continue buying.
If momentum disappears, the TWAP process should stop.
The Real Analogy: Driving With Cruise Control
A useful analogy is driving a car.
Imagine you want to travel 10 kilometers.
A traditional TWAP strategy is like saying:
"Drive exactly 1 kilometer every minute regardless of traffic."
That is simple, but not intelligent.
Our momentum-aware TWAP strategy is different.
It is more like:
"Maintain the target speed while road conditions remain favorable, but slow down or stop if traffic suddenly changes."
The TWAP engine controls the speed of execution.
The momentum model watches the road conditions.
So:
Momentum model
↓
"Conditions are favorable"
↓
TWAP continues
Momentum model
↓
"Conditions are deteriorating"
↓
TWAP slows/stops
This distinction is extremely important.
Why Combine Momentum With TWAP?
A pure momentum strategy has a problem.
Imagine BTC suddenly moves:
BTC
100,000
100,020
100,050
100,090
100,150
A bot detects the move and immediately purchases a large UP position.
But other traders may have already reacted.
The UP price could move from:
$0.48 → $0.56 → $0.64
If the bot buys everything at $0.64, its entry price may be poor.
TWAP attempts to reduce this execution problem by distributing the entry.
Instead of:
BUY 1,000 shares immediately
the bot might execute:
BUY 100
wait
BUY 100
wait
BUY 100
wait
...
This gives the system time to observe whether the momentum continues.
Step 1: Collect Short-Term BTC Data
The first component is a real-time BTC price feed.
The bot maintains a rolling history.
For example:
price_history = [
(timestamp_1, price_1),
(timestamp_2, price_2),
...
]
The important thing is that the strategy is not looking only at the current price.
It is calculating returns over multiple horizons.
For example:
10-second return
30-second return
60-second return
The idea is to detect both very short-term acceleration and broader short-term direction.
Step 2: Calculate Momentum
A simple return calculation is:
def calculate_return(current_price, previous_price):
return (current_price - previous_price) / previous_price
For example, suppose BTC is:
60 seconds ago: $100,000
30 seconds ago: $100,040
10 seconds ago: $100,080
Current: $100,120
Then:
Return 60s ≈ +0.12%
Return 30s ≈ +0.08%
Return 10s ≈ +0.04%
All three are positive.
That tells us the market has upward short-term momentum.
Step 3: Combine Multiple Momentum Signals
Instead of relying on one measurement, we can create a weighted momentum score.
For example:
momentum = (
0.25 * return_10s +
0.35 * return_30s +
0.40 * return_60s
)
The weights can be optimized through backtesting.
For example:
10s return → 25%
30s return → 35%
60s return → 40%
The longer-term signal receives more weight because it may contain less microstructure noise.
But this is not necessarily optimal.
A faster strategy might give more weight to the 10-second return.
For example:
momentum = (
0.45 * return_10s +
0.35 * return_30s +
0.20 * return_60s
)
The correct parameters should be determined through historical testing rather than assumed.
Step 4: Add EMA Slope
Returns tell us how much BTC moved.
An EMA can tell us whether the short-term trend is strengthening or weakening.
For example:
ema_fast = calculate_ema(prices, period=20)
ema_slow = calculate_ema(prices, period=50)
ema_slope = ema_fast - ema_slow
If:
EMA20 > EMA50
and the difference is increasing, the short-term trend is strengthening.
We can therefore incorporate the signal:
Momentum
+
EMA trend
=
stronger directional signal
Step 5: Volume Acceleration
Price alone does not tell the entire story.
Suppose BTC moves upward by 0.10%.
Scenario A:
Price: +0.10%
Volume: normal
Scenario B:
Price: +0.10%
Volume: suddenly 3× normal
The second move may be more significant.
A simple volume acceleration metric could be:
volume_acceleration = current_volume / average_volume
For example:
Current volume = 1,500 BTC
Average volume = 500 BTC
Volume acceleration = 3.0
That can strengthen the momentum signal.
Step 6: Order-Book Imbalance
Another useful feature is BTC order-book imbalance.
Suppose the top levels of the order book look like:
Bids:
$100,100 → 500 BTC
$100,090 → 400 BTC
$100,080 → 300 BTC
Asks:
$100,110 → 100 BTC
$100,120 → 120 BTC
$100,130 → 150 BTC
There is significantly more buying liquidity than selling liquidity.
A simplified imbalance calculation is:
imbalance = (
bid_volume - ask_volume
) / (
bid_volume + ask_volume
)
The result is between approximately:
-1 → strong selling pressure
0 → balanced
+1 → strong buying pressure
For example:
bid_volume = 1,200
ask_volume = 370
imbalance ≈ 0.53
This can be another input to the momentum model.
Step 7: Build a Composite Momentum Score
Now we can combine everything.
For example:
momentum_score = (
0.20 * normalized_return_10s +
0.30 * normalized_return_30s +
0.25 * normalized_return_60s +
0.10 * normalized_ema_slope +
0.05 * normalized_volume_acceleration +
0.10 * orderbook_imbalance
)
The result might look like:
Momentum score = 0.72
We could define:
score > +0.50 → bullish
score < -0.50 → bearish
otherwise → neutral
Therefore:
if momentum_score > 0.50:
direction = "UP"
elif momentum_score < -0.50:
direction = "DOWN"
else:
direction = "NEUTRAL"
This creates the signal layer.
Step 8: Don't Trade Momentum Alone
This is one of the most important parts of the strategy.
A strong BTC momentum signal does not automatically mean that buying UP is profitable.
We also need to look at the Polymarket price.
Suppose:
Model probability of UP = 72%
Polymarket UP price = $0.61
Ignoring fees and other execution effects, the simplified expected value per share is:
EV = probability × payout - entry price
EV = 0.72 × $1.00 - $0.61
EV = +$0.11
That is potentially attractive.
But suppose the market has already moved:
Model probability = 72%
UP price = $0.73
Then:
EV = 0.72 - 0.73
EV = -$0.01
The momentum signal can be correct while the trade is still unattractive.
This is why the strategy should have two independent components:
Directional Signal
+
Market Pricing
↓
Expected Value
↓
Trade / No Trade
Step 9: Convert Momentum Into Probability
Instead of using momentum directly as a buy signal, we can convert it into an estimated probability.
For example:
probability_up = model.predict_proba(features)
A simple conceptual model could be:
Momentum score = +0.75
Estimated UP probability = 74%
Then compare:
Estimated probability = 74%
Market price = 62%
Edge = 12%
We can define:
edge = probability_up - polymarket_up_price
Then:
if edge > minimum_edge:
start_twap()
For example:
if probability_up > 0.70 and edge > 0.05:
start_twap("UP")
Step 10: The TWAP Execution Engine
Now we get to the execution component.
Suppose the bot wants:
Target position: 1,000 shares
TWAP duration: 60 seconds
Execution interval: 5 seconds
Then:
60 / 5 = 12 executions
Approximately:
1,000 / 12 ≈ 83 shares per execution
The execution engine becomes:
for i in range(12):
if momentum_is_valid():
execute_order(83)
sleep(5)
But this is still too simple for a production bot.
We need to continuously reevaluate the market.
Dynamic TWAP
A better implementation is a dynamic TWAP.
Instead of:
83
83
83
83
83
83
every interval, the order size can change according to signal strength.
For example:
Momentum score
0.55 → small order
0.65 → medium order
0.80 → larger order
0.90 → aggressive order
Conceptually:
if momentum_score > 0.80:
order_size = 120
elif momentum_score > 0.65:
order_size = 90
elif momentum_score > 0.50:
order_size = 60
else:
stop_twap()
This transforms ordinary TWAP into signal-aware execution.
The Most Important Feature: Momentum Reversal Detection
The bot should constantly ask:
Is the reason for entering the trade still valid?
Imagine:
BTC +0.10%
BTC +0.15%
BTC +0.22%
BTC +0.30%
The bot starts accumulating UP.
Then suddenly:
BTC +0.30%
BTC +0.20%
BTC +0.08%
BTC -0.05%
Momentum has reversed.
The bot should not say:
"My TWAP has another 30 seconds, so I must continue buying."
Instead:
Momentum reversal detected
↓
Cancel remaining TWAP orders
↓
Stop accumulating
↓
Evaluate existing position
This is what makes the strategy fundamentally different from a static TWAP.
Example Trade
Let's walk through a hypothetical 5-minute BTC market.
Suppose a new market opens:
BTC 5-Minute Up/Down
Current BTC price: $100,000
UP price: $0.48
DOWN price: $0.52
The bot begins collecting data.
After 45 seconds:
10s return: +0.05%
30s return: +0.11%
60s return: +0.18%
EMA slope: positive
Volume acceleration: 1.8×
Order-book imbalance: +0.42
The composite momentum score becomes:
+0.68
The probability model estimates:
UP probability = 71%
The market is pricing UP at:
$0.58
Therefore:
Estimated probability = 71%
Market probability = 58%
Estimated edge = 13 percentage points
The bot decides to enter.
TWAP Execution
Suppose the target position is:
600 UP shares
The bot chooses:
TWAP duration = 60 seconds
Interval = 5 seconds
Execution might look like:
00s → Buy 50
05s → Buy 50
10s → Buy 50
15s → Buy 50
20s → Buy 50
25s → Buy 50
At this point:
Position = 300 UP shares
But then BTC momentum weakens.
The model changes:
Momentum score
+0.68
↓
+0.61
↓
+0.42
↓
+0.18
The bot has a rule:
Stop TWAP if momentum < +0.30
Therefore:
Remaining target = 300 shares
TWAP stopped
The bot does not force itself to complete the 600-share order.
This is crucial.
Why Not Complete the Entire TWAP?
Because the original trade thesis has changed.
The original thesis was:
BTC momentum ↑
+
UP underpriced
↓
Buy UP
If momentum disappears:
BTC momentum →
↓
No directional advantage
↓
No reason to keep accumulating
Completing the TWAP simply because the timer has not finished would turn an intelligent strategy into a mechanical order splitter.
A Better State Machine
For a production bot, I would implement the strategy as a state machine.
┌─────────────┐
│ IDLE │
└──────┬──────┘
│
▼
Monitor BTC data
│
▼
Calculate momentum
│
▼
Check market price
│
Edge > threshold?
/ \
NO YES
│ │
▼ ▼
WAIT START TWAP
│
▼
Recalculate signal
│
┌──────────┴──────────┐
│ │
Momentum valid Momentum weak
│ │
▼ ▼
Continue TWAP STOP TWAP
│
▼
Risk management
│
▼
Market end
This architecture makes the strategy much easier to maintain.
Entry Conditions
A practical entry filter could look like:
if (
momentum_score > MOMENTUM_THRESHOLD
and probability_up > MIN_PROBABILITY
and edge > MIN_EDGE
and market_time_remaining > MIN_TIME
):
start_twap("UP")
For example:
Momentum > 0.50
Probability > 65%
Edge > 5%
At least 90 seconds remaining
These numbers are examples, not universal optimal values.
They should be determined through backtesting and live-market analysis.
Exit / Stop Conditions
The bot should also have explicit stop conditions.
For example:
if momentum_score < EXIT_MOMENTUM:
stop_twap()
if edge < MIN_EDGE:
stop_twap()
if spread > MAX_SPREAD:
stop_twap()
if volatility > MAX_VOLATILITY:
stop_twap()
Additional protections can include:
Maximum position size
Maximum daily loss
Maximum market exposure
Maximum slippage
Maximum order count
Market-data timeout
API failure protection
Why 5-Minute Markets Are Interesting
The 5-minute timeframe creates a particularly interesting environment.
The underlying BTC market can move significantly during a few minutes, while the prediction-market probability must continuously adjust.
That creates a feedback loop:
BTC moves
↓
Model detects momentum
↓
Prediction probability changes
↓
Traders react
↓
Polymarket price changes
↓
Available edge decreases
The opportunity may therefore exist only for a short period.
This means latency and execution quality matter.
The bot doesn't necessarily need to predict BTC perfectly.
It needs to answer three questions quickly:
1. Is momentum real?
2. Is the Polymarket price still inefficient?
3. Can I enter without giving away the edge?
TWAP vs Immediate Market Order
Consider two approaches.
Strategy A — Immediate Entry
Signal detected
BUY 1,000 UP immediately
Advantages:
- Simple
- Fast
- Guaranteed immediate attempt at entry
Disadvantages:
- Larger slippage
- Poorer average entry
- More vulnerable to sudden spread changes
- Entire position exposed immediately
Strategy B — Momentum TWAP
Signal detected
BUY 100
wait
BUY 100
wait
BUY 100
...
Advantages:
- More controlled execution
- Potentially lower market impact
- Allows signal reevaluation
- Can stop when momentum disappears
Disadvantages:
- May not complete the target position
- Price may move away
- Requires more sophisticated execution logic
The strategy is essentially trading off execution certainty versus information gained during execution.
A More Advanced Version
Once the basic version works, we can improve it significantly.
Instead of:
Momentum → TWAP
build:
BTC market data
↓
Feature engineering
↓
Momentum model
↓
Probability model
↓
Polymarket price
↓
Expected value
↓
Execution optimizer
↓
Dynamic TWAP
↓
Risk engine
The execution optimizer can determine:
Order size
Order frequency
Limit price
Maximum slippage
Remaining TWAP duration
based on current market conditions.
Example Python Architecture
A clean implementation could be divided into separate modules:
polymarket_twap_bot/
│
├── data/
│ ├── btc_feed.py
│ └── polymarket_feed.py
│
├── strategy/
│ ├── momentum.py
│ ├── probability.py
│ └── signal.py
│
├── execution/
│ ├── twap.py
│ ├── order_manager.py
│ └── slippage.py
│
├── risk/
│ ├── position.py
│ └── risk_manager.py
│
├── config.py
└── main.py
This separation is useful because the strategy and execution layers should not be tightly coupled.
For example:
signal = strategy.generate_signal(market_data)
if signal.should_trade:
twap.execute(
side=signal.side,
target_size=signal.target_size
)
The TWAP engine doesn't need to know exactly how momentum was calculated.
Simplified Strategy Loop
The overall bot can be represented as:
while market_is_open():
btc_data = get_btc_market_data()
polymarket_data = get_polymarket_market_data()
features = calculate_features(btc_data)
momentum = calculate_momentum(features)
probability = estimate_probability(features)
market_price = polymarket_data.up_price
edge = probability - market_price
if should_enter(momentum, probability, edge):
twap.start(
side="UP",
target_size=TARGET_SIZE
)
if twap.is_running():
if should_stop(
momentum,
probability,
edge
):
twap.stop()
sleep(UPDATE_INTERVAL)
The important design principle is that the signal is recalculated continuously.
Backtesting the Strategy
Before running the strategy with real money, the most important step is backtesting.
The backtest should simulate:
BTC price
BTC momentum
Polymarket price
Signal timestamp
Entry price
Execution delay
TWAP fills
Slippage
Fees
Market expiration
For each trade, record:
Market
Direction
Signal time
Momentum score
Model probability
Market price
Edge
Average entry
Maximum position
Final outcome
PnL
Then calculate:
Win rate
Average return
Expected value
Profit factor
Maximum drawdown
Average entry slippage
Average trade duration
Signal-to-execution latency
One particularly important metric is:
How much edge remains after TWAP execution?
A strategy can look excellent based on theoretical entry prices but become unprofitable after realistic execution costs.
Important Risk: Momentum Can Be Fake
One of the biggest problems with this strategy is false momentum.
For example:
BTC +0.08%
BTC +0.12%
BTC +0.20%
The model sees strong momentum.
But the move may simply be:
- temporary liquidity imbalance
- short-lived order-book activity
- market-maker adjustment
- liquidation event
- exchange-specific price movement
Then BTC reverses:
+0.20%
+0.05%
-0.10%
-0.25%
Therefore, the strategy should not rely on one signal.
Using multiple horizons is useful:
10s
30s
60s
because it helps distinguish a very short spike from more persistent movement.
Another Important Risk: Polymarket Price Already Adjusted
This is probably the most important conceptual risk.
Suppose BTC moves sharply upward.
Your bot detects it.
But thousands of other traders and market makers may detect the same move.
The Polymarket price might already adjust:
BTC momentum detected
UP:
$0.48
↓
$0.55
↓
$0.63
↓
$0.69
By the time your strategy enters:
Model probability = 72%
Market price = 69%
The remaining edge is only:
3 percentage points
After execution costs and uncertainty, that may not be enough.
Therefore:
The goal is not simply to predict the direction correctly. The goal is to identify situations where the market price has not fully incorporated the information yet.
That's a much stronger way to explain the strategy in your article.
Final Strategy Formula
The complete strategy can be summarized as:
BTC Real-Time Data
↓
10s / 30s / 60s Returns
+
EMA Slope
+
Volume Acceleration
+
Order-Book Imbalance
↓
Composite Momentum Score
↓
Probability Estimate
↓
Compare With Polymarket Price
↓
Calculate Edge
↓
Edge > Threshold?
│
YES
↓
Start Dynamic TWAP
↓
Continuously Recalculate Signal
↓
Momentum Valid?
/ \
YES NO
│ │
Continue Stop
TWAP TWAP
The Core Idea
The most important concept for readers to understand is:
Momentum determines whether we should trade. TWAP determines how we enter. Risk management determines when we stop.
That gives you three independent layers:
┌──────────────────────────┐
│ SIGNAL LAYER │
│ BTC Momentum + Model │
└────────────┬─────────────┘
↓
┌──────────────────────────┐
│ PRICING LAYER │
│ Probability vs Market │
└────────────┬─────────────┘
↓
┌──────────────────────────┐
│ EXECUTION LAYER │
│ Dynamic TWAP │
└────────────┬─────────────┘
↓
┌──────────────────────────┐
│ RISK LAYER │
│ Stop / Exposure / Limits │
└──────────────────────────┘
This is also a much stronger architecture for a production Polymarket Trading bot than simply describing the strategy as "TWAP + momentum."
One important disclaimer for the article: present the numerical thresholds and example PnL as hypothetical unless you have actual backtest/live-trading data. Avoid claiming profitability or a specific win rate without reproducible evidence.
🤝 Collaboration & Contact
If you’re interested in building trading bots, buy trading bots, collaborating, exploring strategy improvements, or discussing about this system, feel free to reach out.
I’m especially open to connecting with:
Quant traders
Engineers building trading infrastructure
Researchers in prediction markets
Investors interested in market inefficiencies
📌 GitHub Repository
This repo has some Polymarket several bots in this system.
You can explore the full implementation, strategy logic, and ongoing updates about 5 min crypto market here:
Benjam1nCup
/
Polymarket-trading-bot-python-V2
polymarket trading bot polymarket arbitrage bot polymarket bot polymarket trading bot polymarket arbitrage bot polymarket bot polymarket trading bot polymarket arbitrage bot polymarket bot polymarket trading bot polymarket arbitrage bot polymarket bot polymarket trading bot polymarket arbitrage bot polymarket bot polymarket trading 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.
Features
-
Explosive growth of Polymarket with surging trading volume and new short-term markets
-
Increasing dominance of automated bots and AI in 5-minute and 15-minute crypto prediction markets
-
Higher profitability potential through advanced arbitrage and market-making strategies
-
Stronger edge for Python-based bots with real-time orderbook intelligence and low-latency execution
-
Continuous evolution of sniper, ladder, stair, momentum, and copy trading strategies
-
Scalable daily profits as prediction markets move toward hundreds of billions in annual volume
-
Full future-proof architecture for new features, contracts, and high-frequency trading environments
Included Trading Bots
Designed for arbitrage, directional strategies, and ultra-short-term markets (including 5-minute and 15-minute rounds), this bot framework provides a robust…
💬 Get in Touch
If you have ideas, questions, or would like to collaborate or want these trading bots, don’t hesitate to reach out directly.
Feedback on your repo (based on your description & strategy)
Contact Info
Telegram
https://t.me/BenjaminCup
tags: polymarket,trading,bot,architecture,tutorial,TWAP


Top comments (0)