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.
| Operation | Result | Notes |
|---|---|---|
Price + Price | Price | Precision is max of both operands. |
Price - Price | Price | Precision is max of both operands. |
Price + Decimal | Decimal | |
Price - Decimal | Decimal | |
Price * Decimal | Decimal | |
Price / Decimal | Decimal | |
Price + f64 | f64 | |
Price - f64 | f64 | |
Price * f64 | f64 | |
Price / f64 | f64 | |
-Price | Price |
§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
Pricerepresenting an error, returned by C FFI functions that cannot signal errors throughOptionorResult. - 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
valueis positive. - decode_
raw_ price_ i64 - The raw i64 price has already been scaled by 10^9. Further scale it by the difference to
FIXED_PRECISIONto make it high/defi-precision raw price.