pub struct Amount(pub Decimal);Expand description
Amount type (zero-cost wrapper).
Represents the quantity of an asset using Decimal for precision.
Provides type safety via the newtype pattern.
Tuple Fields§
§0: DecimalImplementations§
Source§impl Amount
impl Amount
Sourcepub fn new(value: Decimal) -> Amount
pub fn new(value: Decimal) -> Amount
Creates a new amount instance.
§Examples
use ccxt_core::types::financial::Amount;
use rust_decimal_macros::dec;
let amount = Amount::new(dec!(0.1));Sourcepub fn as_decimal(&self) -> Decimal
pub fn as_decimal(&self) -> Decimal
Returns the inner Decimal value.
Sourcepub fn parse(s: &str) -> Result<Amount, Error>
pub fn parse(s: &str) -> Result<Amount, Error>
Parses an amount from a string.
§Errors
Returns an error if the string cannot be parsed as a valid Decimal.
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns true if the amount is positive (greater than zero).
Source§impl Amount
impl Amount
Sourcepub fn gt(&self, other: Decimal) -> bool
pub fn gt(&self, other: Decimal) -> bool
Checks if the amount is greater than the given Decimal value.
Sourcepub fn lt(&self, other: Decimal) -> bool
pub fn lt(&self, other: Decimal) -> bool
Checks if the amount is less than the given Decimal value.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Amount
impl<'de> Deserialize<'de> for Amount
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Amount, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Amount, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Div<Decimal> for Amount
Amount ÷ Decimal = Amount (scalar division)
impl Div<Decimal> for Amount
Amount ÷ Decimal = Amount (scalar division)
Used for dividing amounts by a factor.
Source§impl Mul<Amount> for Price
Price × Amount = Cost
impl Mul<Amount> for Price
Price × Amount = Cost
This is the most fundamental relationship in financial calculations: price times amount equals cost. Enforces this constraint through the type system to prevent unit errors.
Source§impl Mul<Decimal> for Amount
Amount × Decimal = Amount (scalar multiplication)
impl Mul<Decimal> for Amount
Amount × Decimal = Amount (scalar multiplication)
Used for multiplying amounts by a factor.
Source§impl Ord for Amount
impl Ord for Amount
Source§impl PartialOrd for Amount
impl PartialOrd for Amount
Source§impl Serialize for Amount
impl Serialize for Amount
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for Amount
impl Eq for Amount
impl StructuralPartialEq for Amount
Auto Trait Implementations§
impl Freeze for Amount
impl RefUnwindSafe for Amount
impl Send for Amount
impl Sync for Amount
impl Unpin for Amount
impl UnwindSafe for Amount
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> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.