#[repr(C)]pub struct Quantity {
pub raw: QuantityRaw,
pub precision: u8,
}Expand description
Represents a quantity with a non-negative value.
Capable of storing either a whole number (no decimal places) of ‘contracts’ or ‘shares’ (instruments denominated in whole units) or a decimal value containing decimal places for instruments denominated in fractional units.
Handles up to {FIXED_PRECISION} decimals of precision.
QUANTITY_MAX= {QUANTITY_MAX}QUANTITY_MIN= 0
Fields§
§raw: QuantityRawRepresents 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 Quantity
impl Quantity
Sourcepub fn new_checked(value: f64, precision: u8) -> Result<Self>
pub fn new_checked(value: f64, precision: u8) -> Result<Self>
Creates a new Quantity instance with correctness checking.
§Errors
This function returns an error:
- If
valueis invalid outside the representable range [0, {QUANTITY_MAX}]. - If
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 non_zero_checked(value: f64, precision: u8) -> Result<Self>
pub fn non_zero_checked(value: f64, precision: u8) -> Result<Self>
Creates a new Quantity instance with a guaranteed non zero value.
§Errors
This function returns an error:
- If
valueis zero. - If
valuebecomes zero after rounding toprecision. - If
valueis invalid outside the representable range [0, {QUANTITY_MAX}]. - If
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 Quantity instance.
§Panics
This function panics:
- If a correctness check fails. See
Quantity::new_checkedfor more details.
Sourcepub fn non_zero(value: f64, precision: u8) -> Self
pub fn non_zero(value: f64, precision: u8) -> Self
Creates a new Quantity instance with a guaranteed non zero value.
§Panics
This function panics:
- If a correctness check fails. See
Quantity::non_zero_checkedfor more details.
Sourcepub fn from_raw(raw: QuantityRaw, precision: u8) -> Self
pub fn from_raw(raw: QuantityRaw, precision: u8) -> Self
Creates a new Quantity instance from the given raw fixed-point value and precision.
§Panics
This function panics:
- If a correctness check fails. See
Quantity::new_checkedfor more details.
Sourcepub fn zero(precision: u8) -> Self
pub fn zero(precision: u8) -> Self
Creates a new Quantity instance with a value of zero with the given precision.
§Panics
This function panics:
- If a correctness check fails. See
Quantity::new_checkedfor 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_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.
Trait Implementations§
Source§impl<T: Into<QuantityRaw>> AddAssign<T> for Quantity
impl<T: Into<QuantityRaw>> AddAssign<T> for Quantity
Source§fn add_assign(&mut self, other: T)
fn add_assign(&mut self, other: T)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Quantity
impl<'de> Deserialize<'de> for Quantity
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 From<&Quantity> for QuantityRaw
impl From<&Quantity> for QuantityRaw
Source§impl From<Quantity> for QuantityRaw
impl From<Quantity> for QuantityRaw
Source§impl<'py> IntoPyObject<'py> for Quantity
impl<'py> IntoPyObject<'py> for Quantity
Source§type Output = Bound<'py, <Quantity as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <Quantity as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl<T: Into<QuantityRaw>> MulAssign<T> for Quantity
impl<T: Into<QuantityRaw>> MulAssign<T> for Quantity
Source§fn mul_assign(&mut self, other: T)
fn mul_assign(&mut self, other: T)
*= operation. Read moreSource§impl Ord for Quantity
impl Ord for Quantity
Source§impl PartialOrd for Quantity
impl PartialOrd for Quantity
Source§impl PyClassImpl for Quantity
impl PyClassImpl for Quantity
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§type ThreadChecker = SendablePyClass<Quantity>
type ThreadChecker = SendablePyClass<Quantity>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
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<Quantity> for PyClassImplCollector<Quantity>
impl PyClassNewTextSignature<Quantity> for PyClassImplCollector<Quantity>
fn new_text_signature(self) -> Option<&'static str>
Source§impl PyMethods<Quantity> for PyClassImplCollector<Quantity>
impl PyMethods<Quantity> for PyClassImplCollector<Quantity>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for Quantity
impl PyTypeInfo for Quantity
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
Source§fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
PyTypeInfo::type_objectPyTypeInfo::type_object.Source§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.Source§fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
PyTypeInfo::is_type_ofPyTypeInfo::is_type_of.Source§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§fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
PyTypeInfo::is_exact_type_ofPyTypeInfo::is_exact_type_of.Source§impl<T: Into<QuantityRaw>> SubAssign<T> for Quantity
impl<T: Into<QuantityRaw>> SubAssign<T> for Quantity
Source§fn sub_assign(&mut self, other: T)
fn sub_assign(&mut self, other: T)
-= operation. Read moreimpl Copy for Quantity
impl DerefToPyAny for Quantity
impl Eq for Quantity
Auto Trait Implementations§
impl Freeze for Quantity
impl RefUnwindSafe for Quantity
impl Send for Quantity
impl Sync for Quantity
impl Unpin for Quantity
impl UnwindSafe for Quantity
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,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FromPyObject<'_> for T
impl<T> FromPyObject<'_> for T
Source§impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
Source§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
Source§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.Source§impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
Source§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
Source§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