Skip to main content

Module types

Module types 

Source
Expand description

Value types for the trading domain model.

This module provides immutable value types that represent fundamental trading concepts: Price, Quantity, and Money. These types use fixed-point arithmetic internally for deterministic calculations while providing a natural numeric interface.

§Immutability

All value types are immutable - once constructed, their values cannot change. Arithmetic operations return new instances rather than modifying existing ones. This design ensures thread safety and predictable behavior in concurrent trading systems.

§Arithmetic operations

Value types implement Rust’s standard arithmetic traits (Add, Sub, Mul) for same-type operations. When operating on two values of the same type, the result preserves that type.

OperationResultNotes
Quantity + QuantityQuantityPrecision is max of both operands.
Quantity - QuantityQuantityPanics if result would be negative.
Price + PricePricePrecision is max of both operands.
Price - PricePricePrecision is max of both operands.
Money + MoneyMoneyPanics if currencies don’t match.
Money - MoneyMoneyPanics if currencies don’t match.

For Python bindings with mixed-type operations (e.g., Quantity + int), see the Python API documentation.

§Precision

Each value type stores a precision field indicating the number of decimal places. The maximum precision is defined by fixed::FIXED_PRECISION. When performing arithmetic between values with different precisions, the result uses the maximum precision of the operands.

§Constraints

  • Quantity: Non-negative values only. Subtracting a larger quantity from a smaller one raises an error rather than producing a negative result.
  • Price: Signed values allowed (can represent negative prices for spreads, etc.).
  • Money: Signed values allowed. Operations between different currencies raise an error.

Re-exports§

pub use balance::AccountBalance;
pub use balance::MarginBalance;
pub use currency::Currency;
pub use money::MONEY_MAX;
pub use money::MONEY_MIN;
pub use money::Money;
pub use price::ERROR_PRICE;
pub use price::PRICE_ERROR;
pub use price::PRICE_MAX;
pub use price::PRICE_MIN;
pub use price::PRICE_RAW_MAX;
pub use price::PRICE_RAW_MIN;
pub use price::PRICE_UNDEF;
pub use price::Price;
pub use quantity::QUANTITY_MAX;
pub use quantity::QUANTITY_MIN;
pub use quantity::QUANTITY_UNDEF;
pub use quantity::Quantity;

Modules§

balance
Represents an account balance denominated in a particular currency.
currency
Represents a medium of exchange in a specified denomination with a fixed decimal precision.
fixed
Functions for handling fixed-point arithmetic.
money
Represents an amount of money in a specified currency denomination.
price
Represents a price in a market with a specified precision.
quantity
Represents a quantity with a non-negative value and specified precision.
stubs