This guide covers how to create and post orders on the Polymarket CLOB, including limit orders, market orders, and batch orders.
Order Types
The CLOB supports four order types:
GTC (Good-Til-Canceled) : Order stays active until filled or manually canceled
GTD (Good-Til-Date) : Order expires at a specified timestamp
FOK (Fill-Or-Kill) : Order must fill completely immediately or be canceled
FAK (Fill-And-Kill) : Order fills as much as possible immediately, unfilled portion is canceled
Creating a Basic Limit Order
Limit orders let you specify an exact price at which you want to buy or sell.
import { ClobClient , Side , OrderType } from "@polymarket/clob-client" ;
import { ethers } from "ethers" ;
const wallet = new ethers . Wallet ( "your-private-key" );
const host = "https://clob.polymarket.com" ;
const chainId = 137 ; // Polygon mainnet
// Initialize client with API credentials
const clobClient = new ClobClient (
host ,
chainId ,
wallet ,
{
key: "your-api-key" ,
secret: "your-secret" ,
passphrase: "your-passphrase"
}
);
// Create a BUY order
const order = await clobClient . createOrder ({
tokenID: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
price: 0.52 , // Price per share (0.52 = 52 cents)
size: 100 , // Number of shares
side: Side . BUY , // Side.BUY or Side.SELL
});
// Post the order to the exchange
const response = await clobClient . postOrder ( order , OrderType . GTC );
console . log ( "Order posted:" , response );
Order Parameters
The token ID of the outcome you want to trade. Get this from the Markets API .
Price per share between 0.0001 and 0.9999. Must align with the market’s tick size.
Number of shares to buy or sell.
Either Side.BUY or Side.SELL.
Fee rate in basis points. If not provided, the market’s fee rate is used automatically.
Nonce for on-chain cancellations. Auto-generated if not provided.
Unix timestamp when the order expires. Required for GTD orders.
Address of specific taker. Use zero address for public orders (default).
Create and Post in One Step
Use createAndPostOrder() to combine order creation and posting:
const response = await clobClient . createAndPostOrder (
{
tokenID: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
price: 0.52 ,
side: Side . BUY ,
size: 100 ,
},
{ tickSize: "0.01" , negRisk: false }, // Options
OrderType . GTC , // Order type
false , // deferExec
false // postOnly
);
Post-Only Orders
Post-only orders ensure your order adds liquidity to the book rather than taking existing liquidity. They’re rejected if they would match immediately.
const order = await clobClient . createOrder ({
tokenID: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
price: 0.50 ,
side: Side . BUY ,
size: 100 ,
});
// Post-only is only supported for GTC/GTD orders
const response = await clobClient . postOrder (
order ,
OrderType . GTC ,
false , // deferExec
true // postOnly - order will be rejected if it would match immediately
);
Market Orders
Market orders execute immediately at the best available price.
Market Buy Order
// Create a market buy order for $100 worth of shares
const marketBuyOrder = await clobClient . createMarketOrder ({
tokenID: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
amount: 100 , // Dollar amount to spend
side: Side . BUY ,
orderType: OrderType . FOK , // FOK or FAK
});
// Post the order
const response = await clobClient . postOrder ( marketBuyOrder , OrderType . FOK );
Market Sell Order
// Create a market sell order for 100 shares
const marketSellOrder = await clobClient . createMarketOrder ({
tokenID: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
amount: 100 , // Number of shares to sell
side: Side . SELL ,
orderType: OrderType . FOK ,
});
const response = await clobClient . postOrder ( marketSellOrder , OrderType . FOK );
Create and Post Market Order
const response = await clobClient . createAndPostMarketOrder (
{
tokenID: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
amount: 100 ,
side: Side . BUY ,
orderType: OrderType . FOK ,
},
{ tickSize: "0.01" },
OrderType . FOK
);
For BUY orders, amount is the dollar amount to spend. For SELL orders, amount is the number of shares to sell.
Batch Orders
Post multiple orders in a single request for better performance:
import { PostOrdersArgs } from "@polymarket/clob-client" ;
// Create multiple orders
const orders : PostOrdersArgs [] = [
{
order: await clobClient . createOrder ({
tokenID: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
price: 0.40 ,
side: Side . BUY ,
size: 100 ,
}),
orderType: OrderType . GTC ,
postOnly: false ,
},
{
order: await clobClient . createOrder ({
tokenID: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
price: 0.45 ,
side: Side . BUY ,
size: 100 ,
}),
orderType: OrderType . GTC ,
postOnly: false ,
},
{
order: await clobClient . createOrder ({
tokenID: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
price: 0.55 ,
side: Side . SELL ,
size: 100 ,
}),
orderType: OrderType . GTC ,
postOnly: true ,
},
];
// Post all orders in one request
const response = await clobClient . postOrders (
orders ,
false , // deferExec
false // defaultPostOnly
);
GTD Orders with Expiration
Good-Til-Date orders expire at a specific timestamp:
const oneDayFromNow = Math . floor ( Date . now () / 1000 ) + 86400 ;
const order = await clobClient . createOrder ({
tokenID: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
price: 0.52 ,
side: Side . BUY ,
size: 100 ,
expiration: oneDayFromNow , // Unix timestamp
});
const response = await clobClient . postOrder ( order , OrderType . GTD );
Order Options
Tick Size
Each market has a minimum tick size that determines price precision. The client fetches this automatically, but you can override it:
const order = await clobClient . createOrder (
{
tokenID: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
price: 0.520 , // Price must be multiple of tick size
side: Side . BUY ,
size: 100 ,
},
{ tickSize: "0.01" } // Valid values: "0.1", "0.01", "0.001", "0.0001"
);
Negative Risk
Some markets use negative risk tokens. Specify this in order options:
const order = await clobClient . createOrder (
{
tokenID: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
price: 0.52 ,
side: Side . BUY ,
size: 100 ,
},
{ negRisk: true }
);
Getting Order Details
Retrieve order information after posting:
// Get a specific order by ID
const order = await clobClient . getOrder ( "0x123..." );
// Get all open orders
const openOrders = await clobClient . getOpenOrders ();
// Filter by market or token
const marketOrders = await clobClient . getOpenOrders ({
market: "0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1" ,
});
const tokenOrders = await clobClient . getOpenOrders ({
asset_id: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
});
Canceling Orders
Cancel a Single Order
await clobClient . cancelOrder ({ orderID: "0x123..." });
Cancel Multiple Orders
const orderHashes = [ "0x123..." , "0x456..." , "0x789..." ];
await clobClient . cancelOrders ( orderHashes );
Cancel All Orders
await clobClient . cancelAll ();
Cancel Orders by Market
await clobClient . cancelMarketOrders ({
market: "0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1" ,
});
// Or by token ID
await clobClient . cancelMarketOrders ({
asset_id: "71321045679252212594626385532706912750332728571942532289631379312455583992563" ,
});
Troubleshooting
Ensure your price is a multiple of the market’s tick size. The error message shows the minimum and maximum valid prices: Error: invalid price (0.523), min: 0.01 - max: 0.99
For a tick size of 0.01, valid prices are 0.01, 0.02, 0.03, etc.
Order rejected immediately
Check your balance and allowance: const balance = await clobClient . getBalanceAllowance ({
asset_type: AssetType . COLLATERAL ,
});
console . log ( "Balance:" , balance . balance );
console . log ( "Allowance:" , balance . allowance );
Ensure you’ve initialized the client with valid API credentials. See Managing API Keys for details.
The tick size you specified is smaller than the market’s minimum: Error: invalid tick size (0.001), minimum for the market is 0.01
Either omit the tick size to use the market’s default, or specify a larger value.
Next Steps