#[repr(C)]pub struct Price {
pub raw: PriceRaw,
pub precision: u8,
}Expand description
Represents a price in a market with a specified precision.
The number of decimal places may vary. For certain asset classes, prices may have negative values. For example, prices for options instruments can be negative under certain conditions.
Handles up to FIXED_PRECISION decimals of precision.
Fields§
§raw: PriceRawRepresents the raw fixed-point value, with precision defining the number of decimal places.
precision: u8The number of decimal places, with a maximum of FIXED_PRECISION.
Implementations§
Source§impl Price
impl Price
Sourcepub fn new_checked(value: f64, precision: u8) -> Result<Self>
pub fn new_checked(value: f64, precision: u8) -> Result<Self>
Creates a new Price instance with correctness checking.
§Errors
Returns an error if:
valueis invalid outside the representable range [PRICE_MIN,PRICE_MAX].precisionis invalid outside the representable range [0, `FIXED_PRECISION``].
§Notes
PyO3 requires a Result type for proper error handling and stacktrace printing in Python.
Sourcepub fn new(value: f64, precision: u8) -> Self
pub fn new(value: f64, precision: u8) -> Self
Creates a new Price instance.
§Panics
Panics if a correctness check fails. See Price::new_checked for more details.
Sourcepub fn from_raw(raw: PriceRaw, precision: u8) -> Self
pub fn from_raw(raw: PriceRaw, precision: u8) -> Self
Creates a new Price instance from the given raw fixed-point value and precision.
§Panics
Panics if a correctness check fails. See Price::new_checked for more details.
Sourcepub fn zero(precision: u8) -> Self
pub fn zero(precision: u8) -> Self
Creates a new Price instance with a value of zero with the given precision.
§Panics
Panics if a correctness check fails. See Price::new_checked for more details.
Sourcepub fn max(precision: u8) -> Self
pub fn max(precision: u8) -> Self
Creates a new Price instance with the maximum representable value with the given precision.
§Panics
Panics if a correctness check fails. See Price::new_checked for more details.
Sourcepub fn min(precision: u8) -> Self
pub fn min(precision: u8) -> Self
Creates a new Price instance with the minimum representable value with the given precision.
§Panics
Panics if a correctness check fails. See Price::new_checked for more details.
Sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Returns true if the value of this instance is undefined.
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns true if the value of this instance is position (> 0).
Sourcepub fn as_f64(&self) -> f64
pub fn as_f64(&self) -> f64
Returns the value of this instance as an f64.
§Panics
Panics if precision is beyond MAX_FLOAT_PRECISION (16).
Sourcepub fn as_decimal(&self) -> Decimal
pub fn as_decimal(&self) -> Decimal
Returns the value of this instance as a Decimal.
Sourcepub fn to_formatted_string(&self) -> String
pub fn to_formatted_string(&self) -> String
Returns a formatted string representation of this instance.
Sourcepub fn from_decimal(decimal: Decimal, precision: u8) -> Result<Self>
pub fn from_decimal(decimal: Decimal, precision: u8) -> Result<Self>
Creates a new Price from a Decimal value with specified precision.
This method provides more reliable parsing by using Decimal arithmetic to avoid floating-point precision issues during conversion.
§Errors
Returns an error if:
precisionexceedsFIXED_PRECISION.- The decimal value cannot be converted to the raw representation.
- Overflow occurs during scaling.
Trait Implementations§
Source§impl AddAssign for Price
impl AddAssign for Price
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Price
impl<'de> Deserialize<'de> for Price
Source§fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<'py> IntoPyObject<'py> for Price
impl<'py> IntoPyObject<'py> for Price
Source§impl Ord for Price
impl Ord for Price
Source§impl PartialOrd for Price
impl PartialOrd for Price
Source§impl PyClassImpl for Price
impl PyClassImpl for Price
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// Represents a price in a market with a specified precision.
///
/// The number of decimal places may vary. For certain asset classes, prices may
/// have negative values. For example, prices for options instruments can be
/// negative under certain conditions.
///
/// Handles up to [`FIXED_PRECISION`] decimals of precision.
///
/// - [`PRICE_MAX`] - Maximum representable price value.
/// - [`PRICE_MIN`] - Minimum representable price value.
const RAW_DOC: &'static CStr = /// Represents a price in a market with a specified precision. /// /// The number of decimal places may vary. For certain asset classes, prices may /// have negative values. For example, prices for options instruments can be /// negative under certain conditions. /// /// Handles up to [`FIXED_PRECISION`] decimals of precision. /// /// - [`PRICE_MAX`] - Maximum representable price value. /// - [`PRICE_MIN`] - Minimum representable price value.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<Price>
type ThreadChecker = SendablePyClass<Price>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::ImmutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::ImmutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature for Price
impl PyClassNewTextSignature for Price
const TEXT_SIGNATURE: &'static str = "(value, precision)"
Source§impl PyMethods<Price> for PyClassImplCollector<Price>
impl PyMethods<Price> for PyClassImplCollector<Price>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for Price
impl PyTypeInfo for Price
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.Source§impl SubAssign for Price
impl SubAssign for Price
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-= operation. Read moreimpl Copy for Price
impl DerefToPyAny for Price
impl Eq for Price
Auto Trait Implementations§
impl Freeze for Price
impl RefUnwindSafe for Price
impl Send for Price
impl Sync for Price
impl Unpin for Price
impl UnwindSafe for Price
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FromPyObject<'_> for Twhere
T: PyClass + Clone,
impl<T> FromPyObject<'_> for Twhere
T: PyClass + Clone,
§fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>
fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>
§impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
§fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>
fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self into an owned Python object, dropping type information and unbinding it
from the 'py lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self into a Python object. Read more§impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
§fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>
fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>
§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
Source§impl<T> Separable for Twhere
T: Display,
impl<T> Separable for Twhere
T: Display,
Source§fn separate_by_policy(&self, policy: SeparatorPolicy<'_>) -> String
fn separate_by_policy(&self, policy: SeparatorPolicy<'_>) -> String
SeparatorPolicy. Read more