polyoxide-gamma 0.12.2

Rust client library for Polymarket Gamma (market data) API
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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
//! Live integration tests against the Polymarket Gamma API.
//!
//! These tests hit the real API and require network access.
//! They are gated behind `#[ignore]` so they don't run in CI.
//!
//! Run manually with:
//! ```sh
//! cargo test -p polyoxide-gamma --test live_api -- --ignored
//! ```

use polyoxide_gamma::Gamma;
use std::time::Duration;

fn client() -> Gamma {
    Gamma::builder().build().expect("gamma client")
}

// ── Health ───────────────────────────────────────────────────────

#[tokio::test]
#[ignore]
async fn live_ping() {
    let gamma = client();
    let latency = gamma.health().ping().await.expect("ping should succeed");
    assert!(
        latency < Duration::from_secs(10),
        "latency too high: {latency:?}"
    );
}

// ── Markets ──────────────────────────────────────────────────────

#[tokio::test]
#[ignore]
async fn live_list_markets() {
    let gamma = client();
    let markets = gamma
        .markets()
        .list()
        .limit(5)
        .send()
        .await
        .expect("list markets");
    assert!(!markets.is_empty(), "should return at least one market");
}

#[tokio::test]
#[ignore]
async fn live_get_market_by_id() {
    let gamma = client();
    let markets = gamma
        .markets()
        .list()
        .limit(1)
        .send()
        .await
        .expect("list markets to discover id");
    let first = markets.first().expect("need at least one market");
    let id = first.id.clone();

    let market = gamma
        .markets()
        .get(&id)
        .send()
        .await
        .expect("get market by id");
    assert_eq!(market.id, id);
}

#[tokio::test]
#[ignore]
async fn live_get_market_by_slug() {
    let gamma = client();
    let markets = gamma
        .markets()
        .list()
        .limit(10)
        .send()
        .await
        .expect("list markets to discover slug");
    let market_with_slug = markets
        .iter()
        .find(|m| m.slug.is_some())
        .expect("need at least one market with a slug");
    let slug = market_with_slug.slug.as_ref().unwrap().clone();

    let market = gamma
        .markets()
        .get_by_slug(&slug)
        .send()
        .await
        .expect("get market by slug");
    assert_eq!(market.slug.as_deref(), Some(slug.as_str()));
}

#[tokio::test]
#[ignore]
async fn live_list_markets_closed_true() {
    let gamma = client();
    let markets = gamma
        .markets()
        .list()
        .closed(true)
        .limit(5)
        .send()
        .await
        .expect("list closed markets");
    assert!(
        !markets.is_empty(),
        "should return at least one closed market"
    );
    for m in &markets {
        assert_eq!(m.closed, Some(true), "market {} should be closed", m.id);
    }
}

#[tokio::test]
#[ignore]
async fn live_list_markets_closed_false() {
    let gamma = client();
    let markets = gamma
        .markets()
        .list()
        .closed(false)
        .limit(5)
        .send()
        .await
        .expect("list open markets");
    assert!(
        !markets.is_empty(),
        "should return at least one open market"
    );
    for m in &markets {
        assert_ne!(m.closed, Some(true), "market {} should not be closed", m.id);
    }
}

// ── Events ──────────────────────────────────────────────────────

#[tokio::test]
#[ignore]
async fn live_list_events() {
    let gamma = client();
    let events = gamma
        .events()
        .list()
        .limit(5)
        .send()
        .await
        .expect("list events");
    assert!(!events.is_empty(), "should return at least one event");
}

#[tokio::test]
#[ignore]
async fn live_get_event_by_id() {
    let gamma = client();
    let events = gamma
        .events()
        .list()
        .limit(1)
        .send()
        .await
        .expect("list events to discover id");
    let first = events.first().expect("need at least one event");
    let id = first.id.clone();

    let event = gamma
        .events()
        .get(&id)
        .send()
        .await
        .expect("get event by id");
    assert_eq!(event.id, id);
}

