Skip to main content
For real-time books, use WebSocketsfetch_orderbook is a one-shot snapshot.

fetch_orderbook

async fn fetch_orderbook(
    req: OrderbookRequest,
) -> Result<Orderbook, OpenPxError>
OrderbookRequest
FieldTypeDescription
market_idstringNative market ID
outcomestring?"Yes" or "No" (binary markets)
token_idstring?Polymarket CLOB token; takes precedence over outcome
Returns Orderbook { market_id, asset_id, bids, asks, last_update_id?, timestamp?, hash? } with bids sorted high-to-low and asks low-to-high. See Orderbook for the full shape.
use openpx::OrderbookRequest;

let book = ex.fetch_orderbook(OrderbookRequest {
    market_id: "KXBTC-25MAR14-T20000".into(),
    outcome: Some("Yes".into()),
    token_id: None,
}).await?;

if let (Some(bid), Some(ask)) = (book.best_bid(), book.best_ask()) {
    println!("spread: {}", ask - bid);
}

Helpers on Orderbook

The Rust type exposes a few zero-copy helpers (Python/TS receive them as plain dicts and have to compute equivalents):
MethodReturns
best_bid()Option<f64>
best_ask()Option<f64>
mid_price()Option<f64> — exact midpoint via FixedPrice
spread()Option<f64>
has_data()bool
sort()sorts bids descending, asks ascending