pub struct DataClient { /* private fields */ }client only.Expand description
Data API client for trader data, positions, and leaderboards
Implementations§
Source§impl DataClient
impl DataClient
Sourcepub fn new(config: DataConfig) -> Result<Self>
pub fn new(config: DataConfig) -> Result<Self>
Create a new Data API client
Sourcepub fn with_defaults() -> Result<Self>
pub fn with_defaults() -> Result<Self>
Create client with default configuration
Sourcepub fn from_env() -> Result<Self>
👎Deprecated since 0.1.0: Use DataClient::with_defaults() instead
pub fn from_env() -> Result<Self>
Create client from environment variables.
Deprecated: Use DataClient::with_defaults() instead.
Sourcepub async fn get_trader_profile(&self, address: &str) -> Result<DataApiTrader>
pub async fn get_trader_profile(&self, address: &str) -> Result<DataApiTrader>
Get trader profile by wallet address
Sourcepub async fn get_positions_with_query(
&self,
query: &PositionsQuery,
) -> Result<Vec<DataApiPosition>>
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?;Sourcepub async fn get_positions(&self, address: &str) -> Result<Vec<DataApiPosition>>
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.
Sourcepub async fn get_trades(
&self,
address: &str,
limit: Option<u32>,
) -> Result<Vec<DataApiTrade>>
pub async fn get_trades( &self, address: &str, limit: Option<u32>, ) -> Result<Vec<DataApiTrade>>
Get trades for a wallet address
Sourcepub async fn get_user_activity_with_query(
&self,
query: &ActivityQuery,
) -> Result<Vec<DataApiActivity>>
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?;Sourcepub async fn get_user_activity(
&self,
address: &str,
limit: Option<u32>,
offset: Option<u32>,
) -> Result<Vec<DataApiActivity>>
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.
Sourcepub async fn get_closed_positions(
&self,
address: &str,
limit: Option<u32>,
offset: Option<u32>,
) -> Result<Vec<ClosedPosition>>
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)
Sourcepub async fn get_redeemable_positions(
&self,
address: &str,
) -> Result<Vec<DataApiPosition>>
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
Sourcepub async fn get_mergeable_positions(
&self,
address: &str,
) -> Result<Vec<DataApiPosition>>
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
Sourcepub async fn get_positions_for_markets(
&self,
address: &str,
market_ids: Vec<String>,
) -> Result<Vec<DataApiPosition>>
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 addressmarket_ids- Vector of market condition IDs
Sourcepub async fn get_positions_for_events(
&self,
address: &str,
event_ids: Vec<i64>,
) -> Result<Vec<DataApiPosition>>
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 addressevent_ids- Vector of event IDs
Sourcepub async fn get_top_profitable_positions(
&self,
address: &str,
limit: Option<u32>,
) -> Result<Vec<DataApiPosition>>
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 addresslimit- Number of positions to return (default: 10)
Sourcepub async fn get_positions_above_size(
&self,
address: &str,
threshold: f64,
) -> Result<Vec<DataApiPosition>>
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 addressthreshold- Minimum position size
Sourcepub async fn get_biggest_winners(
&self,
query: &BiggestWinnersQuery,
) -> Result<Vec<BiggestWinner>>
pub async fn get_biggest_winners( &self, query: &BiggestWinnersQuery, ) -> Result<Vec<BiggestWinner>>
Get biggest winners by category and time period
Sourcepub async fn get_top_biggest_winners(
&self,
category: &str,
time_period: &str,
total_limit: usize,
) -> Result<Vec<BiggestWinner>>
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
Sourcepub async fn get_token_midpoint(&self, token_id: &str) -> Result<f64>
pub async fn get_token_midpoint(&self, token_id: &str) -> Result<f64>
Get token midpoint price from CLOB
Sourcepub async fn get_order_book(&self, token_id: &str) -> Result<Value>
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
impl Clone for DataClient
Source§fn clone(&self) -> DataClient
fn clone(&self) -> DataClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DataClient
impl !RefUnwindSafe for DataClient
impl Send for DataClient
impl Sync for DataClient
impl Unpin for DataClient
impl UnsafeUnpin for DataClient
impl !UnwindSafe for DataClient
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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