DEV Community

Rust Engineer
Rust Engineer

Posted on

Building a Last-Entry Probability Capture Trading Bot on Polymarket with TypeScript

Over the past few months, I've been experimenting with automated trading systems on Polymarket.

One of the more interesting ideas I explored was what I call a Last-Entry Probability Capture Strategy.

The concept sounds simple:

Instead of trying to predict market direction, wait until the final moments before resolution and look for markets where the remaining uncertainty appears overpriced.

In theory, you're not forecasting the future. You're attempting to capture the gap between the market price and what appears to be a near-certain outcome.

As it turns out, the strategy was much more challenging than it looked on paper.

The Core Idea

Imagine a market trading at:

  • YES = 0.88
  • NO = 0.12

If the market ultimately resolves YES:

  • Cost = $0.88
  • Payout = $1.00
  • Gross return = 13.6%

At first glance, that sounds attractive.

The break-even point is straightforward:

You need to be correct more often than the implied probability of your entry price.

For an entry at 0.88, you need a win rate above 88%.

The idea is not to predict outcomes.

The idea is to identify situations where the market is temporarily mispricing the remaining uncertainty.

In other words:

Can you find moments where the market says 88%, but reality is closer to 95%, 98%, or 99%?

That question became the foundation of the project.

Initial Assumption

My original assumption was simple:

As a market approaches resolution, information becomes increasingly complete.

If traders are slow to react or liquidity becomes fragmented, temporary pricing inefficiencies may appear.

Those inefficiencies could potentially create opportunities for automated execution.

The challenge was determining whether those opportunities actually survive real-world execution.

System Architecture

The bot was built around several independent components:

Polymarket Markets
        │
        ▼
Market Scanner
        │
        ▼
Signal Engine
        │
        ▼
Risk Filter
        │
        ▼
Execution Engine
        │
        ▼
Order Manager
        │
        ▼
Trade Analytics
Enter fullscreen mode Exit fullscreen mode

Market Scanner

The scanner continuously monitored active markets and filtered candidates based on:

  • Time remaining
  • Current probability
  • Spread size
  • Available liquidity
  • Historical behavior

The goal was to reduce thousands of market updates into a manageable set of opportunities.

Signal Engine

The signal engine evaluated whether a market met the strategy criteria.

Typical factors included:

  • Probability threshold
  • Remaining time
  • Spread conditions
  • Liquidity requirements

Only markets passing all conditions were forwarded to execution.

Risk Filter

Before submitting an order, the bot evaluated:

  • Position sizing
  • Maximum exposure
  • Current inventory
  • Available liquidity
  • Expected slippage

This layer prevented aggressive entries during poor market conditions.

Execution Engine

Execution turned out to be the most important component in the entire system.

Theoretical edges are easy.

Capturing them consistently is much harder.

The Reality of Execution

The biggest lesson from this project was that strategy logic is only half the problem.

Execution quality determines whether the edge survives.

1. Liquidity Disappears Quickly

One assumption I underestimated was liquidity decay.

As resolution approaches, order books can change dramatically.

An opportunity that appears available at 0.88 may only be partially fillable.

The actual fill price may be:

  • 0.90
  • 0.91
  • 0.93

At that point, much of the theoretical edge has already disappeared.

2. Slippage Matters More Than Expected

Backtests often assume perfect execution.

Reality does not.

A strategy that appears profitable on paper can become unprofitable when real fills are considered.

Tracking actual fill prices became one of the most important metrics in the system.

A small amount of slippage repeated hundreds of times can completely change performance.

3. Late Price Movements Are Violent

One of the largest risks appeared in short-duration crypto markets.

Markets that seem nearly resolved can still experience dramatic price changes in the final moments.

A market trading at:

YES = 0.88

can rapidly move lower if underlying price action changes unexpectedly.

The closer you trade to resolution, the more sensitive you become to sudden market reactions.

4. Resolution Risk Exists

Another challenge was resolution itself.

Not every market resolves immediately.

Close calls, oracle delays, and boundary conditions occasionally introduce uncertainty that isn't reflected in a simple probability calculation.

Capital can remain locked longer than expected.

What Markets Worked Best?

During testing, the most practical candidates were:

  • BTC 15-minute markets
  • ETH 15-minute markets

These markets generally offered:

  • Higher liquidity
  • Tighter spreads
  • More consistent order books
  • Better execution conditions

Lower-liquidity markets often produced theoretical opportunities that disappeared once execution was considered.

Performance Improvements

Much of the engineering effort eventually shifted away from strategy design and toward infrastructure.

Areas of focus included:

  • Faster market scanning
  • Reduced execution latency
  • Better connection management
  • Lower processing overhead
  • Improved monitoring

In one iteration, I reduced execution latency from roughly 100ms to around 50ms.

While that improvement didn't magically create profits, it significantly improved consistency during periods of heavy activity.

The Biggest Lesson

The most important takeaway from this project is that finding an apparent edge is relatively easy.

The difficult part is determining whether that edge survives:

  • Fees
  • Slippage
  • Liquidity constraints
  • Latency
  • Market microstructure

A strategy can look excellent in a spreadsheet and fail completely in production.

The market doesn't care about theoretical profitability.

It cares about execution.

Final Thoughts

What started as a simple idea became a useful lesson in trading system design.

The strategy itself was interesting, but the engineering challenges turned out to be even more valuable:

  • Real-time data processing
  • Risk management
  • Low-latency execution
  • Market microstructure analysis
  • Performance optimization

Whether the strategy ultimately succeeds or fails long term, building the system provided a much deeper understanding of how prediction markets behave under real trading conditions.

And that's often where the most useful lessons come from.

Top comments (0)