polymarket-hft 0.0.7

A high-frequency trading system for Polymarket with built-in API clients (Data API, CLOB, CLOB WebSocket, Gamma, RTDS) and CLI
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
use clap::Args;
use polymarket_hft::client::polymarket::gamma::{
    GetCommentsRequest, GetEventsRequest, GetMarketsRequest, GetSeriesRequest, GetTagsRequest,
    GetTeamsRequest, SearchRequest,
};

#[derive(Args, Debug, Clone)]
pub struct GetTeamsArgs {
    /// Limit results (1-1000)
    #[arg(short, long)]
    pub limit: Option<u32>,
    /// Offset for pagination (>= 0)
    #[arg(short, long)]
    pub offset: Option<u32>,
    /// Order expression (comma-separated)
    #[arg(long)]
    pub order: Option<String>,
    /// Sort ascending
    #[arg(long)]
    pub ascending: Option<bool>,
    /// Filter by league (repeatable)
    #[arg(long)]
    pub league: Option<Vec<String>>,
    /// Filter by name (repeatable)
    #[arg(long)]
    pub name: Option<Vec<String>>,
    /// Filter by abbreviation (repeatable)
    #[arg(long)]
    pub abbreviation: Option<Vec<String>>,
}

impl<'a> From<&'a GetTeamsArgs> for GetTeamsRequest<'a> {
    fn from(args: &'a GetTeamsArgs) -> Self {
        GetTeamsRequest {
            limit: args.limit,
            offset: args.offset,
            order: args.order.as_deref(),
            ascending: args.ascending,
            league: args.league.clone(),
            name: args.name.clone(),
            abbreviation: args.abbreviation.clone(),
        }
    }
}

#[derive(Args, Debug, Clone)]
pub struct GetTagsArgs {
    /// Limit results (1-1000)
    #[arg(short, long)]
    pub limit: Option<u32>,
    /// Offset for pagination (>= 0)
    #[arg(short, long)]
    pub offset: Option<u32>,
    /// Order expression (comma-separated)
    #[arg(long)]
    pub order: Option<String>,
    /// Sort ascending
    #[arg(long)]
    pub ascending: Option<bool>,
    /// Include template tags
    #[arg(long)]
    pub include_template: Option<bool>,
    /// Filter for carousel tags
    #[arg(long)]
    pub is_carousel: Option<bool>,
}

impl<'a> From<&'a GetTagsArgs> for GetTagsRequest<'a> {
    fn from(args: &'a GetTagsArgs) -> Self {
        GetTagsRequest {
            limit: args.limit,
            offset: args.offset,
            order: args.order.as_deref(),
            ascending: args.ascending,
            include_template: args.include_template,
            is_carousel: args.is_carousel,
        }
    }
}

