pub struct PolymarketClient<A = Public> { /* private fields */ }Expand description
Main client for interacting with the Polymarket CLOB API.
The type parameter A tracks the authentication state at compile time:
PolymarketClient<Public>— can only call public endpointsPolymarketClient<Authenticated>— can call all endpoints including trading
Implementations§
Source§impl PolymarketClient<Public>
impl PolymarketClient<Public>
Sourcepub fn new_public(host: Option<&str>) -> Result<Self>
pub fn new_public(host: Option<&str>) -> Result<Self>
Create a public-only client (no authentication, market data only).
Pass None for the host to use the default mainnet URL.
Sourcepub fn authenticate(
self,
creds: ApiCredentials,
) -> PolymarketClient<Authenticated>
pub fn authenticate( self, creds: ApiCredentials, ) -> PolymarketClient<Authenticated>
Upgrade this client to an authenticated client by providing L2 credentials.
This is a zero-cost state transition — it just adds credentials.
Source§impl<A> PolymarketClient<A>
impl<A> PolymarketClient<A>
Sourcepub fn builder() -> PolymarketClientBuilder
pub fn builder() -> PolymarketClientBuilder
Builder-style: create a fully configured client.
Sourcepub fn has_credentials(&self) -> bool
pub fn has_credentials(&self) -> bool
Check if L2 credentials are configured.
Sourcepub fn set_funder(&mut self, funder: Address)
pub fn set_funder(&mut self, funder: Address)
Set the funder address (for proxy wallets).
Sourcepub fn set_signature_type(&mut self, sig_type: SignatureType)
pub fn set_signature_type(&mut self, sig_type: SignatureType)
Set the signature type.
Sourcepub async fn get_sampling_simplified_markets(
&self,
next_cursor: Option<&str>,
) -> Result<Vec<SimplifiedMarket>>
pub async fn get_sampling_simplified_markets( &self, next_cursor: Option<&str>, ) -> Result<Vec<SimplifiedMarket>>
Get simplified markets.
Sourcepub async fn get_simplified_markets(
&self,
next_cursor: Option<&str>,
) -> Result<Vec<SimplifiedMarket>>
pub async fn get_simplified_markets( &self, next_cursor: Option<&str>, ) -> Result<Vec<SimplifiedMarket>>
Get simplified markets (paginated).
Sourcepub async fn get_markets(
&self,
next_cursor: Option<&str>,
) -> Result<Vec<SimplifiedMarket>>
pub async fn get_markets( &self, next_cursor: Option<&str>, ) -> Result<Vec<SimplifiedMarket>>
Get markets from the CLOB API.
Sourcepub async fn get_market(&self, condition_id: &str) -> Result<SimplifiedMarket>
pub async fn get_market(&self, condition_id: &str) -> Result<SimplifiedMarket>
Get a single market by condition ID.
Sourcepub async fn get_order_book(&self, token_id: &str) -> Result<OrderBook>
pub async fn get_order_book(&self, token_id: &str) -> Result<OrderBook>
Get the order book for a token.
Sourcepub async fn get_midpoint(&self, token_id: &str) -> Result<PriceResponse>
pub async fn get_midpoint(&self, token_id: &str) -> Result<PriceResponse>
Get the midpoint price for a token.
Sourcepub async fn get_price(&self, token_id: &str) -> Result<PriceResponse>
pub async fn get_price(&self, token_id: &str) -> Result<PriceResponse>
Get the current price 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 the spread for a token.
Sourcepub async fn get_last_trade_price(
&self,
token_id: &str,
) -> Result<LastTradePriceResponse>
pub async fn get_last_trade_price( &self, token_id: &str, ) -> Result<LastTradePriceResponse>
Get the last trade price for a token.
Sourcepub async fn get_prices_history(
&self,
token_id: &str,
start_ts: Option<i64>,
end_ts: Option<i64>,
fidelity: Option<u32>,
) -> Result<Vec<PriceHistoryEntry>>
pub async fn get_prices_history( &self, token_id: &str, start_ts: Option<i64>, end_ts: Option<i64>, fidelity: Option<u32>, ) -> Result<Vec<PriceHistoryEntry>>
Get price history for a token.
Sourcepub async fn get_tick_size(&self, token_id: &str) -> Result<TickSizeInfo>
pub async fn get_tick_size(&self, token_id: &str) -> Result<TickSizeInfo>
Get tick size for a token.
Sourcepub async fn get_gamma_markets(
&self,
limit: Option<u32>,
offset: Option<u32>,
) -> Result<Vec<GammaMarket>>
pub async fn get_gamma_markets( &self, limit: Option<u32>, offset: Option<u32>, ) -> Result<Vec<GammaMarket>>
Get markets from the Gamma API.
Sourcepub async fn get_gamma_market_by_slug(
&self,
slug: &str,
) -> Result<Vec<GammaMarket>>
pub async fn get_gamma_market_by_slug( &self, slug: &str, ) -> Result<Vec<GammaMarket>>
Search Gamma markets by slug.
Sourcepub async fn get_events(
&self,
limit: Option<u32>,
offset: Option<u32>,
) -> Result<Vec<GammaEvent>>
pub async fn get_events( &self, limit: Option<u32>, offset: Option<u32>, ) -> Result<Vec<GammaEvent>>
Get events from the Gamma API.
Sourcepub async fn get_event(&self, event_id: &str) -> Result<GammaEvent>
pub async fn get_event(&self, event_id: &str) -> Result<GammaEvent>
Get a single event by ID.
Sourcepub async fn search_markets(&self, query: &str) -> Result<Vec<GammaMarket>>
pub async fn search_markets(&self, query: &str) -> Result<Vec<GammaMarket>>
Search markets by text query.
Sourcepub async fn create_or_derive_api_key<S: Signer + Send + Sync>(
&self,
signer: &S,
nonce: Option<u64>,
) -> Result<ApiKeyResponse>
pub async fn create_or_derive_api_key<S: Signer + Send + Sync>( &self, signer: &S, nonce: Option<u64>, ) -> Result<ApiKeyResponse>
Create or derive API keys using L1 authentication.
Sourcepub async fn derive_api_key<S: Signer + Send + Sync>(
&self,
signer: &S,
) -> Result<ApiKeyResponse>
pub async fn derive_api_key<S: Signer + Send + Sync>( &self, signer: &S, ) -> Result<ApiKeyResponse>
Derive an existing API key.
Source§impl PolymarketClient<Authenticated>
impl PolymarketClient<Authenticated>
Sourcepub async fn get_orders(&self) -> Result<Vec<OpenOrder>>
pub async fn get_orders(&self) -> Result<Vec<OpenOrder>>
Get open orders for the authenticated user.
Sourcepub async fn post_order(
&self,
signed_order: &SignedOrder,
) -> Result<OrderResponse>
pub async fn post_order( &self, signed_order: &SignedOrder, ) -> Result<OrderResponse>
Post a pre-signed order to the API.
Sourcepub async fn create_and_post_order<S: Signer + Send + Sync>(
&self,
signer: &S,
params: &TradeParams,
) -> Result<OrderResponse>
pub async fn create_and_post_order<S: Signer + Send + Sync>( &self, signer: &S, params: &TradeParams, ) -> Result<OrderResponse>
Build, sign, and post an order in one call.
This is the most convenient way to place an order.
Sourcepub async fn cancel_order(&self, order_id: &str) -> Result<CancelResponse>
pub async fn cancel_order(&self, order_id: &str) -> Result<CancelResponse>
Cancel an order by ID.
Sourcepub async fn cancel_orders(&self, order_ids: &[&str]) -> Result<CancelResponse>
pub async fn cancel_orders(&self, order_ids: &[&str]) -> Result<CancelResponse>
Cancel multiple orders.
Sourcepub async fn cancel_all_orders(&self) -> Result<CancelResponse>
pub async fn cancel_all_orders(&self) -> Result<CancelResponse>
Cancel all open orders.
Trait Implementations§
Auto Trait Implementations§
impl<A> Freeze for PolymarketClient<A>
impl<A = Public> !RefUnwindSafe for PolymarketClient<A>
impl<A> Send for PolymarketClient<A>where
A: Send,
impl<A> Sync for PolymarketClient<A>where
A: Sync,
impl<A> Unpin for PolymarketClient<A>where
A: Unpin,
impl<A> UnsafeUnpin for PolymarketClient<A>
impl<A = Public> !UnwindSafe for PolymarketClient<A>
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