polyoxide
Unified Rust client for Polymarket APIs, re-exporting the CLOB (trading), Gamma (market data), and Data (user positions/trades) crates behind feature flags.
More information about this crate can be found in the crate documentation.
Installation
By default, all three REST API modules are enabled:
cargo add polyoxide
Select only what you need:
# Market data only
cargo add polyoxide --no-default-features --features gamma
# Trading only
cargo add polyoxide --no-default-features --features clob
# User data only
cargo add polyoxide --no-default-features --features data
# Everything including WebSocket
cargo add polyoxide --no-default-features --features full
Feature flags
| Feature | Default | Description |
|---|---|---|
clob |
yes | CLOB order-book trading via polyoxide-clob |
gamma |
yes | Read-only market data via polyoxide-gamma |
data |
yes | Read-only user positions/trades via polyoxide-data |
ws |
no | WebSocket streaming (implies clob) |
full |
no | Enables clob + gamma + data + ws |
Usage
Unified client (all three features enabled)
When clob, gamma, and data are all enabled, the Polymarket struct provides a single entry point. It requires an Account for authenticated CLOB operations.
use *;
async
Using individual crates directly
Each sub-client can be used standalone without the unified Polymarket wrapper.
// Read-only Gamma client (no auth required)
use Gamma;
let gamma = builder.build?;
let events = gamma.events.list.limit.send.await?;
// Read-only Data API client (no auth required)
use DataApi;
let data = builder.build?;
let leaders = data.leaderboard.list.send.await?;
// Public (unauthenticated) CLOB client for read-only market data
use Clob;
let clob = public;
let book = clob.markets.order_book.send.await?;
WebSocket (requires ws feature)
use *;
use StreamExt;
async
For long-running connections, WebSocketBuilder provides automatic keep-alive pings:
use *;
use Duration;
let stream = new
.ping_interval
.connect_market
.await?;
stream.run.await?;
Environment variables
Authenticated operations (CLOB trading) require:
| Variable | Description |
|---|---|
POLYMARKET_PRIVATE_KEY |
Hex-encoded private key |
POLYMARKET_API_KEY |
L2 API key |
POLYMARKET_API_SECRET |
L2 API secret (base64) |
POLYMARKET_API_PASSPHRASE |
L2 API passphrase |
Account::from_env() reads all four. Alternatively, use Account::new(private_key, credentials) or Account::from_file(path) for file-based config.
License
Licensed under either of MIT or Apache-2.0 at your option.