#[derive(Args, Debug, Clone)]
pub struct GetEventsArgs {
    /// Limit results
    #[arg(short, long)]
    pub limit: Option<u32>,
    /// Offset for pagination (>= 0)
    #[arg(short, long)]
    pub offset: Option<u32>,
    /// Order expression (per Gamma API)
    #[arg(long)]
    pub order: Option<String>,
    /// Sort direction ascending flag
    #[arg(long)]
    pub ascending: Option<bool>,
    /// Filter by event IDs (repeatable)
    #[arg(long)]
    pub id: Option<Vec<String>>,
    /// Filter by tag ID
    #[arg(long)]
    pub tag_id: Option<String>,
    /// Exclude tag IDs (repeatable)
    #[arg(long)]
    pub exclude_tag_id: Option<Vec<String>>,
    /// Filter by event slugs (repeatable)
    #[arg(long)]
    pub slug: Option<Vec<String>>,
    /// Filter by tag slug
    #[arg(long)]
    pub tag_slug: Option<String>,
    /// Include related tags
    #[arg(long)]
    pub related_tags: Option<bool>,
    /// Filter by active status
    #[arg(long)]
    pub active: Option<bool>,
    /// Filter by archived status
    #[arg(long)]
    pub archived: Option<bool>,
    /// Filter by featured flag
    #[arg(long)]
    pub featured: Option<bool>,
    /// Filter by create-your-own-markets flag
    #[arg(long)]
    pub cyom: Option<bool>,
    /// Include chat channel metadata
    #[arg(long)]
    pub include_chat: Option<bool>,
    /// Include template fields
    #[arg(long)]
    pub include_template: Option<bool>,
    /// Filter by recurrence
    #[arg(long)]
    pub recurrence: Option<String>,
    /// Filter by closed status
    #[arg(long)]
    pub closed: Option<bool>,
    /// Minimum liquidity
    #[arg(long)]
    pub liquidity_min: Option<f64>,
    /// Maximum liquidity
    #[arg(long)]
    pub liquidity_max: Option<f64>,
    /// Minimum volume
    #[arg(long)]
    pub volume_min: Option<f64>,
    /// Maximum volume
    #[arg(long)]
    pub volume_max: Option<f64>,
    /// Minimum start date (ISO-8601)
    #[arg(long)]
    pub start_date_min: Option<String>,
    /// Maximum start date (ISO-8601)
    #[arg(long)]
    pub start_date_max: Option<String>,
    /// Minimum end date (ISO-8601)
    #[arg(long)]
    pub end_date_min: Option<String>,
    /// Maximum end date (ISO-8601)
    #[arg(long)]
    pub end_date_max: Option<String>,
}

impl<'a> From<&'a GetEventsArgs> for GetEventsRequest<'a> {
    fn from(args: &'a GetEventsArgs) -> Self {
        GetEventsRequest {
            limit: args.limit,
            offset: args.offset,
            order: args.order.as_deref(),
            ascending: args.ascending,
            id: args.id.clone(),
            tag_id: args.tag_id.as_deref(),
            exclude_tag_id: args.exclude_tag_id.clone(),
            slug: args.slug.clone(),
            tag_slug: args.tag_slug.as_deref(),
            related_tags: args.related_tags,
            active: args.active,
            archived: args.archived,
            featured: args.featured,
            cyom: args.cyom,
            include_chat: args.include_chat,
            include_template: args.include_template,
            recurrence: args.recurrence.as_deref(),
            closed: args.closed,
            liquidity_min: args.liquidity_min,
            liquidity_max: args.liquidity_max,
            volume_min: args.volume_min,
            volume_max: args.volume_max,
            start_date_min: args.start_date_min.as_deref(),
            start_date_max: args.start_date_max.as_deref(),
            end_date_min: args.end_date_min.as_deref(),
            end_date_max: args.end_date_max.as_deref(),
        }
    }
}

#[derive(Args, Debug, Clone)]
pub struct GetMarketsArgs {
    /// Limit results (1-1000)
    #[arg(short, long)]
    pub limit: Option<u32>,
    /// Offset for pagination (>= 0)
    #[arg(short, long)]
    pub offset: Option<u32>,
    /// Order expression
    #[arg(long)]
    pub order: Option<String>,
    /// Sort ascending
    #[arg(long)]
    pub ascending: Option<bool>,
    /// Filter by market IDs (repeatable)
    #[arg(long)]
    pub id: Option<Vec<String>>,
    /// Filter by market slugs (repeatable)
    #[arg(long)]
    pub slug: Option<Vec<String>>,
    /// Filter by CLOB token IDs (repeatable)
    #[arg(long)]
    pub clob_token_ids: Option<Vec<String>>,
    /// Filter by condition IDs (repeatable)
    #[arg(long)]
    pub condition_ids: Option<Vec<String>>,
    /// Filter by market maker addresses (repeatable)
    #[arg(long)]
    pub market_maker_address: Option<Vec<String>>,
    /// Minimum liquidity
    #[arg(long)]
    pub liquidity_num_min: Option<f64>,
    /// Maximum liquidity
    #[arg(long)]
    pub liquidity_num_max: Option<f64>,
    /// Minimum volume
    #[arg(long)]
    pub volume_num_min: Option<f64>,
    /// Maximum volume
    #[arg(long)]
    pub volume_num_max: Option<f64>,
    /// Minimum start date (ISO-8601)
    #[arg(long)]
    pub start_date_min: Option<String>,
    /// Maximum start date (ISO-8601)
    #[arg(long)]
    pub start_date_max: Option<String>,
    /// Minimum end date (ISO-8601)
    #[arg(long)]
    pub end_date_min: Option<String>,
    /// Maximum end date (ISO-8601)
    #[arg(long)]
    pub end_date_max: Option<String>,
    /// Filter by tag ID
    #[arg(long)]
    pub tag_id: Option<String>,
    /// Include related tags
    #[arg(long)]
    pub related_tags: Option<bool>,
    /// Filter by create-your-own-market flag
    #[arg(long)]
    pub cyom: Option<bool>,
    /// Filter by UMA resolution status
    #[arg(long)]
    pub uma_resolution_status: Option<String>,
    /// Filter by game ID
    #[arg(long)]
    pub game_id: Option<String>,
    /// Filter by sports market types (repeatable)
    #[arg(long)]
    pub sports_market_types: Option<Vec<String>>,
    /// Minimum rewards size
    #[arg(long)]
    pub rewards_min_size: Option<f64>,
    /// Filter by question IDs (repeatable)
    #[arg(long)]
    pub question_ids: Option<Vec<String>>,
    /// Include tags in response
    #[arg(long)]
    pub include_tag: Option<bool>,
    /// Filter by closed status
    #[arg(long)]
    pub closed: Option<bool>,
}

