polymarket
Rust SDK for Polymarket prediction market.
Features
- CLOB API - Central Limit Order Book trading (orders, market data)
- Gamma API - Market discovery and event data
- RTDS - Real-Time Data Service for live price feeds
- WebSocket - Real-time market and user data streams
- On-chain - Direct blockchain interactions (ERC20, ERC1155, proxy contracts)
Installation
[dependencies]
polymarket = "0.1"
Quick Start
CLOB Client
use polymarket::clob::{ClobClient, ClobConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClobConfig::polygon_mainnet();
let client = ClobClient::new(config);
let book = client.get_order_book("token_id").await?;
println!("Best bid: {:?}", book.bids.first());
Ok(())
}
WebSocket Market Data
use polymarket::websocket::channels::MarketWebSocket;
use futures_util::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = MarketWebSocket::new("wss://ws-subscriptions-clob.polymarket.com");
client.add_tokens(vec!["token_id".to_string()]).await?;
let mut stream = client.connect().await?;
while let Some(msg) = stream.next().await {
println!("{:?}", msg?);
}
Ok(())
}
Gamma API
use polymarket::gamma::GammaClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = GammaClient::new();
let markets = client.get_markets().await?;
for market in markets {
println!("{}: {}", market.question, market.volume);
}
Ok(())
}
Modules
clob - CLOB API client and order building
gamma - Gamma markets API
data - Market data client
rtds - Real-Time Data Service
websocket - WebSocket streaming (market, user channels)
onchain - Blockchain interactions (wallet, tokens, contracts)
relayer - Order relayer client
License
MIT