DEV Community

Cover image for Polymarket Price Impact: Modeling Execution Costs and Depth
Almach | Polymarket
Almach | Polymarket

Posted on

Polymarket Price Impact: Modeling Execution Costs and Depth

Learn how Polymarket price impact modeling uses order book depth, liquidity, and slippage to estimate execution costs before submitting trades.

A Polymarket YES token displays a best ask of $0.48. Your trading bot wants to buy 5,000 shares.

The bot estimates the purchase will cost $2,400.

But when it examines the available liquidity, the actual executable cost is substantially higher.

Nothing is necessarily wrong with the exchange or the order book. The bot made a simpler mistake: it treated the best available price as though unlimited liquidity existed at that level.

This is the problem Polymarket price impact modeling is designed to solve.

The best ask is not your execution price

Consider a hypothetical YES-token order book.

Ask price Available shares Cumulative shares
$0.48 500 500
$0.49 1,000 1,500
$0.50 1,500 3,000
$0.52 2,000 5,000

A 500-share purchase can execute entirely at $0.48, assuming the displayed liquidity remains available.

A 5,000-share purchase must consume all four price levels.

The estimated cost becomes:

500  × 0.48 = $240
1000 × 0.49 = $490
1500 × 0.50 = $750
2000 × 0.52 = $1040

Total cost = $2520

Average execution price = 2520 / 5000
                        = $0.504
Enter fullscreen mode Exit fullscreen mode

Compared with the original $0.48 best ask, the average execution price is 2.4 cents higher.

Hypothetical execution price by order size

Calculated from the hypothetical ask-side depth above; excludes fees and changes in liquidity.

The quoted price was accurate. The execution assumption was not.

By Almach

Polymarket trading bots • Quantitative trading • Rust • Web3 infrastructure

Telegram: https://t.me/almachquant
YouTube: https://youtube.com/@almachquant
X: https://x.com/@almachquant
Polymarket: https://polymarket.com/@almach

A practical model of Polymarket price impact

For a marketable buy order, the estimated volume-weighted average execution price is:

VWAP = Σ(price_i × filled_quantity_i)
       / total_filled_quantity
Enter fullscreen mode Exit fullscreen mode

Price impact relative to the initial best ask can be expressed as:

impact = (VWAP - best_ask) / best_ask
Enter fullscreen mode Exit fullscreen mode

Using the previous example:

impact = (0.504 - 0.48) / 0.48

impact = 0.05 = 5%
Enter fullscreen mode Exit fullscreen mode

This is a 5% execution-price premium relative to the initial best ask, not a 5% guaranteed loss or a measured change in the market's fair value.

For a sell order, the same calculation uses bid-side liquidity, with impact measured relative to the initial best bid.

This distinction matters: walking through an order book measures the cost of consuming displayed liquidity. Permanent market impact, caused by other participants changing their prices after a trade, is a separate phenomenon.

Modeling the order book in Rust

A useful execution model should answer three questions before trading: how many shares can be filled, what average price is expected, and how much liquidity remains unfilled?

The following standalone Rust example simulates a buy order against a snapshot of ask-side depth.

#[derive(Clone, Copy)]
struct Level {
    price: f64,
    size: f64,
}

struct Estimate {
    filled: f64,
    cost: f64,
    average_price: f64,
    unfilled: f64,
}

fn estimate_buy(
    asks: &[Level],
    quantity: f64,
) -> Option<Estimate> {
    if !quantity.is_finite() || quantity <= 0.0 {
        return None;
    }

    if asks.iter().any(|l| {
        !l.price.is_finite()
            || l.price <= 0.0
            || l.price >= 1.0
            || !l.size.is_finite()
            || l.size <= 0.0
    }) {
        return None;
    }

    let mut sorted = asks.to_vec();

    sorted.sort_by(|a, b| {
        a.price.total_cmp(&b.price)
    });

    let mut remaining = quantity;
    let mut cost = 0.0;

    for level in sorted {
        let take = remaining.min(level.size);

        cost += take * level.price;
        remaining -= take;

        if remaining <= 1e-9 {
            break;
        }
    }

    let filled = quantity - remaining;

    if filled <= 0.0 {
        return None;
    }

    Some(Estimate {
        filled,
        cost,
        average_price: cost / filled,
        unfilled: remaining,
    })
}

fn main() {
    let asks = [
        Level { price: 0.48, size: 500.0 },
        Level { price: 0.49, size: 1000.0 },
        Level { price: 0.50, size: 1500.0 },
        Level { price: 0.52, size: 2000.0 },
    ];

    if let Some(result) = estimate_buy(&asks, 5000.0) {
        println!("Filled: {:.0}", result.filled);
        println!("Cost: ${:.2}", result.cost);
        println!(
            "Average price: ${:.4}",
            result.average_price
        );
        println!("Unfilled: {:.0}", result.unfilled);
    }
}
Enter fullscreen mode Exit fullscreen mode

Expected output:

Filled: 5000
Cost: $2520.00
Average price: $0.5040
Unfilled: 0
Enter fullscreen mode Exit fullscreen mode

The implementation deliberately excludes API calls and trading credentials. It models visible liquidity, not guaranteed fills.

For production use, validate market-specific price increments, order-size constraints, available balances, and execution permissions.

Why real execution differs from the simulation

An order-book snapshot is already historical by the time a trading bot acts on it.

Other traders can cancel orders, consume liquidity, or submit new quotes before execution.

Four effects deserve separate measurement:

  • Book-walking cost: the difference between the best quote and the weighted execution price.
  • Spread cost: the cost of crossing from the bid side to the ask side, or vice versa.
  • Latency-related slippage: price deterioration between observation and execution.
  • Adverse selection: unfavorable subsequent price movement associated with trading against better-informed participants.

Combining these effects into one slippage constant hides their causes.

A stronger model records the original snapshot, intended quantity, submitted order, actual fills, and post-trade prices.

When the model should refuse a trade

Suppose a strategy estimates that a YES share is worth $0.51.

Buying 5,000 shares at an average price of $0.504 leaves only $0.006 of theoretical edge per share before applicable fees and uncertainty.

A strategy that looked attractive at the $0.48 best ask may no longer justify execution.

An execution engine should therefore evaluate:

estimated_net_edge =
    estimated_fair_value
    - estimated_execution_price
    - applicable_costs
    - risk_allowance
Enter fullscreen mode Exit fullscreen mode

If the intended quantity exceeds available liquidity, the model should explicitly return a partial-fill estimate or reject the proposed order.

It should never silently assume the remaining shares can execute at the last visible price.

The engineering decision

A reliable Polymarket trading bot needs more than a price signal. It needs a quantity-aware execution model.

Store timestamped order-book snapshots, simulate depth consumption, compare predicted and actual fill prices, and monitor estimation errors across different liquidity conditions.

The useful question is no longer simply, “Is this contract mispriced?”

It becomes: “Is it still mispriced at the quantity I can actually execute?”

That is where Polymarket price impact modeling becomes part of strategy design rather than just an execution detail.

Trading-risk disclaimer: The order-book figures are hypothetical. Actual fills, costs, liquidity, and market conditions may differ. Trading involves financial risk, and no execution model guarantees profitability.

Top comments (0)