impl<'a> From<&'a GetMarketsArgs> for GetMarketsRequest<'a> {
    fn from(args: &'a GetMarketsArgs) -> Self {
        GetMarketsRequest {
            limit: args.limit,
            offset: args.offset,
            order: args.order.as_deref(),
            ascending: args.ascending,
            id: args.id.clone(),
            slug: args.slug.clone(),
            clob_token_ids: args.clob_token_ids.clone(),
            condition_ids: args.condition_ids.clone(),
            market_maker_address: args.market_maker_address.clone(),
            liquidity_num_min: args.liquidity_num_min,
            liquidity_num_max: args.liquidity_num_max,
            volume_num_min: args.volume_num_min,
            volume_num_max: args.volume_num_max,
            start_date_min: args.start_date_min.as_deref(),
            start_date_max: args.start_date_max.as_deref(),
            end_date_min: args.end_date_min.as_deref(),
            end_date_max: args.end_date_max.as_deref(),
            tag_id: args.tag_id.as_deref(),
            related_tags: args.related_tags,
            cyom: args.cyom,
            uma_resolution_status: args.uma_resolution_status.as_deref(),
            game_id: args.game_id.as_deref(),
            sports_market_types: args.sports_market_types.clone(),
            rewards_min_size: args.rewards_min_size,
            question_ids: args.question_ids.clone(),
            include_tag: args.include_tag,
            closed: args.closed,
        }
    }
}

#[derive(Args, Debug, Clone)]
pub struct GetSeriesArgs {
    /// Limit results (1-1000)
    #[arg(short, long)]
    pub limit: Option<u32>,
    /// Offset for pagination (>= 0)
    #[arg(short, long)]
    pub offset: Option<u32>,
    /// Order expression (per Gamma API)
    #[arg(long)]
    pub order: Option<String>,
    /// Sort ascending
    #[arg(long)]
    pub ascending: Option<bool>,
    /// Filter by slug
    #[arg(short, long)]
    pub slug: Option<String>,
    /// Filter by category IDs (repeatable)
    #[arg(long)]
    pub categories_ids: Option<Vec<String>>,
    /// Filter by category labels (repeatable)
    #[arg(long)]
    pub categories_labels: Option<Vec<String>>,
    /// Filter by closed status
    #[arg(long)]
    pub closed: Option<bool>,
    /// Include chat channel metadata
    #[arg(long)]
    pub include_chat: Option<bool>,
    /// Filter by recurrence
    #[arg(long)]
    pub recurrence: Option<String>,
}

