ClobClient

Struct ClobClient 

Source
pub struct ClobClient { /* private fields */ }
Expand description

Main client for interacting with Polymarket API

Implementations§

Source§

impl ClobClient

Source

pub fn new(host: &str) -> Self

Create a new client with optimized HTTP settings

Source

pub fn new_colocated(host: &str) -> Self

Create a client optimized for co-located environments

Source

pub fn new_internet(host: &str) -> Self

Create a client optimized for internet connections

Source

pub fn with_l1_headers(host: &str, private_key: &str, chain_id: u64) -> Self

Create a client with L1 headers (for authentication)

Source

pub fn with_l2_headers( host: &str, private_key: &str, chain_id: u64, api_creds: ApiCreds, ) -> Self

Create a client with L2 headers (for API key authentication)

Source

pub fn set_api_creds(&mut self, api_creds: ApiCreds)

Set API credentials

Source

pub async fn prewarm_connections(&self) -> Result<()>

Pre-warm connections to reduce first-request latency

Source

pub fn get_address(&self) -> Option<String>

Get the wallet address

Source

pub fn get_collateral_address(&self) -> Option<String>

Get the collateral token address for the current chain

Source

pub fn get_conditional_address(&self) -> Option<String>

Get the conditional tokens contract address for the current chain

Source

pub fn get_exchange_address(&self) -> Option<String>

Get the exchange contract address for the current chain

Source

pub async fn get_ok(&self) -> bool

Test basic connectivity

Source

pub async fn get_server_time(&self) -> Result<u64>

Get server time

Source

pub async fn get_order_book(&self, token_id: &str) -> Result<OrderBookSummary>

Get order book for a token

Source

pub async fn get_midpoint(&self, token_id: &str) -> Result<MidpointResponse>

Get midpoint for a token

Source

pub async fn get_spread(&self, token_id: &str) -> Result<SpreadResponse>

Get spread for a token

Source

pub async fn get_spreads( &self, token_ids: &[String], ) -> Result<HashMap<String, Decimal>>

Get spreads for multiple tokens (batch)

Source

pub async fn get_price( &self, token_id: &str, side: Side, ) -> Result<PriceResponse>

Get price for a token and side

Source

pub async fn get_tick_size(&self, token_id: &str) -> Result<Decimal>

Get tick size for a token

Source

pub async fn create_api_key(&self, nonce: Option<U256>) -> Result<ApiCreds>

Create a new API key

Source

pub async fn derive_api_key(&self, nonce: Option<U256>) -> Result<ApiCreds>

Derive an existing API key

Source

pub async fn create_or_derive_api_key( &self, nonce: Option<U256>, ) -> Result<ApiCreds>

Create or derive API key (try create first, fallback to derive)

Source

pub async fn get_api_keys(&self) -> Result<Vec<String>>

Get all API keys for the authenticated user

Source

pub async fn delete_api_key(&self) -> Result<String>

Delete the current API key

Source

pub async fn get_neg_risk(&self, token_id: &str) -> Result<bool>

Get neg risk for a token

Source

pub async fn create_order( &self, order_args: &OrderArgs, expiration: Option<u64>, extras: Option<ExtraOrderArgs>, options: Option<&OrderOptions>, ) -> Result<SignedOrderRequest>

Create an order

Source

pub async fn create_market_order( &self, order_args: &MarketOrderArgs, extras: Option<ExtraOrderArgs>, options: Option<&OrderOptions>, ) -> Result<SignedOrderRequest>

Create a market order

Source

pub async fn post_order( &self, order: SignedOrderRequest, order_type: OrderType, ) -> Result<Value>

Post an order to the exchange

Source

pub async fn create_and_post_order( &self, order_args: &OrderArgs, ) -> Result<Value>

Create and post an order in one call

Source

pub async fn cancel(&self, order_id: &str) -> Result<Value>

Cancel an order

Source

pub async fn cancel_orders(&self, order_ids: &[String]) -> Result<Value>

Cancel multiple orders

Source

pub async fn cancel_all(&self) -> Result<Value>

Cancel all orders

Source

pub async fn get_orders( &self, params: Option<&OpenOrderParams>, next_cursor: Option<&str>, ) -> Result<Vec<OpenOrder>>

Get open orders with optional filtering

