pub struct PredictClient { /* private fields */ }Expand description
Client for interacting with predict.fun
Implementations§
Source§impl PredictClient
impl PredictClient
Sourcepub fn new(
chain_id: u64,
private_key: &str,
api_base_url: String,
api_key: Option<String>,
) -> Result<Self>
pub fn new( chain_id: u64, private_key: &str, api_base_url: String, api_key: Option<String>, ) -> Result<Self>
Create a new PredictClient with full trading capability
Sourcepub fn new_with_predict_account(
chain_id: u64,
privy_private_key: &str,
predict_account: &str,
api_base_url: String,
api_key: Option<String>,
) -> Result<Self>
pub fn new_with_predict_account( chain_id: u64, privy_private_key: &str, predict_account: &str, api_base_url: String, api_key: Option<String>, ) -> Result<Self>
Create a new PredictClient with Predict Smart Wallet (Kernel) signing
Sourcepub fn new_readonly(
chain_id: u64,
api_base_url: String,
api_key: Option<String>,
) -> Result<Self>
pub fn new_readonly( chain_id: u64, api_base_url: String, api_key: Option<String>, ) -> Result<Self>
Create a read-only PredictClient for market data operations
Sourcepub fn uses_predict_account(&self) -> bool
pub fn uses_predict_account(&self) -> bool
Check if this client uses Predict Account (Kernel) signing
Sourcepub fn predict_account(&self) -> Option<String>
pub fn predict_account(&self) -> Option<String>
Get the Predict Account address if configured
Sourcepub async fn authenticate(&self) -> Result<String>
pub async fn authenticate(&self) -> Result<String>
Authenticate with Predict API and obtain a JWT token
Flow:
- GET /v1/auth/message → dynamic message to sign
- Sign message with wallet private key (EIP-191 personal sign)
- POST /v1/auth → submit signature → receive JWT
The JWT is required for authenticated WebSocket subscriptions
(e.g., predictWalletEvents/{jwt} for order fill notifications).
Sourcepub async fn authenticate_and_store(&self) -> Result<String>
pub async fn authenticate_and_store(&self) -> Result<String>
Authenticate and store the JWT token for subsequent REST API requests
This calls authenticate() and stores the resulting JWT so that
add_auth_headers() will include Authorization: Bearer {jwt} on all requests.
Sourcepub async fn get_markets(&self) -> Result<Vec<PredictMarket>>
pub async fn get_markets(&self) -> Result<Vec<PredictMarket>>
Fetch all markets from Predict
Sourcepub async fn get_orderbook(&self, market_id: &str) -> Result<PredictOrderBook>
pub async fn get_orderbook(&self, market_id: &str) -> Result<PredictOrderBook>
Fetch orderbook for a specific market
Sourcepub async fn place_limit_order(
&self,
token_id: &str,
side: Side,
price: Decimal,
quantity: Decimal,
is_neg_risk: bool,
is_yield_bearing: bool,
fee_rate_bps: u64,
) -> Result<PlaceOrderResponse>
pub async fn place_limit_order( &self, token_id: &str, side: Side, price: Decimal, quantity: Decimal, is_neg_risk: bool, is_yield_bearing: bool, fee_rate_bps: u64, ) -> Result<PlaceOrderResponse>
Place a limit order on Predict
Builds, signs, and submits a limit order to the Predict API. Returns the order ID and hash on success.
Sourcepub async fn cancel_orders(
&self,
order_ids: &[String],
) -> Result<RemoveOrdersResponse>
pub async fn cancel_orders( &self, order_ids: &[String], ) -> Result<RemoveOrdersResponse>
Cancel orders by their IDs
Removes orders from the Predict orderbook. Note: This removes orders from the orderbook but does not cancel on-chain.
§Arguments
order_ids- Order IDs to cancel (max 100)
Sourcepub async fn get_open_orders(&self) -> Result<Vec<PredictOrder>>
pub async fn get_open_orders(&self) -> Result<Vec<PredictOrder>>
Fetch open orders for this account
Returns all orders with status OPEN for the authenticated user.
Sourcepub async fn get_positions(&self) -> Result<Vec<PredictPosition>>
pub async fn get_positions(&self) -> Result<Vec<PredictPosition>>
Fetch positions (token balances) for this account
Sourcepub fn signer_address(&self) -> Result<String>
pub fn signer_address(&self) -> Result<String>
Get the signer address
Sourcepub fn order_builder(&self) -> &OrderBuilder
pub fn order_builder(&self) -> &OrderBuilder
Get the order builder
Sourcepub fn api_base_url(&self) -> &str
pub fn api_base_url(&self) -> &str
Get the API base URL
Sourcepub async fn get_category(&self, slug: &str) -> Result<PredictCategory>
pub async fn get_category(&self, slug: &str) -> Result<PredictCategory>
Fetch a category by slug from Predict
Sourcepub async fn get_category_optional(
&self,
slug: &str,
) -> Result<Option<PredictCategory>>
pub async fn get_category_optional( &self, slug: &str, ) -> Result<Option<PredictCategory>>
Fetch a category by slug, returning None if not found
Sourcepub async fn set_approvals(
&self,
is_neg_risk: bool,
is_yield_bearing: bool,
) -> Result<()>
pub async fn set_approvals( &self, is_neg_risk: bool, is_yield_bearing: bool, ) -> Result<()>
Set all necessary on-chain approvals for trading.
This must be called once before placing orders. It sets:
- ERC-1155 approval on Conditional Tokens for the CTF Exchange
- ERC-20 approval on USDT for the CTF Exchange
- Neg Risk Adapter approval (if is_neg_risk)
Sourcepub async fn split_positions(
&self,
condition_id: &str,
amount: f64,
is_neg_risk: bool,
is_yield_bearing: bool,
) -> Result<String>
pub async fn split_positions( &self, condition_id: &str, amount: f64, is_neg_risk: bool, is_yield_bearing: bool, ) -> Result<String>
Split USDT into UP/DOWN outcome tokens for a market.
When a predict_account is configured, splits via Kernel so tokens land on the predict_account (which is the order maker). When using direct EOA, splits directly.
Auto Trait Implementations§
impl !Freeze for PredictClient
impl !RefUnwindSafe for PredictClient
impl Send for PredictClient
impl Sync for PredictClient
impl Unpin for PredictClient
impl !UnwindSafe for PredictClient
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