Skip to main content

PolymarketClient

Struct PolymarketClient 

Source
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 endpoints
  • PolymarketClient<Authenticated> — can call all endpoints including trading

Implementations§

Source§

impl PolymarketClient<Public>

Source

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.

Source

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 PolymarketClient<Authenticated>

Source

pub fn with_l2( host: Option<&str>, chain_id: u64, creds: ApiCredentials, ) -> Result<Self>

Create a client with L2 credentials for trading.

Source§

impl<A> PolymarketClient<A>

Source

pub fn builder() -> PolymarketClientBuilder

Builder-style: create a fully configured client.

Source

pub fn chain_id(&self) -> u64

Get the configured chain ID.

Source

pub fn has_credentials(&self) -> bool

Check if L2 credentials are configured.

Source

pub fn set_funder(&mut self, funder: Address)

Set the funder address (for proxy wallets).

Source

pub fn set_signature_type(&mut self, sig_type: SignatureType)

Set the signature type.

Source

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

Get simplified markets.

Source

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

Get simplified markets (paginated).

Source

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

Get markets from the CLOB API.

Source

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

Get a single market by condition ID.

Source

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

Get the order book for a token.

Source

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

Get the midpoint price for a token.

Source

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

Get the current price for a token.

Source

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

Get the spread for a token.

Source

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

Get the last trade price for a token.

Source

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.

Source

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

Get tick size for a token.

Source

pub async fn get_gamma_markets( &self, limit: Option<u32>, offset: Option<u32>, ) -> Result<Vec<GammaMarket>>

Get markets from the Gamma API.

Source

pub async fn get_gamma_market_by_slug( &self, slug: &str, ) -> Result<Vec<GammaMarket>>

Search Gamma markets by slug.

Source

pub async fn get_events( &self, limit: Option<u32>, offset: Option<u32>, ) -> Result<Vec<GammaEvent>>

Get events from the Gamma API.

Source

pub async fn get_event(&self, event_id: &str) -> Result<GammaEvent>

Get a single event by ID.

Source

pub async fn search_markets(&self, query: &str) -> Result<Vec<GammaMarket>>

Search markets by text query.

Source

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.

Source

pub async fn derive_api_key<S: Signer + Send + Sync>( &self, signer: &S, ) -> Result<ApiKeyResponse>

Derive an existing API key.

Source

pub async fn delete_api_key<S: Signer + Send + Sync>( &self, signer: &S, ) -> Result<Value>

Delete an API key.

Source§

impl PolymarketClient<Authenticated>

Source

pub async fn get_orders(&self) -> Result<Vec<OpenOrder>>

Get open orders for the authenticated user.

Source

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

Get a single order by ID.

Source

pub async fn post_order( &self, signed_order: &SignedOrder, ) -> Result<OrderResponse>

Post a pre-signed order to the API.

Source

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.

Source

pub async fn cancel_order(&self, order_id: &str) -> Result<CancelResponse>

Cancel an order by ID.

Source

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

Cancel multiple orders.

Source

pub async fn cancel_all_orders(&self) -> Result<CancelResponse>

Cancel all open orders.

Trait Implementations§

Source§

impl<A: Debug> Debug for PolymarketClient<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> 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