DEV Community

Benjamin-Cup
Benjamin-Cup

Posted on

Building a Flow-Alignment Trading Bot for Polymarket 5-Minute BTC Markets

How Binance order flow can improve late-stage prediction market trading.


Introduction

Most traders assume that if the YES side is leading with one minute remaining, it's the obvious trade.

Our research suggests that's only half the story.

We analyzed 2,833 BTC, ETH, and SOL 5-minute Polymarket markets and discovered that the 4-minute leader is only reliable when Binance aggressive order flow confirms the move.

When price and order flow agree, the leader won 70.2% of the time.

When they disagreed, the leader won only 41.3%.

Flow Alignment

That means the same price movement can represent two completely different market conditions:

  • Confirmation (real buying or selling pressure)
  • Absorption (aggressive traders are being absorbed without moving price)

This article explains how to build a Python trading bot that detects this behavior in real time using the open-source repository:

Repository

Polymarket Trading Bot Python V2

The repository provides the trading infrastructure. We'll extend it with a quantitative signal engine based on Binance taker flow. The overall approach also aligns with the standard architecture of Polymarket's Python trading APIs and CLOB client.


The Research

We tested 2,833 crypto prediction markets.

The question was simple:

With 60 seconds remaining, should you trust the current leader?

Across every market:

  • Raw 4-minute leader: 57.6%
  • Leader with flow agreement: 70.2%
  • Leader with flow divergence: 41.3%
  • Follow-or-fade strategy: 65.2%

Breaking it down by asset:

Coin Alignment Divergence
BTC 70.3% 37.7%
ETH 71.5% 37.1%
SOL 68.9% 49.9%

The takeaway is simple:

Price becomes much more informative when aggressive order flow agrees with it.


Why Order Flow Matters

Price is only the visible result.

Order flow explains why price moved.

Suppose BTC rises during the first four minutes.

There are two possibilities.

Case 1

Price ↑

Aggressive buying ↑

This is confirmation.

Buyers are lifting offers and pushing the market higher.

Momentum is real.


Case 2

Price ↑

Aggressive selling ↑

Now something strange is happening.

Sellers are hitting bids...

...yet price refuses to fall.

That usually means larger passive buyers are absorbing the selling.

The move is much less trustworthy.

Your research showed these two situations have dramatically different outcomes.


Bot Architecture

The trading bot has six components.

Binance WebSocket
        │
        ▼
Trade Aggregator
        │
        ▼
Flow Calculator
        │
        ▼
Signal Engine
        │
        ▼
Polymarket API
        │
        ▼
Execution Engine
Enter fullscreen mode Exit fullscreen mode

The GitHub project already contains the foundation for connecting to Polymarket and placing trades. We simply add a new decision layer that scores each opportunity using Binance market microstructure.


Step 1 — Track Binance Trades

Subscribe to Binance Spot WebSocket.

Record every trade.

For every trade determine

  • buyer initiated
  • seller initiated
  • quantity
  • timestamp

Accumulate

Aggressive Buy Volume

Aggressive Sell Volume
Enter fullscreen mode Exit fullscreen mode

Step 2 — Calculate Taker Imbalance

For each market

Flow = Buy Volume − Sell Volume
Enter fullscreen mode Exit fullscreen mode

or

Buy Ratio = Buy / (Buy + Sell)
Enter fullscreen mode Exit fullscreen mode

Positive values indicate buying pressure.

Negative values indicate selling pressure.


Step 3 — Wait Until 240 Seconds

Do nothing for the first four minutes.

At exactly

240 seconds
Enter fullscreen mode Exit fullscreen mode

measure

Return = (Current Price − Opening Price) / Opening Price
Enter fullscreen mode Exit fullscreen mode

Ignore tiny movements.

For example

Absolute Return > 0.5 basis points
Enter fullscreen mode Exit fullscreen mode

Step 4 — Detect Alignment

Now compare price direction with flow direction.

Price Flow Signal
Up Buying Alignment
Down Selling Alignment
Up Selling Divergence
Down Buying Divergence

This single comparison produced the largest improvement in our study.


Step 5 — Read the Polymarket Order Book

Never buy simply because the signal exists.

Read

  • YES ask
  • NO ask
  • spread
  • available liquidity

Suppose

Historical probability

70%
Enter fullscreen mode Exit fullscreen mode

Fair value is

70 cents
Enter fullscreen mode Exit fullscreen mode

Buying

74 cents
Enter fullscreen mode Exit fullscreen mode

is already a negative expected-value trade.

Instead require

Ask ≤ Historical Probability

−

Safety Margin
Enter fullscreen mode Exit fullscreen mode

Price discipline is what converts a predictive signal into a profitable strategy.


Step 6 — Execute

The decision tree becomes extremely simple.

240 seconds

↓

Enough movement?

↓

No

↓

Skip

↓

Yes

↓

Flow agrees?

↓

No

↓

Skip or Fade

↓

Yes

↓

Ask cheap enough?

↓

No

↓

Skip

↓

Yes

↓

Buy Leader
Enter fullscreen mode Exit fullscreen mode

Going Beyond Binary Signals

The current research classifies trades as

Alignment

or

Divergence.

A production system should instead calculate a confidence score.

Example

Confidence

=

0.35 Flow

+

0.25 Price Strength

+

0.15 Flow Acceleration

+

0.15 Entry Price

+

0.10 Volatility
Enter fullscreen mode Exit fullscreen mode

Now every opportunity receives a score between

0

and

100
Enter fullscreen mode Exit fullscreen mode

Instead of making one decision...

...the bot ranks every opportunity.


Position Sizing

Not every signal deserves the same amount of capital.

Example

Score Position Size
55 20 USDC
65 40 USDC
75 80 USDC
90 150 USDC

This is far better than always trading a fixed amount.


Risk Management

Every production trading bot should enforce:

  • Maximum daily loss
  • Maximum open exposure
  • Minimum liquidity
  • Maximum spread
  • Cooldown after consecutive losses
  • Continuous performance monitoring

A strategy with a historical edge can still degrade as market behavior evolves.


Future Improvements

The next generation of the strategy should no longer ask:

"Is the leader winning?"

Instead it should estimate:

"What is the probability this leader wins given the current order flow, volatility, and market price?"

Useful features include:

  • cumulative delta
  • taker imbalance
  • order-flow acceleration
  • recent volatility
  • VWAP distance
  • Polymarket spread
  • liquidity depth
  • order-book imbalance
  • price acceleration
  • execution latency

Eventually this becomes a machine-learning probability model rather than a collection of hard rules.


Final Thoughts

The biggest insight from our research is not that the 4-minute leader wins frequently.

It's that price alone is an incomplete signal.

A late-stage leader only becomes meaningful when aggressive Binance order flow confirms the move.

That transforms a simple momentum strategy into a market microstructure strategy.

The practical lesson is straightforward:

  • Don't buy because the chart moved.
  • Buy because aggressive traders are pushing in the same direction.
  • And only buy when the market price still offers positive expected value.

In prediction markets, finding an edge is only half the challenge.

Paying the right price is what ultimately determines long-term profitability.

Top comments (0)