Skip to main content

Module price

Module price 

Source
Expand description

Represents a price in a market with a specified precision.

Price is an immutable value type for representing market prices, bid/ask quotes, and price levels. Unlike Quantity, prices can be negative (useful for spreads, basis trades, or certain derivative instruments).

§Arithmetic behavior

Adding or subtracting two Price values requires matching effective fixed-point scales. These operations panic on a scale mismatch. Comparisons and hashes account for scale differences without rounding. Without the defi feature, constructors restrict values to a single storage scale.

OperationResultNotes
Price + PricePricePrecision is max of both operands.
Price - PricePricePrecision is max of both operands.
Price + DecimalDecimal
Price - DecimalDecimal
Price * DecimalDecimal
Price / DecimalDecimal
Price + f64f64
Price - f64f64
Price * f64f64
Price / f64f64
-PricePrice

§Immutability

Price is immutable. All arithmetic operations return new instances.

Structs§

Price
Represents a price in a market with a specified precision.

Constants§

ERROR_PRICE
The sentinel Price representing an error, returned by C FFI functions that cannot signal errors through Option or Result.
PRICE_ERROR
The sentinel value for an error or invalid price.
PRICE_MAX
The maximum valid price value that can be represented.
PRICE_MIN
The minimum valid price value that can be represented.
PRICE_UNDEF
The sentinel value for an unset or null price.

Statics§

PRICE_RAW_MAX
The maximum raw price integer value.
PRICE_RAW_MIN
The minimum raw price integer value.

Functions§

check_positive_price
Checks the price value is positive.
decode_raw_price_i64
The raw i64 price has already been scaled by 10^9. Further scale it by the difference to FIXED_PRECISION to make it high/defi-precision raw price.

Type Aliases§

PriceRaw