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
14 changes: 11 additions & 3 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ enum Commands {
/// Minimum probability threshold (e.g., 0.99 for 99%)
#[arg(long, default_value = "0.95")]
min_prob: f64,
/// Maximum probability threshold (e.g., 0.99 for 99%)
#[arg(long, default_value = "1.0")]
max_prob: f64,
/// Maximum number of markets to fetch
#[arg(long, default_value = "500")]
limit: usize,
Expand Down Expand Up @@ -480,10 +483,11 @@ async fn main() -> Result<()> {
}) => run_trending(order_by, ascending, limit).await,
Some(Commands::Yield {
min_prob,
max_prob,
limit,
min_volume,
expires_in,
}) => run_yield(min_prob, limit, min_volume, expires_in).await,
}) => run_yield(min_prob, max_prob, limit, min_volume, expires_in).await,
}
}

Expand Down Expand Up @@ -775,6 +779,7 @@ fn parse_duration(s: &str) -> Option<i64> {

async fn run_yield(
min_prob: f64,
max_prob: f64,
limit: usize,
min_volume: f64,
expires_in: Option<String>,
Expand All @@ -791,8 +796,9 @@ async fn run_yield(
}

log_info!(
"🔍 Searching for markets with outcomes >= {:.1}% probability{}...",
"🔍 Searching for markets with outcomes {:.1}%-{:.1}% probability{}...",
min_prob * 100.0,
max_prob * 100.0,
expires_in
.as_ref()
.map(|s| format!(" expiring within {}", s))
Expand Down Expand Up @@ -862,6 +868,7 @@ async fn run_yield(
for (i, price_str) in market.outcome_prices.iter().enumerate() {
if let Ok(price) = price_str.parse::<f64>()
&& price >= min_prob
&& price <= max_prob
{
let outcome = market
.outcomes
Expand Down Expand Up @@ -899,8 +906,9 @@ async fn run_yield(

if opportunities.is_empty() {
log_info!(
"No markets found with outcomes >= {:.1}% and volume >= ${:.0}",
"No markets found with outcomes {:.1}%-{:.1}% probability and volume >= ${:.0}",
min_prob * 100.0,
max_prob * 100.0,
min_volume
);
return Ok(());
Expand Down
20 changes: 12 additions & 8 deletions crates/cli/src/trending_tui/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ pub async fn fetch_market_prices_batch(
/// Fetch yield opportunities from the Gamma API
pub async fn fetch_yield_opportunities(
min_prob: f64,
max_prob: f64,
limit: usize,
min_volume: f64,
) -> Vec<YieldOpportunity> {
Expand Down Expand Up @@ -710,8 +711,7 @@ pub async fn fetch_yield_opportunities(
for (i, price_str) in market.outcome_prices.iter().enumerate() {
if let Ok(price) = price_str.parse::<f64>()
&& price >= min_prob
&& price < 1.0
// Skip 100% price (no yield)
&& price <= max_prob
{
let outcome = market
.outcomes
Expand Down Expand Up @@ -754,19 +754,23 @@ pub async fn fetch_yield_opportunities(
pub fn spawn_yield_fetch(app_state: Arc<TokioMutex<TrendingAppState>>) {
let app_state_clone = Arc::clone(&app_state);
tokio::spawn(async move {
let (min_prob, min_volume) = {
let (min_prob, min_volume, max_prob) = {
let mut app = app_state.lock().await;
app.yield_state.is_loading = true;
(app.yield_state.min_prob, app.yield_state.min_volume)
(
app.yield_state.min_prob,
app.yield_state.min_volume,
app.yield_state.max_prob,
)
};

log_info!(
"Fetching yield opportunities (min_prob: {:.0}%)...",
min_prob * 100.0
"Fetching yield opportunities (prob: {:.1}%-{:.1}%)...",
min_prob * 100.0,
max_prob * 100.0
);

let opportunities = fetch_yield_opportunities(min_prob, 500, min_volume).await;

let opportunities = fetch_yield_opportunities(min_prob, max_prob, 500, min_volume).await;
let slug_to_fetch = {
let mut app = app_state.lock().await;
app.yield_state.opportunities = opportunities;
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/src/trending_tui/state/yield_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct YieldState {
pub scroll: usize,
pub is_loading: bool,
pub min_prob: f64,
pub max_prob: f64,
pub min_volume: f64,
pub sort_by: YieldSortBy,
pub filter_query: String, // Current filter query
Expand Down Expand Up @@ -81,6 +82,7 @@ impl YieldState {
scroll: 0,
is_loading: false,
min_prob: 0.95,
max_prob: 1.0,
min_volume: 0.0,
sort_by: YieldSortBy::Return,
filter_query: String::new(),
Expand Down