impl<'a> From<&'a GetSeriesArgs> for GetSeriesRequest<'a> {
    fn from(args: &'a GetSeriesArgs) -> Self {
        GetSeriesRequest {
            limit: args.limit,
            offset: args.offset,
            order: args.order.as_deref(),
            ascending: args.ascending,
            slug: args.slug.as_deref(),
            categories_ids: args.categories_ids.clone(),
            categories_labels: args.categories_labels.clone(),
            closed: args.closed,
            include_chat: args.include_chat,
            recurrence: args.recurrence.as_deref(),
        }
    }
}

#[derive(Args, Debug, Clone)]
pub struct GetCommentsArgs {
    /// Parent entity type (Event, Series, market)
    #[arg(long, value_parser = ["Event", "Series", "market"])]
    pub parent_entity_type: String,
    /// Parent entity ID
    #[arg(long)]
    pub parent_entity_id: String,
    /// Limit results (1-1000)
    #[arg(short, long)]
    pub limit: Option<u32>,
    /// Offset for pagination (>= 0)
    #[arg(short, long)]
    pub offset: Option<u32>,
    /// Order expression
    #[arg(long)]
    pub order: Option<String>,
    /// Sort ascending
    #[arg(long)]
    pub ascending: Option<bool>,
    /// Include position data for commenters
    #[arg(long)]
    pub get_positions: Option<bool>,
    /// Restrict results to holders only
    #[arg(long)]
    pub holders_only: Option<bool>,
}

impl<'a> From<&'a GetCommentsArgs> for GetCommentsRequest<'a> {
    fn from(args: &'a GetCommentsArgs) -> Self {
        GetCommentsRequest {
            limit: args.limit,
            offset: args.offset,
            order: args.order.as_deref(),
            ascending: args.ascending,
            parent_entity_type: Some(args.parent_entity_type.as_str()),
            parent_entity_id: Some(args.parent_entity_id.as_str()),
            get_positions: args.get_positions,
            holders_only: args.holders_only,
        }
    }
}

#[derive(Args, Debug, Clone)]
pub struct SearchArgs {
    /// Query string
    pub query: String,
    /// Use cached results when available
    #[arg(long)]
    pub cache: Option<bool>,
    /// Filter by event status
    #[arg(long)]
    pub events_status: Option<String>,
    /// Limit per result type (1-1000)
    #[arg(long)]
    pub limit_per_type: Option<u32>,
    /// Page number (>= 1)
    #[arg(long)]
    pub page: Option<u32>,
    /// Filter by event tags (repeatable)
    #[arg(long)]
    pub events_tag: Option<Vec<String>>,
    /// Include closed markets in results
    #[arg(long)]
    pub keep_closed_markets: Option<u32>,
    /// Sort expression
    #[arg(long)]
    pub sort: Option<String>,
    /// Sort ascending
    #[arg(long)]
    pub ascending: Option<bool>,
    /// Search tags
    #[arg(long)]
    pub search_tags: Option<bool>,
    /// Search profiles
    #[arg(long)]
    pub search_profiles: Option<bool>,
    /// Filter by recurrence
    #[arg(long)]
    pub recurrence: Option<String>,
    /// Exclude tag IDs (repeatable)
    #[arg(long)]
    pub exclude_tag_id: Option<Vec<String>>,
    /// Enable optimized search
    #[arg(long)]
    pub optimized: Option<bool>,
}

impl<'a> From<&'a SearchArgs> for SearchRequest<'a> {
    fn from(args: &'a SearchArgs) -> Self {
        SearchRequest {
            q: args.query.as_str(),
            cache: args.cache,
            events_status: args.events_status.as_deref(),
            limit_per_type: args.limit_per_type,
            page: args.page,
            events_tag: args.events_tag.clone(),
            keep_closed_markets: args.keep_closed_markets,
            sort: args.sort.as_deref(),
            ascending: args.ascending,
            search_tags: args.search_tags,
            search_profiles: args.search_profiles,
            recurrence: args.recurrence.as_deref(),
            exclude_tag_id: args.exclude_tag_id.clone(),
            optimized: args.optimized,
        }
    }
}