#[tokio::test]
#[ignore]
async fn live_get_event_by_slug() {
    let gamma = client();
    let events = gamma
        .events()
        .list()
        .limit(10)
        .send()
        .await
        .expect("list events to discover slug");
    let event_with_slug = events
        .iter()
        .find(|e| e.slug.is_some())
        .expect("need at least one event with a slug");
    let slug = event_with_slug.slug.as_ref().unwrap().clone();

    let event = gamma
        .events()
        .get_by_slug(&slug)
        .send()
        .await
        .expect("get event by slug");
    assert_eq!(event.slug.as_deref(), Some(slug.as_str()));
}

// ── Tags ────────────────────────────────────────────────────────

#[tokio::test]
#[ignore]
async fn live_list_tags() {
    let gamma = client();
    let tags = gamma
        .tags()
        .list()
        .limit(5)
        .send()
        .await
        .expect("list tags");
    assert!(!tags.is_empty(), "should return at least one tag");
}

#[tokio::test]
#[ignore]
async fn live_get_tag_by_id() {
    let gamma = client();
    let tags = gamma
        .tags()
        .list()
        .limit(1)
        .send()
        .await
        .expect("list tags to discover id");
    let first = tags.first().expect("need at least one tag");
    let id = first.id.clone();

    let tag = gamma.tags().get(&id).send().await.expect("get tag by id");
    assert_eq!(tag.id, id);
}

#[tokio::test]
#[ignore]
async fn live_get_tag_by_slug() {
    let gamma = client();
    let tags = gamma
        .tags()
        .list()
        .limit(10)
        .send()
        .await
        .expect("list tags to discover slug");
    let first = tags.first().expect("need at least one tag");
    let slug = first.slug.clone();

    let tag = gamma
        .tags()
        .get_by_slug(&slug)
        .send()
        .await
        .expect("get tag by slug");
    assert_eq!(tag.slug, slug);
}

#[tokio::test]
#[ignore]
async fn live_get_related_tags() {
    let gamma = client();
    let tags = gamma
        .tags()
        .list()
        .limit(10)
        .send()
        .await
        .expect("list tags to discover id");
    let first = tags.first().expect("need at least one tag");
    let id = first.id.clone();

    // Related tags may be empty for some tags, but the call should succeed.
    let _related = gamma
        .tags()
        .get_related(&id)
        .send()
        .await
        .expect("get related tags");
}

// ── Series ──────────────────────────────────────────────────────

#[tokio::test]
#[ignore]
async fn live_list_series() {
    let gamma = client();
    let series = gamma
        .series()
        .list()
        .limit(5)
        .send()
        .await
        .expect("list series");
    assert!(!series.is_empty(), "should return at least one series");
}

#[tokio::test]
#[ignore]
async fn live_get_series_by_id() {
    let gamma = client();
    let series = gamma
        .series()
        .list()
        .limit(1)
        .send()
        .await
        .expect("list series to discover id");
    let first = series.first().expect("need at least one series");
    let id = first.id.clone();

    let s = gamma
        .series()
        .get(&id)
        .send()
        .await
        .expect("get series by id");
    assert_eq!(s.id, id);
}

// ── Sports ──────────────────────────────────────────────────────

#[tokio::test]
#[ignore]
async fn live_list_sports() {
    let gamma = client();
    let sports = gamma.sports().list().send().await.expect("list sports");
    assert!(
        !sports.is_empty(),
        "should return at least one sport metadata entry"
    );
}

#[tokio::test]
#[ignore]
async fn live_list_teams() {
    let gamma = client();
    let teams = gamma
        .sports()
        .list_teams()
        .limit(5)
        .send()
        .await
        .expect("list teams");
    assert!(!teams.is_empty(), "should return at least one team");
}

// ── Comments ────────────────────────────────────────────────────

