ClobClient

Struct ClobClient 

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

CLOB REST API client

Implementations§

Source§

impl ClobClient

Source

pub fn new() -> Self

Create a new CLOB client without authentication (for public endpoints)

Source

pub fn with_auth( api_key: String, api_secret: String, passphrase: String, address: String, ) -> Self

Create a new CLOB client with authentication

Source

pub fn from_env() -> Self

Create a new CLOB client from environment variables Requires: api_key, secret, passphrase, address (or poly_address)

Source

pub fn has_auth(&self) -> bool

Check if the client has authentication credentials

Source

pub async fn get_orderbook(&self, condition_id: &str) -> Result<Orderbook>

Get orderbook for a specific market (condition ID)

Source

pub async fn get_trades( &self, condition_id: &str, limit: Option<usize>, ) -> Result<Vec<Trade>>

Get recent trades for a specific market (condition ID)

Source

pub async fn get_orderbook_by_asset(&self, token_id: &str) -> Result<Orderbook>

Get orderbook for a specific token ID (clob_token_id from Gamma API)

Source

pub async fn get_trades_by_asset( &self, asset_id: &str, limit: Option<usize>, ) -> Result<Vec<Trade>>

Get recent trades for a specific asset ID

Source

pub async fn get_trades_authenticated( &self, market: &str, limit: Option<usize>, ) -> Result<Vec<Trade>>

Get recent trades for a specific market with authentication Returns trade count if authenticated, otherwise returns an error

Source

pub async fn get_trade_count(&self, market: &str) -> Result<usize>

Get trade count for a market (uses authenticated endpoint if credentials available)

Source

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

Get user’s orders (requires authentication)

Source

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

Get a specific order by ID (requires authentication)

Source

pub async fn place_order( &self, _market: &str, _side: Side, _order_type: OrderType, _size: &str, _price: Option<&str>, ) -> Result<Order>

Place a new order (requires authentication)

Source

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

Cancel an order (requires authentication)

Source

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

Get market price for a specific token and side

§Arguments
  • token_id - The unique identifier for the token
  • side - The side of the market (BUY or SELL)
Source

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

Get midpoint price for a specific token

The midpoint is the middle point between the current best bid and ask prices.

§Arguments
  • token_id - The unique identifier for the token
Source

pub async fn get_prices_history( &self, token_id: &str, start_ts: Option<i64>, end_ts: Option<i64>, interval: Option<PriceInterval>, fidelity: Option<u32>, ) -> Result<PriceHistoryResponse>

Get historical price data for a token

§Arguments
  • token_id - The CLOB token ID for which to fetch price history
  • start_ts - Optional start time as Unix timestamp in UTC
  • end_ts - Optional end time as Unix timestamp in UTC
  • interval - Optional interval string (mutually exclusive with start_ts/end_ts)
  • fidelity - Optional resolution of the data in minutes
Source

pub async fn get_spreads( &self, requests: Vec<SpreadRequest>, ) -> Result<HashMap<String, String>>

Get bid-ask spreads for multiple tokens

§Arguments
  • requests - Array of spread requests (max 500)
Source

pub async fn get_orderbooks( &self, requests: Vec<BatchTokenRequest>, ) -> Result<Vec<Orderbook>>

Get multiple orderbooks at once

§Arguments
  • requests - Array of batch token requests (max 500)
Source

pub async fn get_prices_batch( &self, requests: Vec<BatchTokenRequest>, ) -> Result<HashMap<String, TokenPrices>>

Get multiple market prices at once (batch)

§Arguments
  • requests - Array of batch token requests (max 500)
§Returns

HashMap mapping token_id to TokenPrices (buy/sell prices)

Trait Implementations§

Source§

impl Default for ClobClient

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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