polymarket_rs/request/
data_params.rs

1/// Sort direction for activity queries
2#[derive(Debug, Clone)]
3pub enum SortDirection {
4    Asc,
5    Desc,
6}
7
8impl SortDirection {
9    pub fn as_str(&self) -> &str {
10        match self {
11            SortDirection::Asc => "ASC",
12            SortDirection::Desc => "DESC",
13        }
14    }
15}
16
17/// Sort field for activity queries
18#[derive(Debug, Clone)]
19pub enum ActivitySortBy {
20    Timestamp,
21}
22
23impl ActivitySortBy {
24    pub fn as_str(&self) -> &str {
25        match self {
26            ActivitySortBy::Timestamp => "TIMESTAMP",
27        }
28    }
29}
30
31/// Query parameters for trade endpoints with offset/limit pagination
32#[derive(Debug, Clone, Default)]
33pub struct TradeQueryParams {
34    pub limit: Option<u32>,
35    pub offset: Option<u32>,
36    pub taker_only: Option<bool>,
37}
38
39impl TradeQueryParams {
40    pub fn new() -> Self {
41        Self::default()
42    }
43
44    pub fn with_limit(mut self, limit: u32) -> Self {
45        self.limit = Some(limit);
46        self
47    }
48
49    pub fn with_offset(mut self, offset: u32) -> Self {
50        self.offset = Some(offset);
51        self
52    }
53
54    pub fn with_taker_only(mut self, taker_only: bool) -> Self {
55        self.taker_only = Some(taker_only);
56        self
57    }
58
59    pub fn to_query_string(&self) -> String {
60        let mut params = Vec::new();
61
62        if let Some(limit) = self.limit {
63            params.push(format!("limit={}", limit));
64        }
65        if let Some(offset) = self.offset {
66            params.push(format!("offset={}", offset));
67        }
68        if let Some(taker_only) = self.taker_only {
69            params.push(format!("takerOnly={}", taker_only));
70        }
71
72        if params.is_empty() {
73            String::new()
74        } else {
75            format!("&{}", params.join("&"))
76        }
77    }
78}
79
80/// Query parameters for activity endpoints with offset/limit pagination and sorting
81#[derive(Debug, Clone, Default)]
82pub struct ActivityQueryParams {
83    pub limit: Option<u32>,
84    pub offset: Option<u32>,
85    pub sort_by: Option<ActivitySortBy>,
86    pub sort_direction: Option<SortDirection>,
87}
88
89impl ActivityQueryParams {
90    pub fn new() -> Self {
91        Self::default()
92    }
93
94    pub fn with_limit(mut self, limit: u32) -> Self {
95        self.limit = Some(limit);
96        self
97    }
98
99    pub fn with_offset(mut self, offset: u32) -> Self {
100        self.offset = Some(offset);
101        self
102    }
103
104    pub fn with_sort_by(mut self, sort_by: ActivitySortBy) -> Self {
105        self.sort_by = Some(sort_by);
106        self
107    }
108
109    pub fn with_sort_direction(mut self, sort_direction: SortDirection) -> Self {
110        self.sort_direction = Some(sort_direction);
111        self
112    }
113
114    pub fn to_query_string(&self) -> String {
115        let mut params = Vec::new();
116
117        if let Some(limit) = self.limit {
118            params.push(format!("limit={}", limit));
119        }
120        if let Some(ref sort_by) = self.sort_by {
121            params.push(format!("sortBy={}", sort_by.as_str()));
122        }
123        if let Some(ref sort_direction) = self.sort_direction {
124            params.push(format!("sortDirection={}", sort_direction.as_str()));
125        }
126        if let Some(offset) = self.offset {
127            params.push(format!("offset={}", offset));
128        }
129
130        if params.is_empty() {
131            String::new()
132        } else {
133            format!("&{}", params.join("&"))
134        }
135    }
136}