polyte-clob
Rust client library for Polymarket CLOB (Central Limit Order Book) API.
The CLOB API enables trading operations on Polymarket, including order creation, signing, posting, and account management.
More information about this crate can be found in the crate documentation.
Features
- EIP-712 Order Signing: Ethereum-standard order signing for security
- Complete Trading Flow: Create, sign, and post orders with a single method
- Account Management: Check balances, allowances, and trade history
- Order Management: List and cancel orders
- Market Data: Get order books, prices, and market information
Installation
[]
= "0.1.0"
= { = "1", = ["full"] }
Or use the unified client:
[]
= "0.1.0"
Usage
Setup
use ;
async
Place an Order
use ;
let params = CreateOrderParams ;
// Single method to create, sign, and post order
let response = clob.place_order.await?;
if response.success else
Advanced: Manual Order Flow
// 1. Create unsigned order
let order = clob.create_order.await?;
// 2. Sign the order with EIP-712
let signed_order = clob.sign_order.await?;
// 3. Post to the order book
let response = clob.post_order.await?;
Check Balance and Allowance
let balance = clob.account
.balance_allowance
.send
.await?;
println!;
println!;
List Your Orders
let orders = clob.orders.list.send.await?;
for order in orders
Cancel an Order
let response = clob.orders
.cancel
.send
.await?;
if response.success
Get Order Book
let order_book = clob.markets
.order_book
.send
.await?;
println!;
println!;
Get Market Price
use OrderSide;
let price = clob.markets
.price
.send
.await?;
println!;
Configuration
let clob = builder?
.base_url
.timeout_ms
.pool_size
.chain // or Chain::PolygonAmoy for testnet
.build?;
Supported Chains
- Polygon Mainnet (chain ID: 137) - Production
- Polygon Amoy (chain ID: 80002) - Testnet
Authentication
The CLOB API requires two types of authentication:
- Private Key: For signing orders with EIP-712 (on-chain security)
- API Credentials: For authenticating API requests (off-chain)
- API Key
- API Secret
- Passphrase
Obtaining API Credentials
Visit the Polymarket API documentation for instructions on obtaining API credentials.
Security Notes
- Never commit private keys or API credentials to version control
- Store credentials securely (environment variables, secrets manager)
- Use testnet (Polygon Amoy) for development and testing
- Validate all order parameters before signing
Examples
The crate includes examples:
# Check balance and allowance
# Retrieve market data
API Coverage
- Orders: Create, sign, post, list, cancel
- Markets: Get market info, order book, prices, midpoint
- Account: Balance, allowance, trade history
License
This project is licensed under the MIT License.