polymarket-us
Unofficial Rust SDK for the Polymarket US Retail API.
Features
- Resource-based API — Organized into focused clients (
client.markets(),client.orders(),client.events(), etc.) - Ed25519 request signing — Automatic X-PM-* authentication headers
- Typed async REST client — Markets, events, orders, portfolio, account, and search endpoints
- Async WebSocket streaming — Market data and order updates with automatic reconnect
- Order book & pricing data — Get order books, best bid/offer, settlement prices
- Builder-based configuration — Base URLs, timeouts, custom HTTP client
- Backward compatible — All legacy methods still work (deprecated)
Installation
This crate is currently easiest to consume from source or git:
[]
= { = "../polymarket-us" }
= { = "1", = ["macros", "rt-multi-thread"] }
Or via git:
[]
= { = "https://github.com/mbordash/DRADIS", = "polymarket-us" }
= { = "1", = ["macros", "rt-multi-thread"] }
Authentication
Authenticated endpoints require:
POLYMARKET_US_KEY_IDPOLYMARKET_US_SECRET_KEY
POLYMARKET_US_SECRET_KEY must be Base64 that decodes to either:
- 64 bytes (keypair format, first 32 bytes are used as signing seed), or
- 32 bytes (raw Ed25519 seed).
Example:
Quick start
use PolymarketUsClient;
async
Resource-Based API
The SDK is organized into focused resource clients for better discoverability and maintainability:
Markets
Market discovery, order books, and pricing data.
// List markets
let markets = client.markets.list.await?;
// List with filters
let query = ;
let page = client.markets.list_with_query.await?;
// Order book and pricing
let book = client.markets.order_book.await?;
let bbo = client.markets.bbo.await?; // Best bid/offer
let settlement = client.markets.settlement_price.await?;
Events
Event-level metadata and context.
// List all events
let events = client.events.list.await?;
// Get event by ID or slug
let event = client.events.retrieve.await?;
let event = client.events.retrieve_by_slug.await?;
Orders
Complete order lifecycle management. All operations are authenticated.
use types;
let order_req = PlaceOrderRequest ;
// Place order
let order = client.orders.create.await?;
// Get open orders
let open = client.orders.open.await?;
// Modify, cancel, preview
client.orders.modify.await?;
client.orders.cancel.await?;
let estimate = client.orders.preview.await?;
// Close position
client.orders.close_position.await?;
Account
Account balances and buying power (authenticated).
let balances = client.account.balances.await?;
for balance in balances.balances
Portfolio
Holdings and activity history (authenticated).
// Get positions
let positions = client.portfolio.positions.await?;
// Get activity with pagination
let query = ;
let activities = client.portfolio.activities.await?;
Search
Full-text search across markets and events.
let query = ;
let results = client.search.search.await?;
// Search specific resource
let markets = client.search.markets.await?;
let events = client.search.events.await?;
Advanced market queries
Use list_with_query() for filters, cursors, and pagination:
use PolymarketUsClient;
use Serialize;
async
If your account tier requires authenticated access for some filters, use list_authenticated_with_query():
Streaming market data
The SDK exposes an async WebSocket client via client.streaming(). It handles handshake signing, subscription frames, reconnects, and event parsing.
use ;
async
Endpoint coverage
Markets (client.markets()):
list()— List all marketslist_with_query(q)— List markets with filters/paginationlist_authenticated()— Authenticated market listinglist_authenticated_with_query(q)— Authenticated with filtersorder_book(symbol)— Get market order bookbbo(symbol)— Get best bid/offersettlement_price(symbol)— Get settlement price
Events (client.events()):
list()— List all eventslist_with_query(q)— List events with filtersretrieve(id)— Get event by IDretrieve_by_slug(slug)— Get event by slug
Orders (client.orders()):
create(req)— Create orderplace(req)— Place order (alternative endpoint)place_batch(req)— Place multiple orders atomicallyopen(q)— Get open ordersretrieve(id)— Get order by IDcancel(id, params)— Cancel ordercancel_trading(id)— Cancel via trading endpointcancel_all(params)— Cancel all ordersmodify(id, req)— Modify open orderpreview(req)— Preview order estimateclose_position(req)— Close position
Account (client.account()):
balances()— Get account balances and buying power
Portfolio (client.portfolio()):
positions()— Get positionsactivities(q)— Get activity with pagination
Search (client.search()):
search(q)— Full-text search across markets/eventsmarkets(q)— Search marketsevents(q)— Search events
Streaming (client.streaming()):
- Async WebSocket client with automatic reconnect and subscription management
Backward Compatibility
All legacy methods (e.g., client.markets_list(), client.order_create()) are still available but deprecated. They're aliases to the new resource-based API. Your existing code will continue to work—migrate at your own pace:
// Old style (deprecated, but still works)
let markets = client.markets_list.await?;
// New style (preferred)
let markets = client.markets.list.await?;
Configuration
use ;
use Duration;
Error handling
use ;
async
Testing
The SDK includes comprehensive unit tests for all resource clients and type serialization/deserialization:
# Run all tests
# Run with output
# Run specific test module
# Run a single test
Current test coverage includes:
- ✅ Resource client creation and type checking (6 resources × 2 tests = 12 tests)
- ✅ Request/Response serialization for all order types (8+ tests)
- ✅ Type deserialization for markets, events, positions, balances (4+ tests)
- ✅ Client resource accessor availability (2 tests)
- ✅ Plus existing auth, streaming, and client tests (6 tests)
Total: 36 tests, all passing
Acknowledgements
Initial implementation originated in the DRADIS project and was extracted into this crate.
- Project link:
https://github.com/mbordash/DRADIS - Attribution is kept for provenance and maintenance history.