polynode
Rust SDK for the PolyNode real-time Polymarket API.
Stream settlements, trades, positions, deposits, oracle events, orderbook updates, and more through a single WebSocket connection. All events enriched with full market metadata.
New in v0.4: Local Cache — SQLite-backed local storage. Backfill wallet history in seconds, query trades and positions instantly with zero API calls.
Install
[]
= "0.4"
= { = "1", = ["rt", "macros"] }
# For local cache (optional):
# polynode = { version = "0.4", features = ["cache"] }
Quick Start
use PolyNodeClient;
async
REST API
// System
client.healthz.await?;
client.status.await?;
client.create_key.await?;
// Markets
client.markets.await?;
client.market.await?;
client.market_by_slug.await?;
client.market_by_condition.await?;
client.list_markets.await?;
client.search.await?;
// Pricing
client.candles.await?;
client.stats.await?;
// Settlements
client.recent_settlements.await?;
client.token_settlements.await?;
client.wallet_settlements.await?;
// Wallets
client.wallet.await?;
// RPC (rpc.polynode.dev)
client.rpc_call.await?;
WebSocket Streaming
use ;
use WsMessage;
let mut stream = client.stream.await?;
stream.subscribe.await?;
while let Some = stream.next.await
Subscription Types
Settlements // pending + confirmed settlements
Trades // all trade activity
Prices // price-moving events
Blocks // new Polygon blocks
Wallets // all wallet activity
Markets // all market activity
LargeTrades // $1K+ trades
Oracle // UMA resolution events
Chainlink // real-time price feeds
Subscription Filters
new
.wallets
.tokens
.slugs
.condition_ids
.side
.status
.min_size
.max_size
.event_types
.snapshot_count
.feeds
Orderbook Streaming
use ;
let mut stream = client.orderbook_stream.await?;
stream.subscribe.await?;
let mut book = new;
while let Some = stream.next.await
// Query local state
let best_bid = book.best_bid;
let best_ask = book.best_ask;
let spread = book.spread;
OrderbookEngine
Higher-level orderbook client. One connection, shared state, filtered views for different parts of your app.
use ;
let engine = connect.await?;
// Subscribe with token IDs, slugs, or condition IDs
engine.subscribe.await?;
// Query computed values from local state
engine.midpoint.await; // Some(0.465)
engine.spread.await; // Some(0.01)
engine.best_bid.await; // Some(OrderbookLevel { price: "0.46", size: "226.29" })
engine.book.await; // Some((bids, asks))
// Create filtered views for different components
let mut view = engine.view;
view.midpoint.await; // reads from shared state
// Receive only this view's updates
while let Some = view.next.await
engine.close.await?;
Zlib compression is enabled by default (~50% bandwidth savings). All connections auto-reconnect with exponential backoff.
Local Cache
Store trades and positions in a local SQLite database. Backfills recent history on startup, streams live updates, and serves all queries locally with zero API calls.
Enable the cache feature in your Cargo.toml:
= { = "0.4", = ["cache"] }
use ;
use Arc;
let client = new;
let mut cache = builder
.db_path
.watchlist_path
.on_backfill_progress
.build?;
cache.start.await?;
// Query locally — instant, no API calls
let trades = cache.wallet_trades?;
let positions = cache.wallet_positions?;
let stats = cache.stats?;
// Add wallets at runtime
use EntityType;
cache.add_to_watchlist?;
cache.stop.await?;
Watchlist (polynode.watch.json):
Backfill timing: 1 request per wallet at 1 req/s. 10 wallets = 10 seconds. See full documentation.
Configuration
let client = builder
.base_url
.ws_url
.ob_url
.rpc_url
.timeout
.build?;
Error Handling
use Error;
match client.market.await
Links
License
MIT