betex 0.35.0

Betfair / Prediction Market Exchange
Documentation
use clap::{Parser, ValueEnum};

#[derive(Debug, Clone, Copy, ValueEnum)]
pub(crate) enum WaitStrategyOpt {
    #[value(name = "busy-spin")]
    BusySpin,
    #[value(name = "blocking-wait")]
    BlockingWait,
}

#[derive(Debug, Clone, Parser)]
#[command(name = "live", about = "Live market simulation server")]
pub(crate) struct Cli {
    /// Disruptor ring size (must be a power of 2).
    #[arg(
        long = "ring-size",
        default_value_t = 8192 * 4,
        value_parser = parse_pow2_usize
    )]
    pub(crate) ring_size_pow2: usize,

    /// Enforce BinaryYes price ticks denominator (ticks per $1.00 payout).
    ///
    /// Example: 100 enforces $0.01 per tick.
    #[arg(long, default_value_t = 100)]
    pub(crate) binary_yes_max_price_ticks: u16,

    /// Disruptor wait strategy.
    #[arg(long, value_enum, default_value_t = WaitStrategyOpt::BusySpin)]
    pub(crate) wait_strategy: WaitStrategyOpt,
}

pub(crate) fn parse_pow2_usize(s: &str) -> Result<usize, String> {
    let v: usize = s
        .parse()
        .map_err(|_| format!("invalid integer for --ring-size: {s}"))?;
    if v == 0 || (v & (v - 1)) != 0 {
        return Err(format!(
            "--ring-size must be a power of 2 (e.g. 32768); got {v}"
        ));
    }
    Ok(v)
}