pub struct Cost(pub Decimal);Expand description
Cost type (zero-cost wrapper).
Represents the cost or total value of a trade, typically the result of price × amount. Provides type safety via the newtype pattern.
Tuple Fields§
§0: DecimalImplementations§
Source§impl Cost
impl Cost
Sourcepub fn new(value: Decimal) -> Cost
pub fn new(value: Decimal) -> Cost
Creates a new cost instance.
§Examples
use ccxt_core::types::financial::Cost;
use rust_decimal_macros::dec;
let cost = Cost::new(dec!(5000.0));Sourcepub fn as_decimal(&self) -> Decimal
pub fn as_decimal(&self) -> Decimal
Returns the inner Decimal value.
Sourcepub fn parse(s: &str) -> Result<Cost, Error>
pub fn parse(s: &str) -> Result<Cost, Error>
Parses a cost 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 cost is positive (greater than zero).
Source§impl Cost
impl Cost
Sourcepub fn gt(&self, other: Decimal) -> bool
pub fn gt(&self, other: Decimal) -> bool
Checks if the cost is greater than the given Decimal value.
Sourcepub fn lt(&self, other: Decimal) -> bool
pub fn lt(&self, other: Decimal) -> bool
Checks if the cost is less than the given Decimal value.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Cost
impl<'de> Deserialize<'de> for Cost
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Cost, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Cost, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Cost
impl Ord for Cost
Source§impl PartialOrd for Cost
impl PartialOrd for Cost
Source§impl Serialize for Cost
impl Serialize for Cost
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,
Serialize this value into the given Serde serializer. Read more
impl Copy for Cost
impl Eq for Cost
impl StructuralPartialEq for Cost
Auto Trait Implementations§
impl Freeze for Cost
impl RefUnwindSafe for Cost
impl Send for Cost
impl Sync for Cost
impl Unpin for Cost
impl UnwindSafe for Cost
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
Mutably borrows from an owned value. Read more
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.