Skip to main content

Crate polymarket_client

Crate polymarket_client 

Source
Expand description

Unified Polymarket Rust SDK.

Modeled after the official TypeScript SDK (@polymarket/client).

§Clients

  • PublicClient — read-only discovery, market data, and (with account) portfolio reads
  • [SecureClient] — authenticated trading, notifications, rewards, CTF wallet ops, and user websockets

§Feature flags

FeatureEnables
(default)HTTP discovery + CLOB market data
accountData API reads on PublicClient
websocketsRealtime subscribe() on PublicClient
secureaccount + websockets + [SecureClient] trading and wallet ops

§Quickstart

use polymarket_client::{Environment, PublicClient};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = PublicClient::new(Environment::production());
    let mut paginator = client.list_markets(polymarket_client::ListMarketsRequest {
        closed: Some(false),
        page_size: Some(5),
        ..Default::default()
    })?;
    let page = paginator.first_page().await?;
    for market in &page.items {
        println!("{}: {}", market.id, market.question.as_deref().unwrap_or(""));
    }
    Ok(())
}

§Realtime (websockets)

use futures::StreamExt as _;
use polymarket_client::{Environment, MarketSubscription, PublicClient, SubscriptionSpec};

let client = PublicClient::new(Environment::production());
let mut handle = client.subscribe(vec![SubscriptionSpec::Market(MarketSubscription {
    token_ids: vec!["123".into()],
    custom_feature_enabled: false,
})])?;
if let Some(Ok(event)) = handle.next().await {
    println!("{event:?}");
}
handle.close();

Structs§

CtfConditionId
CTF condition identifier (bytes32 hex).
DecimalString
Environment
Production and preproduction environment configuration.
Event
Normalized Polymarket event.
EventId
EvmAddress
An EVM account or contract address.
FetchMidpointRequest
FetchOrderBookRequest
ListEventsRequest
ListMarketsRequest
Market
MarketId
OrderBook
OrderBookLevel
Page
PaginationCursor
Paginator
PublicClient
Read-only Polymarket client for discovery and market data.
PublicClientBuilder
Builder for PublicClient.
RateLimitError
RequestRejectedError
TokenId
TransportError
UnexpectedResponseError
UserInputError

Enums§

Error
Top-level SDK error.
FetchMarketError
FetchMarketRequest
FetchMidpointError
FetchOrderBookError
ListEventsError
ListMarketsError
OrderSide
OrderType

Functions§

unexpected_response
user_input