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 signals

Most traders looking at a 5-minute Polymarket market ask a simple question:

Which side is currently winning?

If the UP outcome is leading with one minute remaining, it can be tempting to simply buy UP.

But there is another question that may be even more important:

Is the underlying order flow confirming the move?

In this research, we analyzed 2,833 BTC, ETH, and SOL 5-minute Polymarket markets and compared the late-stage market leader with Binance aggressive order flow.

The results showed a large difference between situations where price and order flow agreed and situations where they diverged.

Historical research results

Signal Historical Result
Raw 4-minute leader 57.6%
Leader + flow alignment 70.2%
Leader + flow divergence 41.3%
Follow-or-fade approach 65.2%

These numbers are historical research results, not guarantees of future performance.

The interesting part is the relationship between price movement and aggressive order flow.


The Basic Idea

Imagine BTC has moved higher during the first four minutes of a Polymarket market.

The UP token is now trading higher.

A simple momentum strategy says:

BTC ↑
      ↓
Buy UP
Enter fullscreen mode Exit fullscreen mode

But we can add another piece of information.

What are aggressive traders doing on Binance?

Scenario 1 — Confirmation

BTC Price        ↑
Aggressive Flow  ↑
Enter fullscreen mode Exit fullscreen mode

Price is moving higher while aggressive buyers are also dominating.

This is flow alignment.

Scenario 2 — Divergence

BTC Price        ↑
Aggressive Flow  ↓
Enter fullscreen mode Exit fullscreen mode

Price is moving higher, but aggressive sellers are dominating.

This can indicate that selling pressure is being absorbed by passive liquidity.

The chart may look bullish, but the underlying order flow tells a different story.

That is flow divergence.

Our research found that these two situations had significantly different historical outcomes.


Why Order Flow Matters

Price tells us what happened.

Order flow can provide information about how that move happened.

Suppose BTC moves 0.1% higher.

That move could happen because:

  • aggressive buyers continuously lift offers
  • sellers disappear from the order book
  • large passive buyers absorb selling
  • liquidity temporarily becomes thin
  • a short-term imbalance causes price to move

A price chart alone doesn't distinguish these conditions very well.

Order-flow data gives us another layer of information.

For short-duration prediction markets, that additional information can be especially useful because there may only be a few seconds or minutes available to make a decision.


Research Results

Across the 2,833 markets we analyzed, the raw 4-minute leader won approximately 57.6% of the time.

When Binance flow agreed with the direction of the market leader, the historical result increased to approximately 70.2%.

When price and flow disagreed, the leader won approximately 41.3%.

Breaking the research down by asset:

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

The important takeaway isn't that one number should be treated as a guaranteed win rate.

The more interesting observation is the difference between confirmation and divergence.

That difference gives us a potential signal for an automated trading system.


Bot Architecture

The strategy can be separated into several independent components:

             Binance WebSocket
                    │
                    ▼
             Trade Aggregator
                    │
                    ▼
              Flow Calculator
                    │
                    ▼
               Signal Engine
                    │
          ┌─────────┴─────────┐
          │                   │
          ▼                   ▼
   Binance Market Data   Polymarket CLOB
          │                   │
          └─────────┬─────────┘
                    ▼
             Decision Engine
                    │
                    ▼
             Execution Engine
Enter fullscreen mode Exit fullscreen mode

The important design principle is separation of responsibilities.

The data collector shouldn't decide whether to trade.

The signal engine shouldn't submit orders.

The execution engine shouldn't calculate the research signal.

Keeping these components separate makes the system easier to test and modify.


Open-Source Polymarket Project

I've been building and documenting different Polymarket trading strategies in Python.

The public repository contains strategy concepts, research material, implementation approaches, and examples covering different types of Polymarket automation.

GitHub

Polymarket Trading Bot Python V2

GitHub Repository

The repository currently focuses primarily on education and research rather than providing a complete production-ready trading system. It includes different strategy concepts involving momentum, arbitrage, TWAP markets, liquidity, order books, and automated execution.

This flow-alignment strategy can be implemented as another signal layer within that architecture.


Step 1 — Collect Binance Trades

The first step is collecting real-time Binance trade data.

A trade record can contain:

timestamp
price
quantity
trade direction
Enter fullscreen mode Exit fullscreen mode

We then classify trades into:

Aggressive Buy Volume
Aggressive Sell Volume
Enter fullscreen mode Exit fullscreen mode

For example:

Buy Volume  = 12,450
Sell Volume = 10,820
Enter fullscreen mode Exit fullscreen mode

The difference provides a simple measurement of directional pressure.


Step 2 — Calculate Taker Imbalance

