Repository: nautechsystems/nautilus_trader
File: crates/model/src/instruments/mod.rs (Rust)

Code before:
pub fn validate_instrument_common(
    price_precision: u8,
    size_precision: u8,
    size_increment: Quantity,
    multiplier: Quantity,
    margin_init: Decimal,
    margin_maint: Decimal,
    price_increment: Option<Price>,
    lot_size: Option<Quantity>,
    max_quantity: Option<Quantity>,
    min_quantity: Option<Quantity>,
    _max_notional: Option<Money>, // TODO: Needs `check_positive_money`
    _min_notional: Option<Money>, // TODO: Needs `check_positive_money`
    max_price: Option<Price>,
    min_price: Option<Price>,
) -> anyhow::Result<()> {
    check_positive_quantity(size_increment, "size_increment")?;
    check_equal_u8(
        size_increment.precision,
        size_precision,
        "size_increment.precision",
        "size_precision",
    )?;
    check_positive_quantity(multiplier, "multiplier")?;
    check_positive_decimal(margin_init, "margin_init")?;
    check_predicate_true(margin_init >= dec!(0), "margin_init negative")?;
    check_predicate_true(margin_maint >= dec!(0), "margin_maint negative")?;

    if let Some(price_increment) = price_increment {
        check_positive_price(price_increment, "price_increment")?;
        check_equal_u8(
            price_increment.precision,
            price_precision,
            "price_increment.precision",
            "price_precision",
        )?;
    }

    if let Some(lot) = lot_size {
        check_positive_quantity(lot, "lot_size")?;
    }

    if let Some(quantity) = max_quantity {
        check_positive_quantity(quantity, "max_quantity")?;
    }

    if let Some(quantity) = min_quantity {
        check_positive_quantity(quantity, "max_quantity")?;
    }

    // TODO: check_positive_money

Review comment (suggestion):
We could use `check_positive_decimal` for both of these now rather than the general `check_predicate_true`.

Code after:
pub fn validate_instrument_common(
    price_precision: u8,
    size_precision: u8,
    size_increment: Quantity,
    multiplier: Quantity,
    margin_init: Decimal,
    margin_maint: Decimal,
    price_increment: Option<Price>,
    lot_size: Option<Quantity>,
    max_quantity: Option<Quantity>,
    min_quantity: Option<Quantity>,
    _max_notional: Option<Money>, // TODO: Needs `check_positive_money`
    _min_notional: Option<Money>, // TODO: Needs `check_positive_money`
    max_price: Option<Price>,
    min_price: Option<Price>,
) -> anyhow::Result<()> {
    check_positive_quantity(size_increment, "size_increment")?;
    check_equal_u8(
        size_increment.precision,
        size_precision,
        "size_increment.precision",
        "size_precision",
    )?;
    check_positive_quantity(multiplier, "multiplier")?;
    check_positive_decimal(margin_init, "margin_init")?;
    check_positive_decimal(margin_maint, "margin_maint")?;

    if let Some(price_increment) = price_increment {
        check_positive_price(price_increment, "price_increment")?;
        check_equal_u8(
            price_increment.precision,
            price_precision,
            "price_increment.precision",
            "price_precision",
        )?;
    }

    if let Some(lot) = lot_size {
        check_positive_quantity(lot, "lot_size")?;
    }

    if let Some(quantity) = max_quantity {
        check_positive_quantity(quantity, "max_quantity")?;
    }

    if let Some(quantity) = min_quantity {
        check_positive_quantity(quantity, "max_quantity")?;
    }

    // TODO: check_positive_money
    // if let Some(notional) = max_notional {