rs-clob-client
🦀 Rust client for Polymarket's CLOB (Central Limit Order Book) API with full EIP-712 signing support.
This library provides a complete Rust port of the TypeScript @polymarket/clob-client, enabling you to interact with Polymarket's trading infrastructure for creating orders, managing API keys, fetching market data, and more.
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= "0.8"
= "0.5"
= { = "1.0", = ["full"] }
API Documentation
- Public API - Market data, orderbook, prices (No auth required)
- Auth API - API key management, balance, notifications
- Trading API - Order creation, submission, cancellation
Quick Start
Basic Setup and Placing an Order
use ;
use PrivateKeySigner;
async
Market Data Access
use ClobClient;
async
Managing Orders
// Cancel a specific order
let order_id = "your_order_id";
client.cancel_order.await?;
// Cancel all orders for a market
let token_id = "your_token_id";
client.cancel_market_orders.await?;
// Cancel all orders
client.cancel_all.await?;
// Get your open orders
let open_orders = client.get_orders.await?;
println!;
Advanced Usage
Market Orders
use ;
// Execute a market buy
let market_order = UserMarketOrder ;
let result = client.post_order.await?;
println!;
Builder API Integration
use BuilderConfig;
// Create builder configuration
let builder_config = new;
// Create client with builder support
let client = new;
// Now you can use builder-specific endpoints
let builder_trades = client.get_builder_trades.await?;
Security Considerations
- 🔒 Private Keys: Never hardcode private keys. Use environment variables or secure key management solutions
- 🔐 EIP-712: All orders are signed using EIP-712 standard to prevent replay and phishing attacks
- ✅ API Credentials: Store API keys securely. Use L2 authentication for production deployments
- 🛡️ Domain Separation: Orders are bound to specific chain IDs and contract addresses
- 🔑 Key Derivation: Use
create_or_derive_api_key()instead of creating new keys repeatedly - ⚠️ Rate Limiting: Respect API rate limits to avoid being blocked
Configuration
Chain IDs
- Polygon Mainnet:
Chain::Polygon(137) - Amoy Testnet:
Chain::Amoy(80002)
Signature Types
- 0 (EOA): Standard wallet signatures (MetaMask, Coinbase Wallet, etc.)
- 1 (Poly Proxy): Polymarket proxy contract (for email/Magic login users)
- 2 (EIP-1271): Smart contract wallets (Gnosis Safe, etc.)
Order Types
- GTC (Good-Til-Cancelled): Order stays open until filled or cancelled
- FOK (Fill-Or-Kill): Order must be filled immediately or cancelled
- GTD (Good-Til-Date): Order expires at a specific time
Testing
# Run all tests
# Run tests with output
# Run specific test with output
# Build the library
Examples
See the TypeScript examples in the original repository for reference. Rust equivalents can be created following the patterns shown above.
Notice
⚠️ AI-Generated Code: This library was generated with AI assistance as a port from the official TypeScript implementation. While it aims for feature parity and has been structured following Rust best practices, users should:
- Review the code thoroughly before using in production
- Conduct their own security audits
- Test extensively with their specific use cases
- Start with testnet (Amoy) before moving to mainnet
- Use at their own risk
Contributing
Contributions are welcome! This is a community-maintained port of the official TypeScript client.
License
MIT
Acknowledgments
- Original TypeScript implementation: Polymarket clob-client