pub struct ClobClient { /* private fields */ }Expand description
CLOB REST API client
Implementations§
Source§impl ClobClient
impl ClobClient
Sourcepub fn with_auth(
api_key: String,
api_secret: String,
passphrase: String,
address: String,
) -> Self
pub fn with_auth( api_key: String, api_secret: String, passphrase: String, address: String, ) -> Self
Create a new CLOB client with authentication
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create a new CLOB client from environment variables Requires: api_key, secret, passphrase, address (or poly_address)
Sourcepub async fn get_orderbook(&self, condition_id: &str) -> Result<Orderbook>
pub async fn get_orderbook(&self, condition_id: &str) -> Result<Orderbook>
Get orderbook for a specific market (condition ID)
Sourcepub async fn get_trades(
&self,
condition_id: &str,
limit: Option<usize>,
) -> Result<Vec<Trade>>
pub async fn get_trades( &self, condition_id: &str, limit: Option<usize>, ) -> Result<Vec<Trade>>
Get recent trades for a specific market (condition ID)
Sourcepub async fn get_orderbook_by_asset(&self, token_id: &str) -> Result<Orderbook>
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)
Sourcepub async fn get_trades_by_asset(
&self,
asset_id: &str,
limit: Option<usize>,
) -> Result<Vec<Trade>>
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
Sourcepub async fn get_trades_authenticated(
&self,
market: &str,
limit: Option<usize>,
) -> Result<Vec<Trade>>
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
Sourcepub async fn get_trade_count(&self, market: &str) -> Result<usize>
pub async fn get_trade_count(&self, market: &str) -> Result<usize>
Get trade count for a market (uses authenticated endpoint if credentials available)
Sourcepub async fn get_orders(&self) -> Result<Vec<Order>>
pub async fn get_orders(&self) -> Result<Vec<Order>>
Get user’s orders (requires authentication)
Sourcepub async fn get_order(&self, order_id: &str) -> Result<Order>
pub async fn get_order(&self, order_id: &str) -> Result<Order>
Get a specific order by ID (requires authentication)
Sourcepub async fn place_order(
&self,
_market: &str,
_side: Side,
_order_type: OrderType,
_size: &str,
_price: Option<&str>,
) -> Result<Order>
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)
Sourcepub async fn cancel_order(&self, order_id: &str) -> Result<()>
pub async fn cancel_order(&self, order_id: &str) -> Result<()>
Cancel an order (requires authentication)
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 market price for a specific token and side
§Arguments
token_id- The unique identifier for the tokenside- The side of the market (BUY or SELL)
Sourcepub async fn get_midpoint(&self, token_id: &str) -> Result<MidpointResponse>
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
Sourcepub 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>
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 historystart_ts- Optional start time as Unix timestamp in UTCend_ts- Optional end time as Unix timestamp in UTCinterval- Optional interval string (mutually exclusive with start_ts/end_ts)fidelity- Optional resolution of the data in minutes