#[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: QuantityRaw
Represents the raw fixed-point value, with precision
defining the number of decimal places.
precision: u8
The 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
Returns an error if:
value
is invalid outside the representable range [0, {QUANTITY_MAX}].precision
is 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
Returns an error if:
value
is zero.value
becomes zero after rounding toprecision
.value
is invalid outside the representable range [0, {QUANTITY_MAX}].precision
is 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
Panics if a correctness check fails. See Quantity::new_checked
for 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
Panics if a correctness check fails. See Quantity::non_zero_checked
for 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
Panics if a correctness check fails. See Quantity::new_checked
for 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
Panics if a correctness check fails. See Quantity::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_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§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
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
PyTypeInfo::type_object
PyTypeInfo::type_object
].§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_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
PyTypeInfo::is_type_of
PyTypeInfo::is_type_of
].§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.§fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
PyTypeInfo::is_exact_type_of
PyTypeInfo::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,
§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<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<'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 moreSource§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>
§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