pub struct AccountBalance {
pub currency: Currency,
pub total: Money,
pub locked: Money,
pub free: Money,
}Expand description
Represents an account balance denominated in a particular currency.
Fields§
§currency: CurrencyThe account balance currency.
total: MoneyThe total account balance.
locked: MoneyThe account balance locked (assigned to pending orders).
free: MoneyThe account balance free for trading.
Implementations§
Source§impl AccountBalance
impl AccountBalance
Sourcepub fn new_checked(
total: Money,
locked: Money,
free: Money,
) -> CorrectnessResult<Self>
pub fn new_checked( total: Money, locked: Money, free: Money, ) -> CorrectnessResult<Self>
Creates a new AccountBalance instance with correctness checking.
§Errors
Returns an error if total is not the result of locked + free.
§Notes
PyO3 requires a Result type that stacktrace can be printed for errors.
Sourcepub fn new(total: Money, locked: Money, free: Money) -> Self
pub fn new(total: Money, locked: Money, free: Money) -> Self
Creates a new AccountBalance instance.
§Panics
Panics if a correctness check fails. See AccountBalance::new_checked for more details.
Sourcepub fn from_total_and_locked(
total: Decimal,
locked: Decimal,
currency: Currency,
) -> CorrectnessResult<Self>
pub fn from_total_and_locked( total: Decimal, locked: Decimal, currency: Currency, ) -> CorrectnessResult<Self>
Creates a new AccountBalance from total and locked decimal amounts,
deriving free in fixed-point so the total == locked + free invariant
holds by construction at the currency precision.
When total is non-negative, locked is clamped into [0, total] so
a transient rounding glitch or overshoot cannot leave free negative.
When total is negative (spot borrow deficit or underwater margin account),
locked is passed through verbatim so venue-reported reserved margin is
preserved and free carries the shortfall.
§Errors
Returns an error if total or locked cannot be represented at the currency
precision.
Sourcepub fn from_total_and_free(
total: Decimal,
free: Decimal,
currency: Currency,
) -> CorrectnessResult<Self>
pub fn from_total_and_free( total: Decimal, free: Decimal, currency: Currency, ) -> CorrectnessResult<Self>
Creates a new AccountBalance from total and free decimal amounts,
deriving locked in fixed-point so the total == locked + free invariant
holds by construction at the currency precision.
When total is non-negative, free is clamped into [0, total] so
a transient PnL overshoot cannot leave locked negative. When total is
negative, free is passed through verbatim so the venue-reported available
amount is preserved and locked carries the difference.
§Errors
Returns an error if total or free cannot be represented at the currency
precision.
Source§impl AccountBalance
impl AccountBalance
Sourcepub fn py_from_dict(values: &Bound<'_, PyDict>) -> PyResult<Self>
pub fn py_from_dict(values: &Bound<'_, PyDict>) -> PyResult<Self>
Constructs an AccountBalance from a Python dict.
§Errors
Returns a PyErr if parsing or conversion fails.
§Panics
Panics if parsing numeric values (unwrap()) fails due to invalid format.
Sourcepub fn py_to_dict(&self, py: Python<'_>) -> PyResult<Py<PyAny>>
pub fn py_to_dict(&self, py: Python<'_>) -> PyResult<Py<PyAny>>
Trait Implementations§
Source§impl Clone for AccountBalance
impl Clone for AccountBalance
Source§fn clone(&self) -> AccountBalance
fn clone(&self) -> AccountBalance
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AccountBalance
impl Debug for AccountBalance
Source§impl<'de> Deserialize<'de> for AccountBalance
impl<'de> Deserialize<'de> for AccountBalance
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 Display for AccountBalance
impl Display for AccountBalance
Source§impl<'a, 'py> FromPyObject<'a, 'py> for AccountBalancewhere
Self: Clone,
impl<'a, 'py> FromPyObject<'a, 'py> for AccountBalancewhere
Self: Clone,
Source§impl<'py> IntoPyObject<'py> for AccountBalance
impl<'py> IntoPyObject<'py> for AccountBalance
Source§type Target = AccountBalance
type Target = AccountBalance
Source§type Output = Bound<'py, <AccountBalance as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <AccountBalance 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 PartialEq for AccountBalance
impl PartialEq for AccountBalance
Source§impl PyClass for AccountBalance
impl PyClass for AccountBalance
Source§impl PyClassImpl for AccountBalance
impl PyClassImpl for AccountBalance
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 an account balance denominated in a particular currency.
const RAW_DOC: &'static CStr = /// Represents an account balance denominated in a particular currency.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type Layout = <<AccountBalance as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<AccountBalance>
type Layout = <<AccountBalance as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<AccountBalance>
Source§type ThreadChecker = NoopThreadChecker
type ThreadChecker = NoopThreadChecker
type Inventory = Pyo3MethodsInventoryForAccountBalance
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<PyObjectOffset>
fn dict_offset() -> Option<PyObjectOffset>
§fn weaklist_offset() -> Option<PyObjectOffset>
fn weaklist_offset() -> Option<PyObjectOffset>
Source§impl PyClassNewTextSignature for AccountBalance
impl PyClassNewTextSignature for AccountBalance
const TEXT_SIGNATURE: &'static str = "(total, locked, free)"
Source§impl PyStubType for AccountBalance
impl PyStubType for AccountBalance
Source§fn type_output() -> TypeInfo
fn type_output() -> TypeInfo
§fn type_input() -> TypeInfo
fn type_input() -> TypeInfo
Source§impl PyTypeInfo for AccountBalance
impl PyTypeInfo for AccountBalance
Source§const NAME: &str = <Self as ::pyo3::PyClass>::NAME
const NAME: &str = <Self as ::pyo3::PyClass>::NAME
prefer using ::type_object(py).name() to get the correct runtime value
Source§const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE
const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE
prefer using ::type_object(py).module() to get the correct runtime value
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 Serialize for AccountBalance
impl Serialize for AccountBalance
impl Copy for AccountBalance
impl DerefToPyAny for AccountBalance
Auto Trait Implementations§
impl Freeze for AccountBalance
impl RefUnwindSafe for AccountBalance
impl Send for AccountBalance
impl Sync for AccountBalance
impl Unpin for AccountBalance
impl UnsafeUnpin for AccountBalance
impl UnwindSafe for AccountBalance
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<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,
§const NAME: &'static str = T::NAME
const NAME: &'static str = T::NAME
Use ::classinfo_object() instead and format the type name at runtime. Note that using built-in cast features is often better than manual PyTypeCheck usage.
§fn type_check(object: &Bound<'_, PyAny>) -> bool
fn type_check(object: &Bound<'_, PyAny>) -> bool
§fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
isinstance and issubclass function. Read more