Skip to main content

PredictClient

Struct PredictClient 

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

Client for interacting with predict.fun

Implementations§

Source§

impl PredictClient

Source

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

Source

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

Source

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

Source

pub fn can_sign(&self) -> bool

Check if this client has signing capability

Source

pub fn uses_predict_account(&self) -> bool

Check if this client uses Predict Account (Kernel) signing

Source

pub fn predict_account(&self) -> Option<String>

Get the Predict Account address if configured

Source

pub async fn authenticate(&self) -> Result<String>

Authenticate with Predict API and obtain a JWT token

Flow:

  1. GET /v1/auth/message → dynamic message to sign
  2. Sign message with wallet private key (EIP-191 personal sign)
  3. POST /v1/auth → submit signature → receive JWT

The JWT is required for authenticated WebSocket subscriptions (e.g., predictWalletEvents/{jwt} for order fill notifications).

Source

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.

Source

pub fn jwt_token(&self) -> Option<String>

Get the stored JWT token (if authenticated)

Source

pub async fn get_markets(&self) -> Result<Vec<PredictMarket>>

Fetch all markets from Predict

Source

pub async fn get_orderbook(&self, market_id: &str) -> Result<PredictOrderBook>

Fetch orderbook for a specific market

Source

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.

Source

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

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.

Source

pub async fn get_positions(&self) -> Result<Vec<PredictPosition>>

Fetch positions (token balances) for this account

Source

pub fn signer_address(&self) -> Result<String>

Get the signer address

Source

pub fn chain_id(&self) -> ChainId

Get the chain ID

Source

pub fn api_key(&self) -> Option<&str>

Get the API key (if set)

Source

pub fn order_builder(&self) -> &OrderBuilder

Get the order builder

Source

pub fn api_base_url(&self) -> &str

Get the API base URL

Source

pub async fn get_category(&self, slug: &str) -> Result<PredictCategory>

Fetch a category by slug from Predict

Source

pub async fn get_category_optional( &self, slug: &str, ) -> Result<Option<PredictCategory>>

Fetch a category by slug, returning None if not found

Source

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

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§

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