#[tokio::test]
#[ignore]
async fn live_list_comments() {
    let gamma = client();

    // The comments endpoint requires parent_entity_type and parent_entity_id.
    // Discover an event ID first.
    let events = gamma
        .events()
        .list()
        .limit(5)
        .send()
        .await
        .expect("list events to discover id for comments");
    let first = events.first().expect("need at least one event");
    let event_id: i64 = first.id.parse().expect("event id should be numeric");

    let comments = gamma
        .comments()
        .list()
        .parent_entity_type("Event")
        .parent_entity_id(event_id)
        .limit(5)
        .send()
        .await
        .expect("list comments");
    // Some events may have no comments, but deserialization must succeed.
    let _ = comments;
}

// ── Comments: get and by_user ───────────────────────────────────

#[tokio::test]
#[ignore]
async fn live_get_comment_by_id() {
    let gamma = client();

    // Discover a comment ID from listing
    let events = gamma
        .events()
        .list()
        .active(true)
        .limit(5)
        .send()
        .await
        .expect("list events");
    let first = events.first().expect("need at least one event");
    let event_id: i64 = first.id.parse().expect("event id should be numeric");

    let comments = gamma
        .comments()
        .list()
        .parent_entity_type("Event")
        .parent_entity_id(event_id)
        .limit(1)
        .send()
        .await
        .expect("list comments");

    if let Some(comment) = comments.first() {
        let fetched = gamma
            .comments()
            .get(&comment.id)
            .send()
            .await
            .expect("get comment by id");
        assert_eq!(fetched.id, comment.id);
    }
}

// ── Events: related by ID, tags, counts ────────────────────────

#[tokio::test]
#[ignore]
async fn live_event_tags() {
    let gamma = client();
    let events = gamma
        .events()
        .list()
        .limit(1)
        .send()
        .await
        .expect("list events");
    let first = events.first().expect("need at least one event");

    let _tags = gamma
        .events()
        .tags(&first.id)
        .send()
        .await
        .expect("get event tags");
}

// ── Markets: tags ──────────────────────────────────────────────

#[tokio::test]
#[ignore]
async fn live_market_tags() {
    let gamma = client();
    let markets = gamma
        .markets()
        .list()
        .limit(1)
        .send()
        .await
        .expect("list markets");
    let first = markets.first().expect("need at least one market");

    let _tags = gamma
        .markets()
        .tags(&first.id)
        .send()
        .await
        .expect("get market tags");
}

// ── Sports: market types ───────────────────────────────────────

#[tokio::test]
#[ignore]
async fn live_sports_market_types() {
    let gamma = client();
    let _types = gamma
        .sports()
        .market_types()
        .send()
        .await
        .expect("sports market types should deserialize");
}

// ── Search ──────────────────────────────────────────────────────

#[tokio::test]
#[ignore]
async fn live_public_search() {
    let gamma = client();
    let results = gamma
        .search()
        .public_search("bitcoin")
        .search_profiles(true)
        .limit_per_type(5)
        .send()
        .await
        .expect("public search");
    // Search may return empty results for some queries,
    // but deserialization must succeed.
    let _ = results;
}

// ── User ────────────────────────────────────────────────────────

#[tokio::test]
#[ignore]
async fn live_get_user() {
    let gamma = client();

    // Discover a real user address from comments.
    let events = gamma
        .events()
        .list()
        .active(true)
        .limit(5)
        .send()
        .await
        .expect("list events");
    let first = events.first().expect("need at least one event");
    let event_id: i64 = first.id.parse().expect("event id should be numeric");

    let comments = gamma
        .comments()
        .list()
        .parent_entity_type("Event")
        .parent_entity_id(event_id)
        .limit(20)
        .send()
        .await
        .expect("list comments to find a user");

    if let Some(comment) = comments.first() {
        let user_id = &comment.user.id;
        let user = gamma
            .user()
            .get(user_id)
            .send()
            .await
            .expect("get user profile");
        // Deserialization succeeded; the profile may have sparse fields.
        let _ = user;
    }
    // If no comments found, skip silently -- the endpoint itself is
    // exercised in the request path even when no suitable address exists.
}