This retrieves all open orders for the authenticated user. You can filter by:

  • Order ID (exact match)
  • Asset/Token ID (all orders for a specific token)
  • Market ID (all orders for a specific market)

The response includes order status, fill information, and timestamps.

Source

pub async fn get_trades( &self, trade_params: Option<&TradeParams>, next_cursor: Option<&str>, ) -> Result<Vec<Value>>

Get trade history with optional filtering

This retrieves historical trades for the authenticated user. You can filter by:

  • Trade ID (exact match)
  • Maker address (trades where you were the maker)
  • Market ID (trades in a specific market)
  • Asset/Token ID (trades for a specific token)
  • Time range (before/after timestamps)

Trades are returned in reverse chronological order (newest first).

Source

pub async fn get_balance_allowance( &self, params: Option<BalanceAllowanceParams>, ) -> Result<Value>

Get balance and allowance information for all assets

This returns the current balance and allowance for each asset in your account. Balance is how much you own, allowance is how much the exchange can spend on your behalf.

You need both balance and allowance to place orders - the exchange needs permission to move your tokens when orders are filled.

Source

pub async fn get_notifications(&self) -> Result<Value>

Set up notifications for order fills and other events

This configures push notifications so you get alerted when:

  • Your orders get filled
  • Your orders get cancelled
  • Market conditions change significantly

The signature proves you own the account and want to receive notifications.

Source

pub async fn get_midpoints( &self, token_ids: &[String], ) -> Result<HashMap<String, Decimal>>

Get midpoints for multiple tokens in a single request

This is much more efficient than calling get_midpoint() multiple times. Instead of N round trips, you make just 1 request and get all the midpoints back.

Midpoints are returned as a HashMap where the key is the token_id and the value is the midpoint price (or None if there’s no valid midpoint).

Source

pub async fn get_prices( &self, book_params: &[BookParams], ) -> Result<HashMap<String, HashMap<Side, Decimal>>>

Get bid/ask/mid prices for multiple tokens in a single request

This gives you the full price picture for multiple tokens at once. Much more efficient than individual calls, especially when you’re tracking a portfolio or comparing multiple markets.

Returns bid (best buy price), ask (best sell price), and mid (average) for each token.

Source

pub async fn get_order_books( &self, token_ids: &[String], ) -> Result<Vec<OrderBookSummary>>

Get order book for multiple tokens (batch) - reference implementation compatible

Source

pub async fn get_order(&self, order_id: &str) -> Result<OpenOrder>

Get single order by ID

Source

pub async fn get_last_trade_price(&self, token_id: &str) -> Result<Value>

Get last trade price for a token

Source

pub async fn get_last_trade_prices(&self, token_ids: &[String]) -> Result<Value>

Get last trade prices for multiple tokens

Source

pub async fn cancel_market_orders( &self, market: Option<&str>, asset_id: Option<&str>, ) -> Result<Value>

Cancel market orders with optional filters

Source

pub async fn drop_notifications(&self, ids: &[String]) -> Result<Value>

Drop (delete) notifications by IDs

Source

pub async fn update_balance_allowance( &self, params: Option<BalanceAllowanceParams>, ) -> Result<Value>

Update balance allowance

Source

pub async fn is_order_scoring(&self, order_id: &str) -> Result<bool>

Check if an order is scoring

Source

pub async fn are_orders_scoring( &self, order_ids: &[&str], ) -> Result<HashMap<String, bool>>

Check if multiple orders are scoring

Source

pub async fn get_sampling_markets( &self, next_cursor: Option<&str>, ) -> Result<MarketsResponse>

Get sampling markets with pagination

Source

pub async fn get_sampling_simplified_markets( &self, next_cursor: Option<&str>, ) -> Result<SimplifiedMarketsResponse>

Get sampling simplified markets with pagination

Source

pub async fn get_markets( &self, next_cursor: Option<&str>, ) -> Result<MarketsResponse>

Get markets with pagination

Source

pub async fn get_simplified_markets( &self, next_cursor: Option<&str>, ) -> Result<SimplifiedMarketsResponse>

Get simplified markets with pagination

Source

pub async fn get_market(&self, condition_id: &str) -> Result<Market>

Get single market by condition ID

Source

pub async fn get_market_trades_events( &self, condition_id: &str, ) -> Result<Value>

Get market trades events

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,