Learn how to build a Polymarket market maker using Rust, inventory-aware quoting, bid-ask spreads, order management, and risk controls.
A market maker can buy at $0.48 and sell at $0.50, capture the two-cent spread, and still lose money.
The problem is rarely the spread calculation. It is what happens between the two trades.
Suppose your bid fills just before the market reprices to $0.44. Your ask at $0.50 is no longer competitive, and your inventory is worth less than you paid. You earned no round-trip spread. You simply bought into a falling market.
This is the central engineering problem when you build a Polymarket market maker: keeping quotes competitive without allowing inventory and adverse selection to overwhelm the expected spread revenue.
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
The spread is revenue potential, not profit
Consider a hypothetical YES-token order book.
| Quote | Price | Size |
|---|---|---|
| Best ask | $0.52 | 800 |
| Best bid | $0.48 | 1,200 |
The quoted spread is:
spread = best_ask - best_bid spread = 0.52 - 0.48 spread = 0.04 A market maker might submit a bid at $0.49 and an ask at $0.51, improving both sides of the existing market.
If both orders fill for equal quantities, the gross spread capture is $0.02 per matched share.
But that result assumes both executions occur. It also excludes applicable fees, inventory financing, price changes, and other costs.
A single-sided fill creates directional exposure. This is why market making cannot be reduced to continuously posting two limit orders.
Quote around a reservation price
A basic market maker starts with a fair-value estimate.
For a binary YES token, that estimate may come from a probability model, external reference data, or another research signal.
The model should produce a value between zero and one.
Instead of quoting symmetrically around fair value, an inventory-aware strategy adjusts its reservation price.
reservation_price = fair_value - inventory_skew * net_inventory bid = reservation_price - half_spread ask = reservation_price + half_spread Here, inventory_skew is a configurable risk coefficient, not a universal market constant.
If the bot holds too many YES shares, the reservation price decreases. Its quotes become less attractive for additional buying and more attractive for selling.
If inventory is negative, assuming short exposure is permitted and supported by the account's collateral and execution setup, the adjustment works in the opposite direction.
The goal is not to predict every price movement. It is to prevent repeated fills from pushing the portfolio into an uncontrolled position.
Implementing a quote calculator in Rust
The following Rust example calculates theoretical bid and ask prices using fair value, inventory, and a minimum spread.
It is a standalone quote model, not a complete Polymarket API client.
#[derive(Debug)] struct Quote { bid: f64, ask: f64, } fn calculate_quote( fair_value: f64, inventory: f64, skew: f64, spread: f64, tick: f64, ) -> Option<Quote> { if !fair_value.is_finite() || !(0.0..=1.0).contains(&fair_value) || !inventory.is_finite() || !skew.is_finite() || skew < 0.0 || !spread.is_finite() || spread <= 0.0 || !tick.is_finite() || tick <= 0.0 { return None; } let reservation = fair_value - inventory * skew; let half = spread / 2.0; let bid = ((reservation - half) / tick).floor() * tick; let ask = ((reservation + half) / tick).ceil() * tick; if !bid.is_finite() || !ask.is_finite() || bid <= 0.0 || ask >= 1.0 || bid >= ask { return None; } Some(Quote { bid, ask }) } fn main() { let quote = calculate_quote( 0.50, 100.0, 0.0001, 0.02, 0.01, ); match quote { Some(q) => println!( "Bid: {:.2}, Ask: {:.2}", q.bid, q.ask ), None => println!("No valid quote"), } } For these hypothetical inputs, the result is:
Bid: 0.48, Ask: 0.50 The positive inventory shifts both quotes below the original $0.50 fair value.
A production implementation must obtain the market's permitted tick size, enforce valid price and order-size constraints, and check available balances before submitting orders.
Why quote cancellation matters as much as placement
A market maker operates in a changing order book. Its quotes become stale whenever fair value, inventory, spread, or market conditions change.
A sensible execution cycle is:
Receive market update | Update fair value | Reconcile inventory and open orders | Calculate desired quotes | Check exposure limits | Cancel or amend stale orders | Submit permitted replacements | Reconcile acknowledgments and fills Order acknowledgments are not equivalent to fills.
Similarly, sending a cancellation request does not prove that the order can no longer execute. The bot must account for fills that occur while cancellation is pending.
This race condition is particularly dangerous when replacing quotes: the old order and its replacement may both create exposure.
The inventory problem gets worse near resolution
Prediction-market contracts introduce risks that ordinary spot-market quoting models do not fully capture.
A YES token may trade near $0.50 for an extended period, then move sharply toward zero or one as new information arrives.
Inventory that appeared manageable under normal conditions can suddenly dominate the portfolio's risk.
A market maker therefore needs limits on individual token positions, total market exposure, correlated positions, and outstanding order quantities.
Near resolution or during abnormal volatility, widening quotes or withdrawing liquidity may be preferable to maintaining a constant spread.
The appropriate decision depends on the market rules, available liquidity, and model uncertainty.
Testing before deploying capital
Backtesting a market-making strategy using midpoint prices is insufficient.
A realistic simulator needs order-book updates, queue-position assumptions, partial fills, cancellation delays, transaction costs, and adverse selection.
A useful test asks whether the strategy remains viable when only its bid fills before a price decline, rather than assuming every buy is eventually matched with a profitable sell.
Operational testing matters too. Disconnect the market-data stream. Restart the process with outstanding orders. Introduce delayed acknowledgments and duplicate events.
The system should recover its actual positions and outstanding orders before resuming quoting.
A reliable Polymarket market maker is not the bot that posts the tightest spread. It is the one that knows when its quotes are no longer worth keeping in the market.
Trading-risk disclaimer: This article is educational. Market making involves inventory losses, adverse selection, liquidity risk, execution uncertainty, and market-resolution risk. Profitability is not guaranteed.


