Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/commands/events.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use anyhow::Result;
use chrono::{DateTime, Utc};
use clap::{Args, Subcommand};
use polymarket_client_sdk::gamma::{
self,
types::request::{EventByIdRequest, EventBySlugRequest, EventTagsRequest, EventsRequest},
};
use rust_decimal::Decimal;

use super::is_numeric_id;
use crate::output::OutputFormat;
Expand Down Expand Up @@ -47,6 +49,38 @@ pub enum EventsCommand {
/// Filter by tag slug (e.g. "politics", "crypto")
#[arg(long)]
tag: Option<String>,

/// Minimum trading volume (e.g. 1000000)
#[arg(long)]
volume_min: Option<Decimal>,

/// Maximum trading volume
#[arg(long)]
volume_max: Option<Decimal>,

/// Minimum liquidity
#[arg(long)]
liquidity_min: Option<Decimal>,

/// Maximum liquidity
#[arg(long)]
liquidity_max: Option<Decimal>,

/// Only events starting after this date (e.g. 2026-03-01T00:00:00Z)
#[arg(long)]
start_date_min: Option<DateTime<Utc>>,

/// Only events starting before this date
#[arg(long)]
start_date_max: Option<DateTime<Utc>>,

/// Only events ending after this date
#[arg(long)]
end_date_min: Option<DateTime<Utc>>,

/// Only events ending before this date
#[arg(long)]
end_date_max: Option<DateTime<Utc>>,
},

/// Get a single event by ID or slug
Expand All @@ -72,6 +106,14 @@ pub async fn execute(client: &gamma::Client, args: EventsArgs, output: OutputFor
order,
ascending,
tag,
volume_min,
volume_max,
liquidity_min,
liquidity_max,
start_date_min,
start_date_max,
end_date_min,
end_date_max,
} => {
let resolved_closed = closed.or_else(|| active.map(|a| !a));

Expand All @@ -83,6 +125,14 @@ pub async fn execute(client: &gamma::Client, args: EventsArgs, output: OutputFor
.maybe_tag_slug(tag)
// EventsRequest::order is Vec<String>; into_iter on Option yields 0 or 1 items.
.order(order.into_iter().collect())
.maybe_volume_min(volume_min)
.maybe_volume_max(volume_max)
.maybe_liquidity_min(liquidity_min)
.maybe_liquidity_max(liquidity_max)
.maybe_start_date_min(start_date_min)
.maybe_start_date_max(start_date_max)
.maybe_end_date_min(end_date_min)
.maybe_end_date_max(end_date_max)
.build();

let events = client.events(&request).await?;
Expand Down
56 changes: 56 additions & 0 deletions src/commands/markets.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use chrono::{DateTime, Utc};
use clap::{Args, Subcommand};
use polymarket_client_sdk::gamma::{
self,
Expand All @@ -10,6 +11,7 @@ use polymarket_client_sdk::gamma::{
response::Market,
},
};
use rust_decimal::Decimal;

use super::is_numeric_id;
use crate::output::OutputFormat;
Expand Down Expand Up @@ -49,6 +51,42 @@ pub enum MarketsCommand {
/// Sort ascending instead of descending
#[arg(long)]
ascending: bool,

/// Minimum trading volume (e.g. 1000000)
#[arg(long)]
volume_min: Option<Decimal>,

/// Maximum trading volume
#[arg(long)]
volume_max: Option<Decimal>,

/// Minimum liquidity
#[arg(long)]
liquidity_min: Option<Decimal>,

/// Maximum liquidity
#[arg(long)]
liquidity_max: Option<Decimal>,

/// Only markets starting after this date (e.g. 2026-03-01T00:00:00Z)
#[arg(long)]
start_date_min: Option<DateTime<Utc>>,

/// Only markets starting before this date
#[arg(long)]
start_date_max: Option<DateTime<Utc>>,

/// Only markets ending after this date
#[arg(long)]
end_date_min: Option<DateTime<Utc>>,

/// Only markets ending before this date
#[arg(long)]
end_date_max: Option<DateTime<Utc>>,

/// Filter by tag ID
#[arg(long)]
tag: Option<String>,
},

/// Get a single market by ID or slug
Expand Down Expand Up @@ -87,6 +125,15 @@ pub async fn execute(
offset,
order,
ascending,
volume_min,
volume_max,
liquidity_min,
liquidity_max,
start_date_min,
start_date_max,
end_date_min,
end_date_max,
tag,
} => {
let resolved_closed = closed.or_else(|| active.map(|a| !a));

Expand All @@ -96,6 +143,15 @@ pub async fn execute(
.maybe_offset(offset)
.maybe_order(order)
.ascending(ascending)
.maybe_volume_num_min(volume_min)
.maybe_volume_num_max(volume_max)
.maybe_liquidity_num_min(liquidity_min)
.maybe_liquidity_num_max(liquidity_max)
.maybe_start_date_min(start_date_min)
.maybe_start_date_max(start_date_max)
.maybe_end_date_min(end_date_min)
.maybe_end_date_max(end_date_max)
.maybe_tag_id(tag)
.build();

let markets = client.markets(&request).await?;
Expand Down