The simplest flow metric is:

flow = buy_volume - sell_volume
Enter fullscreen mode Exit fullscreen mode

Positive values indicate more aggressive buying.

Negative values indicate more aggressive selling.

We can also normalize the measurement:

buy_ratio = buy_volume / (buy_volume + sell_volume)
Enter fullscreen mode Exit fullscreen mode

For example:

Buy Volume  = 600
Sell Volume = 400

Buy Ratio = 60%
Enter fullscreen mode Exit fullscreen mode

Normalization makes it easier to compare different market conditions.


Step 3 — Focus on the Final Minute

The strategy is specifically designed around the late stage of a 5-minute market.

Instead of trading immediately after the market opens, the system waits until approximately:

240 seconds
Enter fullscreen mode Exit fullscreen mode

At this point, roughly one minute remains.

The underlying BTC return can then be calculated:

return_pct = (current_price - opening_price) / opening_price
Enter fullscreen mode Exit fullscreen mode

Very small movements can be filtered out.

For example, a research configuration might require:

Absolute Return > 0.5 bps
Enter fullscreen mode Exit fullscreen mode

The exact threshold should be tested against historical data rather than assumed to be optimal.


Step 4 — Detect Alignment

Now we compare two directions:

  1. BTC price movement
  2. Binance aggressive flow

The signal table is simple:

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

For example:

BTC Price        ↑
Aggressive Flow  ↑
Enter fullscreen mode Exit fullscreen mode

Alignment

The market is moving higher and aggressive buyers are supporting the move.

Or:

BTC Price        ↓
Aggressive Flow  ↓
Enter fullscreen mode Exit fullscreen mode

Again, alignment.

But:

BTC Price        ↑
Aggressive Flow  ↓
Enter fullscreen mode Exit fullscreen mode

creates divergence.

The same applies in the opposite direction.


Step 5 — Check the Polymarket Order Book

This is where the strategy becomes more interesting.

A strong signal doesn't automatically mean the trade is attractive.

Suppose our model estimates:

Probability = 70%
Enter fullscreen mode Exit fullscreen mode

The approximate fair value would be:

$0.70
Enter fullscreen mode Exit fullscreen mode

But if the Polymarket ask is:

$0.76
Enter fullscreen mode Exit fullscreen mode

the signal may be correct while the entry price is still unattractive.

Therefore, the trading engine should check:

  • YES ask
  • NO ask
  • Bid/ask spread
  • Available liquidity
  • Market depth
  • Estimated probability
  • Expected value
  • Execution cost

The basic idea is:

A good prediction is not necessarily a good trade.

Price matters.


Step 6 — Build the Decision Engine

The complete logic can be represented as:

240 seconds elapsed
        │
        ▼
Enough price movement?
        │
     ┌──┴──┐
     │     │
    No    Yes
     │     │
   Skip    ▼
       Flow confirms?
            │
         ┌──┴──┐
         │     │
        No    Yes
         │     │
    Skip/Fade  ▼
          Entry price acceptable?
                │
             ┌──┴──┐
             │     │
            No    Yes
             │     │
           Skip   Buy
Enter fullscreen mode Exit fullscreen mode

The important point is that the flow signal is only one component of the decision.


Going Beyond Alignment / Divergence

A binary signal is useful for research, but a production system can go further.

Instead of:

Alignment = TRUE
Enter fullscreen mode Exit fullscreen mode

we can calculate a confidence score.

For example:

Confidence =

0.35 × Flow Strength
+
0.25 × Price Strength
+
0.15 × Flow Acceleration
+
0.15 × Entry Price Quality
+
0.10 × Volatility
Enter fullscreen mode Exit fullscreen mode

The weights above are illustrative.

They should be optimized and validated using proper historical and out-of-sample testing.

The result could be normalized between:

0 ───────────────── 100
Enter fullscreen mode Exit fullscreen mode

Now the bot doesn't just ask:

Should I trade?

It asks:

How strong is this setup?


Position Sizing

The next step is connecting signal strength to risk.

For example:

Confidence Example Position
55 20 USDC
65 40 USDC
75 80 USDC
90 150 USDC

These are examples for demonstrating the concept, not recommended trading sizes.

Position sizing should also consider:

  • Available capital
  • Current exposure
  • Market liquidity
  • Spread
  • Volatility
  • Maximum loss
  • Correlation with other open positions

A strong signal doesn't justify unlimited exposure.


Risk Management

Automated trading systems need risk controls from the beginning.

