Expand description
Represents a quantity with a non-negative value and specified precision.
Quantity is an immutable value type for representing trade sizes, order quantities,
and position amounts. It enforces non-negative values and provides fixed-point arithmetic
for deterministic calculations.
§Arithmetic behavior
| Operation | Result | Notes |
|---|---|---|
Quantity + Quantity | Quantity | Precision is max of both operands. |
Quantity - Quantity | Quantity | Panics if result would be negative. |
Quantity * Quantity | Quantity | Scales back by FIXED_SCALAR. |
Quantity + Decimal | Decimal | |
Quantity - Decimal | Decimal | |
Quantity * Decimal | Decimal | |
Quantity / Decimal | Decimal | |
Quantity + f64 | f64 | |
Quantity - f64 | f64 | |
Quantity * f64 | f64 | |
Quantity / f64 | f64 |
§Immutability
Quantity is immutable. All arithmetic operations return new instances.
Structs§
- Quantity
- Represents a quantity with a non-negative value and specified precision.
Constants§
- QUANTITY_
MAX - The maximum valid quantity value that can be represented.
- QUANTITY_
MIN - The minimum valid quantity value that can be represented.
- QUANTITY_
UNDEF - The sentinel value for an unset or null quantity.
Statics§
- QUANTITY_
RAW_ MAX - The maximum raw quantity integer value.
Functions§
- check_
positive_ quantity - Checks if the quantity
valueis positive.