#[repr(C)]pub struct Currency {
pub code: Ustr,
pub precision: u8,
pub iso4217: u16,
pub name: Ustr,
pub currency_type: CurrencyType,
}Expand description
Represents a medium of exchange in a specified denomination with a fixed decimal precision.
Handles up to FIXED_PRECISION decimals of precision.
Fields§
§code: UstrThe currency code as an alpha-3 string (e.g., “USD”, “EUR”).
precision: u8The currency decimal precision.
iso4217: u16The ISO 4217 currency code.
name: UstrThe full name of the currency.
currency_type: CurrencyTypeThe currency type, indicating its category (e.g. Fiat, Crypto).
Implementations§
Source§impl Currency
impl Currency
Sourcepub fn new_checked<T: AsRef<str>>(
code: T,
precision: u8,
iso4217: u16,
name: T,
currency_type: CurrencyType,
) -> CorrectnessResult<Self>
pub fn new_checked<T: AsRef<str>>( code: T, precision: u8, iso4217: u16, name: T, currency_type: CurrencyType, ) -> CorrectnessResult<Self>
Creates a new Currency instance with correctness checking.
§Errors
Returns an error if:
codeis not a valid string.nameis the empty string.precisionis invalid outside the valid representable range [0,FIXED_PRECISION].
§Notes
PyO3 requires a Result type for proper error handling and stacktrace printing in Python.
Sourcepub fn new<T: AsRef<str>>(
code: T,
precision: u8,
iso4217: u16,
name: T,
currency_type: CurrencyType,
) -> Self
pub fn new<T: AsRef<str>>( code: T, precision: u8, iso4217: u16, name: T, currency_type: CurrencyType, ) -> Self
Creates a new Currency instance.
§Panics
Panics if a correctness check fails. See Currency::new_checked for more details.
Sourcepub fn register(currency: Self, overwrite: bool) -> CorrectnessResult<()>
pub fn register(currency: Self, overwrite: bool) -> CorrectnessResult<()>
Register the given currency in the internal currency map.
- If
overwriteistrue, any existing currency will be replaced. - If
overwriteisfalseand the currency already exists, the operation is a no-op.
§Errors
This function does not currently return an error.
Sourcepub fn try_from_str(s: &str) -> Option<Self>
pub fn try_from_str(s: &str) -> Option<Self>
Attempts to parse a Currency from a string, returning None if not found.
Sourcepub fn is_fiat(code: &str) -> Result<bool, CurrencyLookupError>
pub fn is_fiat(code: &str) -> Result<bool, CurrencyLookupError>
Checks if the currency identified by the given code is a fiat currency.
§Errors
Returns an error if a currency with the given code does not exist.
Sourcepub fn is_crypto(code: &str) -> Result<bool, CurrencyLookupError>
pub fn is_crypto(code: &str) -> Result<bool, CurrencyLookupError>
Checks if the currency identified by the given code is a cryptocurrency.
§Errors
Returns an error if a currency with the given code does not exist.
Sourcepub fn is_commodity_backed(code: &str) -> Result<bool, CurrencyLookupError>
pub fn is_commodity_backed(code: &str) -> Result<bool, CurrencyLookupError>
Checks if the currency identified by the given code is a commodity (such as a precious
metal).
§Errors
Returns an error if a currency with the given code does not exist.
Sourcepub fn get_or_create_crypto<T: AsRef<str>>(code: T) -> Self
pub fn get_or_create_crypto<T: AsRef<str>>(code: T) -> Self
Returns a currency from the internal map or creates a new crypto currency if not found.
This is a convenience method for adapters that need to handle unknown currencies (e.g., newly listed assets on exchanges). If the currency code is not found in the internal map, a new cryptocurrency is created with:
- 8 decimal precision
- ISO 4217 code of 0
CurrencyType::Crypto
The newly created currency is automatically registered in the internal map.
Sourcepub fn get_or_create_crypto_with_context<T: AsRef<str>>(
code: T,
context: Option<&str>,
) -> Self
pub fn get_or_create_crypto_with_context<T: AsRef<str>>( code: T, context: Option<&str>, ) -> Self
Gets or creates a cryptocurrency with context logging.
This is a convenience wrapper around Currency::get_or_create_crypto that:
- Trims whitespace from the currency code
- Handles empty strings with a fallback to USDT
- Provides optional context for logging
Used by exchange adapters for consistent currency handling across parsing operations.
§Arguments
code- The currency code (will be trimmed)context- Optional context for logging (e.g., “balance detail”, “instrument”)
Trait Implementations§
impl Copy for Currency
impl DerefToPyAny for Currency
Source§impl<'de> Deserialize<'de> for Currency
impl<'de> Deserialize<'de> for Currency
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>,
impl Eq for Currency
Source§impl<'py> IntoPyObject<'py> for Currency
impl<'py> IntoPyObject<'py> for Currency
Source§impl PyClassImpl for Currency
impl PyClassImpl for Currency
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 medium of exchange in a specified denomination with a fixed decimal precision.
///
/// Handles up to [`FIXED_PRECISION`] decimals of precision.
const RAW_DOC: &'static CStr = /// Represents a medium of exchange in a specified denomination with a fixed decimal precision. /// /// Handles up to [`FIXED_PRECISION`] decimals of precision.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type Layout = <<Currency as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<Currency>
type Layout = <<Currency as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<Currency>
Source§type ThreadChecker = NoopThreadChecker
type ThreadChecker = NoopThreadChecker
type Inventory = Pyo3MethodsInventoryForCurrency
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 Currency
impl PyClassNewTextSignature for Currency
const TEXT_SIGNATURE: &'static str = "(code, precision, iso4217, name, currency_type)"
Source§impl PyStubType for Currency
impl PyStubType for Currency
Source§fn type_output() -> TypeInfo
fn type_output() -> TypeInfo
§fn type_input() -> TypeInfo
fn type_input() -> TypeInfo
Source§impl PyTypeInfo for Currency
impl PyTypeInfo for Currency
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.Auto Trait Implementations§
impl Freeze for Currency
impl RefUnwindSafe for Currency
impl Send for Currency
impl Sync for Currency
impl Unpin for Currency
impl UnsafeUnpin for Currency
impl UnwindSafe for Currency
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§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<'py, T> FromPyObjectOwned<'py> for Twhere
T: for<'a> FromPyObject<'a, 'py>,
§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>where
Self: IntoPyObject<'py, Error = !>,
fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>where
Self: IntoPyObject<'py, Error = !>,
self into a [Py<PyAny>] when the underlying conversion is infallible.§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
§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