Skip to main content

Module quantity

Module quantity 

Source
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

OperationResultNotes
Quantity + QuantityQuantityPrecision is max of both operands.
Quantity - QuantityQuantityPanics if result would be negative.
Quantity * QuantityQuantityScales back by FIXED_SCALAR.
Quantity + DecimalDecimal
Quantity - DecimalDecimal
Quantity * DecimalDecimal
Quantity / DecimalDecimal
Quantity + f64f64
Quantity - f64f64
Quantity * f64f64
Quantity / f64f64

§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 value is positive.

Type Aliases§

QuantityRaw