-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathseries.rs
More file actions
79 lines (66 loc) · 1.88 KB
/
series.rs
File metadata and controls
79 lines (66 loc) · 1.88 KB
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
use anyhow::Result;
use clap::{Args, Subcommand};
use polymarket_client_sdk::gamma::{
self,
types::request::{SeriesByIdRequest, SeriesListRequest},
};
use crate::output::OutputFormat;
use crate::output::series::{print_series, print_series_item};
#[derive(Args)]
pub struct SeriesArgs {
#[command(subcommand)]
pub command: SeriesCommand,
}
#[derive(Subcommand)]
pub enum SeriesCommand {
/// List series
List {
/// Max results
#[arg(long, default_value = "25")]
limit: i32,
/// Pagination offset
#[arg(long)]
offset: Option<i32>,
/// Sort field (e.g. volume, liquidity)
#[arg(long)]
order: Option<String>,
/// Sort ascending instead of descending
#[arg(long)]
ascending: bool,
/// Filter by closed status
#[arg(long)]
closed: Option<bool>,
},
/// Get a single series by ID
Get {
/// Series ID
id: String,
},
}
pub async fn execute(client: &gamma::Client, args: SeriesArgs, output: OutputFormat) -> Result<()> {
match args.command {
SeriesCommand::List {
limit,
offset,
order,
ascending,
closed,
} => {
let request = SeriesListRequest::builder()
.limit(limit)
.maybe_offset(offset)
.maybe_order(order)
.maybe_ascending(if ascending { Some(true) } else { None })
.maybe_closed(closed)
.build();
let series = client.series(&request).await?;
print_series(&series, &output)?;
}
SeriesCommand::Get { id } => {
let req = SeriesByIdRequest::builder().id(id).build();
let series = client.series_by_id(&req).await?;
print_series_item(&series, &output)?;
}
}
Ok(())
}