Polymarket Rust CLOB Client
[!WARNING] This repository has been archived and is no longer maintained.
The client is no longer functional and should not be used for new or existing integrations.
Please migrate to the V2 client: https://github.com/Polymarket/rs-clob-client-v2
An ergonomic Rust client for interacting with Polymarket services, primarily the Central Limit Order Book (CLOB).
This crate provides strongly typed request builders, authenticated endpoints, alloy support and more.
alloy::signers::Signerserde supportreqwestAdd the crate to your Cargo.toml:
[dependencies]
polymarket-client-sdk = "0.3"or
cargo add polymarket-client-sdkThen run any of the examples
cargo run --example unauthenticatedThe crate is modular with optional features for different Polymarket APIs:
| Feature | Description |
|---|---|
clob |
Core CLOB client for order placement, market data, and authentication |
tracing |
Structured logging via tracing for HTTP requests, auth flows, and caching |
ws |
WebSocket client for real-time orderbook, price, and user event streaming |
rtds |
Real-time data streams for crypto prices (Binance, Chainlink) and comments |
data |
Data API client for positions, trades, leaderboards, and analytics |
gamma |
Gamma API client for market/event discovery, search, and metadata |
bridge |
Bridge API client for cross-chain deposits (EVM, Solana, Bitcoin) |
rfq |
RFQ API (within CLOB) for submitting and querying quotes |
heartbeats |
Clob feature that automatically sends heartbeat messages to the Polymarket server, if the client disconnects all open orders will be cancelled |
ctf |
CTF API client to perform split/merge/redeem on binary and neg risk markets |
Enable features in your Cargo.toml:
[dependencies]
polymarket-client-sdk = { version = "0.3", features = ["ws", "data"] }This SDK re-exports commonly used types from external crates so you don't need to add them to your Cargo.toml:
types moduleuse polymarket_client_sdk::types::{
Address, ChainId, Signature, address, // from alloy::primitives
DateTime, NaiveDate, Utc, // from chrono
Decimal, dec, // from rust_decimal + rust_decimal_macros
};auth moduleuse polymarket_client_sdk::auth::{
LocalSigner, Signer, // from alloy::signers (LocalSigner + trait)
Uuid, ApiKey, // from uuid (ApiKey = Uuid)
SecretString, ExposeSecret, // from secrecy
builder::Url, // from url (for remote builder config)
};error moduleuse polymarket_client_sdk::error::{
StatusCode, Method, // from reqwest (for error inspection)
};This allows you to work with the SDK without managing version compatibility for these common dependencies.
See examples/ for the complete set. Below are hand-picked examples for common use cases.
use polymarket_client_sdk::clob::Client;
#[tokio::main]
async fn main() -> anyhow::Result {
let client = Client::default();
let ok = client.ok().await?;
println!("Ok: {ok}");
Ok(())
}Set POLYMARKET_PRIVATE_KEY as an environment variable with your private key.
If using MetaMask or hardware wallet, you must first set token allowances. See Token Allowances section below.
…For proxy/Safe wallets, the funder address is automatically derived using CREATE2 from your signer's EOA address:
let client = Client::new("https://clob.polymarket.com", Config::default())?
.authentication_builder(&signer)
.signature_type(SignatureType::GnosisSafe) // Funder auto-derived via CREATE2
.authenticate()
.await?;The SDK computes the deterministic wallet address that Polymarket deploys for your EOA. This is the same address shown on polymarket.com when you log in with a browser wallet.
If you need to override the derived address (e.g., for advanced use cases), you can explicitly provide it:
let client = Client::new("https://clob.polymarket.com", Config::default())?
.authentication_builder(&signer)
.funder(address!(""))
.signature_type(SignatureType::GnosisSafe)
.authenticate()
.await?;You can also derive these addresses manually:
use polymarket_client_sdk::{derive_safe_wallet, derive_proxy_wallet, POLYGON};
// For browser wallet users (GnosisSafe)
let safe_address = derive_safe_wallet(signer.address(), POLYGON);
// For Magic/email wallet users (Proxy)
let proxy_address = derive_proxy_wallet(signer.address(), POLYGON);The funder address is the actual address that holds your funds on Polymarket. When using proxy wallets (email wallets
like Magic or browser extension wallets), the signing key differs from the address holding the funds. The SDK automatically
derives the correct funder address using CREATE2 when you specify SignatureType::Proxy or SignatureType::GnosisSafe.
You can override this with .funder(address) if needed.
The signature_type parameter tells the system how to verify your signatures:
signature_type=0 (default): Standard EOA (Externally Owned Account) signatures - includes MetaMask, hardware wallets,
and any wallet where you control the private key directlysignature_type=1: Email/Magic wallet signatures (delegated signing)signature_type=2: Browser wallet proxy signatures (when using a proxy contract, not direct wallet connections)See SignatureType for more information.
……For institutional/third-party app integrations with remote signing:
…Real-time orderbook and user event streaming. Requires the ws feature.
polymarket-client-sdk = { version = "0.3", features = ["ws"] }…Available streams:
subscribe_orderbook() - Bid/ask levels for assetssubscribe_prices() - Price change eventssubscribe_midpoints() - Calculated midpoint pricessubscribe_orders() - User order updates (authenticated)subscribe_trades() - User trade executions (authenticated)See examples/clob/ws/ for more WebSocket examples including authenticated user streams.
Trading analytics, positions, and leaderboards. Requires the data feature.
use polymarket_client_sdk::data::Client;
use polymarket_client_sdk::data::types::request::PositionsRequest;
use polymarket_client_sdk::types::address;
#[tokio::main]
async fn main() -> anyhow::Result {
let client = Client::default();
let user = address!("0x0000000000000000000000000000000000000000"); // Your address
let request = PositionsRequest::builder().user(user).limit(10)?.build();
let positions = client.positions(&request).await?;
println!("Open positions: {:?}", positions);
Ok(())
}See examples/data.rs for trades, leaderboards, activity, and more.
Market and event discovery. Requires the gamma feature.
…See examples/gamma.rs for tags, series, comments, and sports endpoints.
Cross-chain deposits from EVM chains, Solana, and Bitcoin. Requires the bridge feature.
…See examples/bridge.rs for supported assets and minimum deposits.
Beyond basic order placement, the CLOB client supports:
stream_data() for iterating through large result setspost_orders() and cancel_orders() for multiple orders at onceSee examples/clob/authenticated.rs for comprehensive usage.
MetaMask and EOA users must set token allowances. If you are using a proxy or Safe-type wallet, then you do not.
Think of allowances as permissions. Before Polymarket can move your funds to execute trades, you need to give the exchange contracts permission to access your USDC and conditional tokens.
You need to approve two types of tokens:
Each needs approval for the exchange contracts to work properly.
Use examples/approvals.rs to approve the right contracts. Run once to approve USDC. Then change
the TOKEN_TO_APPROVE and run for each conditional token.
Pro tip: You only need to set these once per wallet. After that, you can trade freely.
MSRV: Rust 1.88
Older versions may compile, but are not supported.
This project aims to maintain compatibility with a Rust version that is at least six months old.
Version updates may occur more
No open issues yet, or sync has not completed.