pub struct ClobClient {
pub http_client: Client,
pub base_url: String,
/* private fields */
}Expand description
Main client for interacting with Polymarket API
Fields§
§http_client: Client§base_url: StringImplementations§
Source§impl ClobClient
impl ClobClient
Sourcepub fn new(host: &str) -> Self
pub fn new(host: &str) -> Self
Create a new client with optimized HTTP/2 settings (benchmarked 11.4% faster) Now includes DNS caching, connection management, and buffer pooling
Sourcepub fn new_colocated(host: &str) -> Self
pub fn new_colocated(host: &str) -> Self
Create a client optimized for co-located environments
Sourcepub fn new_internet(host: &str) -> Self
pub fn new_internet(host: &str) -> Self
Create a client optimized for internet connections
Sourcepub fn with_l1_headers(host: &str, private_key: &str, chain_id: u64) -> Self
pub fn with_l1_headers(host: &str, private_key: &str, chain_id: u64) -> Self
Create a client with L1 headers (for authentication)
Sourcepub fn with_l2_headers(
host: &str,
private_key: &str,
chain_id: u64,
api_creds: ApiCreds,
) -> Self
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)
Sourcepub fn set_api_creds(&mut self, api_creds: ApiCreds)
pub fn set_api_creds(&mut self, api_creds: ApiCreds)
Set API credentials
Sourcepub async fn start_keepalive(&self, interval: Duration)
pub async fn start_keepalive(&self, interval: Duration)
Start background keep-alive to maintain warm connection Sends periodic lightweight requests to prevent connection drops
Sourcepub async fn stop_keepalive(&self)
pub async fn stop_keepalive(&self)
Stop keep-alive background task
Sourcepub async fn prewarm_connections(&self) -> Result<()>
pub async fn prewarm_connections(&self) -> Result<()>
Pre-warm connections to reduce first-request latency
Sourcepub fn get_address(&self) -> Option<String>
pub fn get_address(&self) -> Option<String>
Get the wallet address
Sourcepub fn get_collateral_address(&self) -> Option<String>
pub fn get_collateral_address(&self) -> Option<String>
Get the collateral token address for the current chain
Sourcepub fn get_conditional_address(&self) -> Option<String>
pub fn get_conditional_address(&self) -> Option<String>
Get the conditional tokens contract address for the current chain
Sourcepub fn get_exchange_address(&self) -> Option<String>
pub fn get_exchange_address(&self) -> Option<String>
Get the exchange contract address for the current chain
Sourcepub async fn get_server_time(&self) -> Result<u64>
pub async fn get_server_time(&self) -> Result<u64>
Get server time
Sourcepub async fn get_order_book(&self, token_id: &str) -> Result<OrderBookSummary>
pub async fn get_order_book(&self, token_id: &str) -> Result<OrderBookSummary>
Get order book for a token
Sourcepub async fn get_midpoint(&self, token_id: &str) -> Result<MidpointResponse>
pub async fn get_midpoint(&self, token_id: &str) -> Result<MidpointResponse>
Get midpoint for a token
Sourcepub async fn get_spread(&self, token_id: &str) -> Result<SpreadResponse>
pub async fn get_spread(&self, token_id: &str) -> Result<SpreadResponse>
Get spread for a token
Sourcepub async fn get_spreads(
&self,
token_ids: &[String],
) -> Result<HashMap<String, Decimal>>
pub async fn get_spreads( &self, token_ids: &[String], ) -> Result<HashMap<String, Decimal>>
Get spreads for multiple tokens (batch)
Sourcepub async fn get_price(
&self,
token_id: &str,
side: Side,
) -> Result<PriceResponse>
pub async fn get_price( &self, token_id: &str, side: Side, ) -> Result<PriceResponse>
Get price for a token and side
Sourcepub async fn get_tick_size(&self, token_id: &str) -> Result<Decimal>
pub async fn get_tick_size(&self, token_id: &str) -> Result<Decimal>
Get tick size for a token
Sourcepub async fn create_api_key(&self, nonce: Option<U256>) -> Result<ApiCreds>
pub async fn create_api_key(&self, nonce: Option<U256>) -> Result<ApiCreds>
Create a new API key
Sourcepub async fn derive_api_key(&self, nonce: Option<U256>) -> Result<ApiCreds>
pub async fn derive_api_key(&self, nonce: Option<U256>) -> Result<ApiCreds>
Derive an existing API key
Sourcepub async fn create_or_derive_api_key(
&self,
nonce: Option<U256>,
) -> Result<ApiCreds>
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)
Sourcepub async fn get_api_keys(&self) -> Result<Vec<String>>
pub async fn get_api_keys(&self) -> Result<Vec<String>>
Get all API keys for the authenticated user
Sourcepub async fn delete_api_key(&self) -> Result<String>
pub async fn delete_api_key(&self) -> Result<String>
Delete the current API key
Sourcepub async fn get_neg_risk(&self, token_id: &str) -> Result<bool>
pub async fn get_neg_risk(&self, token_id: &str) -> Result<bool>
Get neg risk for a token
Sourcepub async fn create_order(
&self,
order_args: &OrderArgs,
expiration: Option<u64>,
extras: Option<ExtraOrderArgs>,
options: Option<&OrderOptions>,
) -> Result<SignedOrderRequest>
pub async fn create_order( &self, order_args: &OrderArgs, expiration: Option<u64>, extras: Option<ExtraOrderArgs>, options: Option<&OrderOptions>, ) -> Result<SignedOrderRequest>
Create an order
Sourcepub async fn create_market_order(
&self,
order_args: &MarketOrderArgs,
extras: Option<ExtraOrderArgs>,
options: Option<&OrderOptions>,
) -> Result<SignedOrderRequest>
pub async fn create_market_order( &self, order_args: &MarketOrderArgs, extras: Option<ExtraOrderArgs>, options: Option<&OrderOptions>, ) -> Result<SignedOrderRequest>
Create a market order
Sourcepub async fn post_order(
&self,
order: SignedOrderRequest,
order_type: OrderType,
) -> Result<Value>
pub async fn post_order( &self, order: SignedOrderRequest, order_type: OrderType, ) -> Result<Value>
Post an order to the exchange
Sourcepub async fn create_and_post_order(
&self,
order_args: &OrderArgs,
) -> Result<Value>
pub async fn create_and_post_order( &self, order_args: &OrderArgs, ) -> Result<Value>
Create and post an order in one call
Sourcepub async fn cancel_orders(&self, order_ids: &[String]) -> Result<Value>
pub async fn cancel_orders(&self, order_ids: &[String]) -> Result<Value>
Cancel multiple orders
Sourcepub async fn cancel_all(&self) -> Result<Value>
pub async fn cancel_all(&self) -> Result<Value>
Cancel all orders
Sourcepub async fn get_orders(
&self,
params: Option<&OpenOrderParams>,
next_cursor: Option<&str>,
) -> Result<Vec<OpenOrder>>
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.
Sourcepub async fn get_trades(
&self,
trade_params: Option<&TradeParams>,
next_cursor: Option<&str>,
) -> Result<Vec<Value>>
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).
Sourcepub async fn get_balance_allowance(
&self,
params: Option<BalanceAllowanceParams>,
) -> Result<Value>
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.
Sourcepub async fn get_notifications(&self) -> Result<Value>
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.
Sourcepub async fn get_midpoints(
&self,
token_ids: &[String],
) -> Result<HashMap<String, Decimal>>
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).
Sourcepub async fn get_prices(
&self,
book_params: &[BookParams],
) -> Result<HashMap<String, HashMap<Side, Decimal>>>
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.
Sourcepub async fn get_order_books(
&self,
token_ids: &[String],
) -> Result<Vec<OrderBookSummary>>
pub async fn get_order_books( &self, token_ids: &[String], ) -> Result<Vec<OrderBookSummary>>
Get order book for multiple tokens (batch) - reference implementation compatible
Sourcepub async fn get_last_trade_price(&self, token_id: &str) -> Result<Value>
pub async fn get_last_trade_price(&self, token_id: &str) -> Result<Value>
Get last trade price for a token
Sourcepub async fn get_last_trade_prices(&self, token_ids: &[String]) -> Result<Value>
pub async fn get_last_trade_prices(&self, token_ids: &[String]) -> Result<Value>
Get last trade prices for multiple tokens
Sourcepub async fn cancel_market_orders(
&self,
market: Option<&str>,
asset_id: Option<&str>,
) -> Result<Value>
pub async fn cancel_market_orders( &self, market: Option<&str>, asset_id: Option<&str>, ) -> Result<Value>
Cancel market orders with optional filters
Sourcepub async fn drop_notifications(&self, ids: &[String]) -> Result<Value>
pub async fn drop_notifications(&self, ids: &[String]) -> Result<Value>
Drop (delete) notifications by IDs
Sourcepub async fn update_balance_allowance(
&self,
params: Option<BalanceAllowanceParams>,
) -> Result<Value>
pub async fn update_balance_allowance( &self, params: Option<BalanceAllowanceParams>, ) -> Result<Value>
Update balance allowance
Sourcepub async fn is_order_scoring(&self, order_id: &str) -> Result<bool>
pub async fn is_order_scoring(&self, order_id: &str) -> Result<bool>
Check if an order is scoring
Sourcepub async fn are_orders_scoring(
&self,
order_ids: &[&str],
) -> Result<HashMap<String, bool>>
pub async fn are_orders_scoring( &self, order_ids: &[&str], ) -> Result<HashMap<String, bool>>
Check if multiple orders are scoring
Sourcepub async fn get_sampling_markets(
&self,
next_cursor: Option<&str>,
) -> Result<MarketsResponse>
pub async fn get_sampling_markets( &self, next_cursor: Option<&str>, ) -> Result<MarketsResponse>
Get sampling markets with pagination
Sourcepub async fn get_sampling_simplified_markets(
&self,
next_cursor: Option<&str>,
) -> Result<SimplifiedMarketsResponse>
pub async fn get_sampling_simplified_markets( &self, next_cursor: Option<&str>, ) -> Result<SimplifiedMarketsResponse>
Get sampling simplified markets with pagination
Sourcepub async fn get_markets(
&self,
next_cursor: Option<&str>,
) -> Result<MarketsResponse>
pub async fn get_markets( &self, next_cursor: Option<&str>, ) -> Result<MarketsResponse>
Get markets with pagination
Sourcepub async fn get_simplified_markets(
&self,
next_cursor: Option<&str>,
) -> Result<SimplifiedMarketsResponse>
pub async fn get_simplified_markets( &self, next_cursor: Option<&str>, ) -> Result<SimplifiedMarketsResponse>
Get simplified markets with pagination
Sourcepub async fn get_market(&self, condition_id: &str) -> Result<Market>
pub async fn get_market(&self, condition_id: &str) -> Result<Market>
Get single market by condition ID
Sourcepub async fn get_market_trades_events(
&self,
condition_id: &str,
) -> Result<Value>
pub async fn get_market_trades_events( &self, condition_id: &str, ) -> Result<Value>
Get market trades events
Auto Trait Implementations§
impl Freeze for ClobClient
impl !RefUnwindSafe for ClobClient
impl Send for ClobClient
impl Sync for ClobClient
impl Unpin for ClobClient
impl !UnwindSafe for ClobClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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