Skip to main content

DataClient

Struct DataClient 

Source
pub struct DataClient { /* private fields */ }
Available on crate feature client only.
Expand description

Data API client for trader data, positions, and leaderboards

Implementations§

Source§

impl DataClient

Source

pub fn new(config: DataConfig) -> Result<Self>

Create a new Data API client

Source

pub fn with_defaults() -> Result<Self>

Create client with default configuration

Source

pub fn from_env() -> Result<Self>

👎Deprecated since 0.1.0: Use DataClient::with_defaults() instead

Create client from environment variables.

Deprecated: Use DataClient::with_defaults() instead.

Source

pub async fn get_trader_profile(&self, address: &str) -> Result<DataApiTrader>

Get trader profile by wallet address

Source

pub async fn get_positions_with_query( &self, query: &PositionsQuery, ) -> Result<Vec<DataApiPosition>>

Get positions for a wallet address with query parameters

§Examples
use polymarket_sdk::data::{DataClient, DataConfig};
use polymarket_sdk::types::{PositionsQuery, PositionSortBy, SortDirection};

let client = DataClient::new(DataConfig::default())?;

// Simple query - just user address
let positions = client.get_positions_with_query(
    &PositionsQuery::new("0x...")
).await?;

// Advanced query with filters
let query = PositionsQuery::new("0x...")
    .with_size_threshold(10.0)
    .redeemable_only()
    .with_limit(50)
    .sort_by(PositionSortBy::CashPnl)
    .sort_direction(SortDirection::Desc);

let positions = client.get_positions_with_query(&query).await?;
Source

pub async fn get_positions(&self, address: &str) -> Result<Vec<DataApiPosition>>

Get positions for a wallet address (simple version)

For more control over query parameters, use Self::get_positions_with_query.

Source

pub async fn get_trades( &self, address: &str, limit: Option<u32>, ) -> Result<Vec<DataApiTrade>>

Get trades for a wallet address

Source

pub async fn get_user_activity_with_query( &self, query: &ActivityQuery, ) -> Result<Vec<DataApiActivity>>

Get user activity with full query options

Use ActivityQuery to build complex queries with filtering, sorting, and pagination.

§Example
use polymarket_sdk::types::{ActivityQuery, ActivityType, ActivitySortBy, SortDirection, Side};

// Get recent trades for a user
let query = ActivityQuery::new("0x...")
    .trades_only()
    .with_limit(50)
    .newest_first();

let activity = client.get_user_activity_with_query(&query).await?;

// Get buy trades in a specific time range
let query = ActivityQuery::new("0x...")
    .with_type(ActivityType::Trade)
    .buys_only()
    .with_time_range(start_ts, end_ts)
    .largest_first();

let activity = client.get_user_activity_with_query(&query).await?;
Source

pub async fn get_user_activity( &self, address: &str, limit: Option<u32>, offset: Option<u32>, ) -> Result<Vec<DataApiActivity>>

Get user activity (trades, position changes) - simple version

For more control over query parameters, use Self::get_user_activity_with_query.

Source

pub async fn get_closed_positions( &self, address: &str, limit: Option<u32>, offset: Option<u32>, ) -> Result<Vec<ClosedPosition>>

Get closed positions for a user (for PnL calculation)

Source

pub async fn get_redeemable_positions( &self, address: &str, ) -> Result<Vec<DataApiPosition>>

Get all redeemable positions for a user

Convenience method to fetch positions that can be redeemed

Source

pub async fn get_mergeable_positions( &self, address: &str, ) -> Result<Vec<DataApiPosition>>

Get all mergeable positions for a user

Convenience method to fetch positions that can be merged

Source

pub async fn get_positions_for_markets( &self, address: &str, market_ids: Vec<String>, ) -> Result<Vec<DataApiPosition>>

Get positions for specific markets

§Arguments
  • address - User wallet address
  • market_ids - Vector of market condition IDs
Source

pub async fn get_positions_for_events( &self, address: &str, event_ids: Vec<i64>, ) -> Result<Vec<DataApiPosition>>

Get positions for specific events

§Arguments
  • address - User wallet address
  • event_ids - Vector of event IDs
Source

pub async fn get_top_profitable_positions( &self, address: &str, limit: Option<u32>, ) -> Result<Vec<DataApiPosition>>

Get top profitable positions sorted by PnL

§Arguments
  • address - User wallet address
  • limit - Number of positions to return (default: 10)
Source

pub async fn get_positions_above_size( &self, address: &str, threshold: f64, ) -> Result<Vec<DataApiPosition>>

Get positions above a certain size threshold

§Arguments
  • address - User wallet address
  • threshold - Minimum position size
Source

pub async fn get_biggest_winners( &self, query: &BiggestWinnersQuery, ) -> Result<Vec<BiggestWinner>>

Get biggest winners by category and time period

Source

pub async fn get_top_biggest_winners( &self, category: &str, time_period: &str, total_limit: usize, ) -> Result<Vec<BiggestWinner>>

Get top biggest winners with auto-pagination

Fetches winners in batches of 100 until reaching total_limit

Source

pub async fn get_token_midpoint(&self, token_id: &str) -> Result<f64>

Get token midpoint price from CLOB

Source

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

Get order book for a token

Trait Implementations§

Source§

impl Clone for DataClient

Source§

fn clone(&self) -> DataClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DataClient

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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