Understanding the complete lifecycle of an order—from API request to on-chain settlement.
If you've built trading bots, market-making systems, or analytics tools around Polymarket, you've probably used the API to place orders.
A typical workflow looks simple:
const order = await client.createOrder({...});
await client.postOrder(order);
The order appears in the market almost instantly.
But what actually happens behind the scenes?
Many developers assume every order is immediately submitted to Polygon. Others believe Polymarket operates like a traditional decentralized exchange where matching and settlement happen entirely on-chain.
Neither is true.
With the introduction of Polymarket CLOB V2, the platform uses a hybrid architecture that combines the performance of centralized exchanges with the security guarantees of blockchain settlement.
Understanding this architecture is critical if you're building:
In this article, we'll follow an order through the entire execution pipeline and explain exactly how Polymarket V2 processes trades.
CLOB stands for Central Limit Order Book.
Unlike automated market makers (AMMs) that determine prices using mathematical formulas, a CLOB matches buyers and sellers directly through an order book.
If you've traded on exchanges such as Binance, Coinbase, Kraken, or NASDAQ, you've already used a CLOB.
Polymarket V2 brings this model to prediction markets.
Instead of trading cryptocurrencies, users trade outcome tokens representing probabilities of future events.
Example:
Will Bitcoin exceed $200,000 before Jan 1, 2027?
The market may trade at:
YES = $0.68
NO = $0.32
These prices represent market-implied probabilities.
Under the hood, Polymarket V2 consists of four major components:
┌─────────────────────┐
│ Trader │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ CLOB API V2 │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Matching Engine │
│ Off-Chain │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Exchange Contract │
│ Polygon │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Atomic Settlement │
└─────────────────────┘
This architecture separates trading performance from blockchain settlement.
The result is a trading experience that feels similar to a centralized exchange while maintaining non-custodial execution.
One of the biggest misconceptions among developers is:
"Submitting an order means sending a transaction."
In Polymarket V2, this is not how trading works.
When you create an order:
const order = await client.createOrder({
tokenID,
side: "BUY",
price: 0.63,
size: 100
});
you are not creating a blockchain transaction.
Instead, you're generating a signed message.
The signed message contains information such as:
{
"tokenID": "...",
"side": "BUY",
"price": "0.63",
"size": "100",
"timestamp": 1748530000
}
The order is cryptographically signed using EIP-712 typed data.
This signature proves:
At this stage:
✅ Signed locally
✅ Verifiable
❌ Not on-chain
❌ No gas cost
❌ No blockchain transaction
This distinction is extremely important because it explains why placing orders is fast and inexpensive.
Before trading, developers must authenticate with the API.
Polymarket V2 uses a two-layer authentication system.
The wallet itself acts as the root identity.
A wallet signs messages to prove ownership.
Wallet
│
▼
EIP-712 Signature
This layer is responsible for:
After wallet verification, developers generate API credentials.
apiKey
secret
passphrase
These credentials are used for:
This design avoids requiring a wallet signature for every API request while maintaining strong security guarantees.
Once authenticated, the workflow looks straightforward.
const order = await client.createOrder({
tokenID,
side: "BUY",
price: 0.65,
size: 100
});
await client.postOrder(order);
After posting, the order enters the off-chain order book.
At this moment, the order becomes visible to other traders.
Example:
BIDS
0.65 → 100
0.64 → 250
0.63 → 500
The order now exists inside the matching engine.
Importantly, Polygon still has no knowledge of this order.
Nothing has been settled yet.
The matching engine is the heart of Polymarket.
Its job is to continuously compare:
BUY ORDERS
vs
SELL ORDERS
When compatible orders exist, a trade can be executed.
Consider the following example.
SELL YES
Price: 0.65
Size: 100
BUY YES
Price: 0.65
Size: 100
The prices match exactly.
The engine immediately creates a trade.
Trade:
100 shares @ 0.65
The matching process happens entirely off-chain.
This is one of the biggest reasons Polymarket can support high-frequency trading activity without blockchain congestion.
If matching occurred directly on Polygon:
The off-chain matching engine solves these problems.
Polymarket V2 follows standard exchange matching rules.
Example:
Bid A = 0.64
Bid B = 0.65
Bid B receives priority.
Example:
09:00 BUY @ 0.65
09:01 BUY @ 0.65
The 09:00 order executes first.
This is known as price-time priority.
It ensures fair execution across the marketplace.
Not every order is filled completely.
Imagine:
BUY 500 YES @ 0.65
Available liquidity:
SELL 100 @ 0.65
SELL 150 @ 0.65
Only:
250 shares
can execute immediately.
Result:
Filled: 250
Remaining: 250
The remaining quantity stays on the order book.
Developers building trading bots should always account for partial fills.
Assuming an order is either completely filled or completely unfilled is a common mistake.
This is where blockchain finally enters the process.
After matching occurs:
Order A
│
Order B
│
▼
Match Created
The matched trade is sent for settlement.
Match
│
▼
Exchange Contract V2
│
▼
Polygon
Settlement verifies:
If all checks pass, ownership changes atomically.
Atomic settlement means:
Everything succeeds
OR
Nothing succeeds
There is no intermediate state.
Example:
Alice buys YES.
Bob sells YES.
Settlement either:
Alice receives YES
Bob receives pUSD
or:
Trade fails
No balances change
This protects both participants.
One major change in V2 is the adoption of pUSD.
In previous versions, collateral management was different.
Now settlement generally occurs between:
pUSD
↔
Outcome Tokens
This simplifies trading infrastructure and standardizes settlement mechanics.
For developers building portfolio systems, this means collateral tracking logic should be updated to reflect the V2 architecture.
This question appears frequently.
Why not simply perform matching directly on Polygon?
The answer is performance.
Imagine a market maker updating quotes every second.
BUY @ 0.64
SELL @ 0.66
Then:
BUY @ 0.65
SELL @ 0.67
Then:
BUY @ 0.66
SELL @ 0.68
If every update required a blockchain transaction:
Modern exchanges require extremely fast order management.
The hybrid architecture allows:
Matching = Off-Chain
Settlement = On-Chain
This provides the best balance between speed and security.
Most developers interact with Polymarket through automated systems.
Typical bot architecture:
Market Data Feed
│
▼
Strategy Engine
│
▼
Risk Checks
│
▼
Order Creation
│
▼
CLOB API
Common bot types include:
Continuously quote:
BUY 0.64
SELL 0.66
and earn spread.
Compare prices across:
Use probability models to identify mispriced contracts.
Offset exposure across multiple correlated markets.
Understanding the execution pipeline is critical because latency, partial fills, and settlement timing directly affect profitability.
Orders are signed messages.
Settlement is the transaction.
Large orders frequently execute across multiple counterparties.
Always track remaining quantity.
V2 introduced:
Use V2 tooling only.
Matching may occur instantly.
Settlement still requires successful on-chain execution.
Your system should handle asynchronous updates.
No.
Open orders remain inside the off-chain CLOB.
Only completed settlements reach Polygon.
No.
Order creation is off-chain.
Settlement involves blockchain execution, but users generally interact through the exchange infrastructure rather than manually submitting transactions.
No.
Orders are signed by users and validated through smart contracts.
Yes.
The off-chain matching architecture is specifically designed to support low-latency trading.
https://docs.polymarket.com/api-reference/introduction
https://docs.polymarket.com/api-reference/authentication
https://docs.polymarket.com/developers/CLOB/trades/trades
https://docs.polymarket.com/v2-migration
Polymarket V2 is fundamentally different from traditional decentralized exchanges.
Rather than forcing every action onto the blockchain, it separates the trading lifecycle into two distinct phases:
Phase 1:
Order Creation + Matching
(Off-Chain)
Phase 2:
Settlement
(On-Chain)
This architecture enables fast execution, deep liquidity, and a familiar trading experience while preserving the security guarantees of blockchain settlement.
For developers, understanding where an order lives at each stage—signed message, order book entry, matched trade, and settled position—is essential when building reliable trading systems on top of Polymarket.
Once you understand this lifecycle, the behavior of the entire platform becomes much easier to reason about, optimize, and automate.
🤝 Collaboration & Contact
If you’re interested in building trading bots, buy trading bots, collaborating, exploring strategy improvements, or discussing about this system, feel free to reach out.
I’m especially open to connecting with:
Quant traders
Engineers building trading infrastructure
Researchers in prediction markets
Investors interested in market inefficiencies
This repo has some Polymarket several bots in this system.
You can explore the full implementation, strategy logic, and ongoing updates about 5 min crypto market here:
💬 Get in Touch
If you have ideas, questions, or would like to collaborate or want these trading bots, don’t hesitate to reach out directly.
Feedback on your repo (based on your description & strategy)
Contact Info
Telegram
Tags: #polymarket #polymarket-trading-bot #trading #bot #Crypto #TradingBots #AlgorithmicTrading #PredictionMarkets #Web3 #DeFi #Blockchain #QuantitativeTrading #Fintech #python #OpenSource #CryptoTrading