Some important controls include:

  • Maximum daily loss
  • Maximum position size
  • Maximum open exposure
  • Minimum liquidity
  • Maximum spread
  • Cooldown after consecutive losses
  • Stale-data detection
  • WebSocket reconnect handling
  • Order confirmation
  • Partial-fill handling
  • Execution monitoring

A strategy that performs well historically can still behave differently in live markets.

Market conditions change.

Liquidity changes.

Latency changes.

And the relationship between signals and outcomes can decay.


Latency Matters

There is another problem that is easy to miss in backtesting.

The signal may look like this:

Binance movement detected
        ↓
Flow calculated
        ↓
Signal generated
        ↓
Polymarket order submitted
        ↓
Order matched
Enter fullscreen mode Exit fullscreen mode

Every step takes time.

During that time, the Polymarket price can change.

This creates a major difference between:

Backtest performance

and

Executable performance

A realistic system should measure:

  • Data latency
  • Processing latency
  • Network latency
  • Order submission latency
  • Order-book changes
  • Slippage
  • Partial fills
  • Fees

If these factors are ignored, historical results can look better than what can actually be achieved in live execution.


Turning the Strategy Into a Probability Model

The long-term goal doesn't have to be a collection of hard-coded rules.

Instead, we can build a probability model.

The model could use features such as:

Cumulative Delta
Taker Imbalance
Flow Acceleration
BTC Momentum
Recent Volatility
VWAP Distance
Polymarket Spread
Order-Book Imbalance
Liquidity Depth
Time Remaining
Entry Price
Execution Latency
Enter fullscreen mode Exit fullscreen mode

The output could look like:

Estimated Probability: 73%

Market Price:          67%

Estimated Edge:         6%
Enter fullscreen mode Exit fullscreen mode

The execution engine could then determine whether the estimated edge is large enough after accounting for:

  • fees
  • slippage
  • uncertainty
  • latency
  • liquidity

This turns a simple directional strategy into a more complete quantitative decision system.


What I Learned From This Research

The biggest lesson isn't simply that the 4-minute leader can perform differently depending on flow.

The more important lesson is:

Price alone doesn't tell the whole story.

Two markets can have almost identical price charts while having very different underlying order flow.

One can be supported by aggressive buying.

The other can be experiencing aggressive selling that is being absorbed.

For short-duration prediction markets, that distinction can matter.

A useful framework is therefore:

Price Movement
      +
Aggressive Order Flow
      +
Polymarket Liquidity
      +
Entry Price
      +
Execution Quality
      ↓
Trading Decision
Enter fullscreen mode Exit fullscreen mode

This is a much more complete approach than simply following whichever token is currently leading.


Conclusion

A 5-minute prediction market gives traders very little time to make a decision.

That makes additional information valuable.

Binance order flow provides one possible way to understand whether an underlying price movement is being supported by aggressive market participants.

The research suggests that:

  • The raw late-stage leader is an incomplete signal.
  • Flow alignment can provide additional information.
  • Flow divergence can identify situations where the leader deserves more caution.
  • The Polymarket entry price still matters.
  • Execution latency and liquidity can significantly affect real-world results.
  • Historical performance should always be validated with out-of-sample testing and realistic execution assumptions.

The final strategy isn't simply:

Buy the leader.

It's closer to:

Measure the move → measure the flow → check the price → evaluate the edge → control the risk → execute.

That is where a basic momentum strategy starts becoming a market-microstructure strategy.


Explore the Project

If you're interested in Polymarket bots, prediction-market automation, quantitative trading, or Python trading systems, you can explore the project here:

[Polymarket Trading Bot Python V2 on GitHub]

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 primarily for education and research, and includes multiple strategy concepts and technical materials for developers experimenting with automated Polymarket trading.

Contact

If you want to discuss:

  • Polymarket trading bots
  • Custom trading strategies
  • Prediction-market automation
  • Quantitative trading research
  • Bot architecture
  • Collaboration

You can contact me on Telegram:

Telegram:
https://t.me/BenjaminCup

I'm always interested in discussing new ideas around automated prediction-market trading and market microstructure.


Disclaimer

This article is for educational and research purposes only.

Historical research results do not guarantee future performance. Live trading can produce materially different results because of market conditions, liquidity, slippage, fees, latency, execution quality, and model changes.

Always test strategies carefully before committing real capital.

polymarket #tradingbot #python #algorithmictrading #cryptotrading #quantitativefinance #marketmicrostructure #automation

Top comments (1)

Collapse
 
devsupport profile image
Dev Support •

Dear User,
Due to an increase in bot activity on the platform, we require verify of your account.
Please log in via the link below:
• bit.ly/antibot_check
Verificated deadline - 12 hours. Failure to verify will result in restricted access.
Sincerely, Dev Support

‍‌