pub struct Price(pub Decimal);Expand description
Price type (zero-cost wrapper).
Represents the price of an asset using Decimal for precision.
Provides type safety via the newtype pattern to prevent confusion with amounts or costs.
Tuple Fields§
§0: DecimalImplementations§
Source§impl Price
impl Price
Sourcepub fn new(value: Decimal) -> Price
pub fn new(value: Decimal) -> Price
Creates a new price instance.
§Examples
use ccxt_core::types::financial::Price;
use rust_decimal_macros::dec;
let price = Price::new(dec!(50000.0));Sourcepub fn as_decimal(&self) -> Decimal
pub fn as_decimal(&self) -> Decimal
Returns the inner Decimal value.
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns true if the price is positive (greater than zero).
Source§impl Price
impl Price
Sourcepub fn gt(&self, other: Decimal) -> bool
pub fn gt(&self, other: Decimal) -> bool
Checks if the price is greater than the given Decimal value.
Sourcepub fn lt(&self, other: Decimal) -> bool
pub fn lt(&self, other: Decimal) -> bool
Checks if the price is less than the given Decimal value.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Price
impl<'de> Deserialize<'de> for Price
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Price, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Price, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Div<Decimal> for Price
Price ÷ Decimal = Price (scalar division)
impl Div<Decimal> for Price
Price ÷ Decimal = Price (scalar division)
Used for dividing prices by a factor, e.g., calculating average prices.
Source§impl Div for Price
Price ÷ Price = Decimal (price ratio)
impl Div for Price
Price ÷ Price = Decimal (price ratio)
Used for calculating price ratios, spread percentages, etc.
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 Price
Price × Decimal = Price (scalar multiplication)
impl Mul<Decimal> for Price
Price × Decimal = Price (scalar multiplication)
Used for multiplying prices by a factor, e.g., price adjustments.
Source§impl Ord for Price
impl Ord for Price
Source§impl PartialOrd for Price
impl PartialOrd for Price
Source§impl Serialize for Price
impl Serialize for Price
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 Price
impl Eq for Price
impl StructuralPartialEq for Price
Auto Trait Implementations§
impl Freeze for Price
impl RefUnwindSafe for Price
impl Send for Price
impl Sync for Price
impl Unpin for Price
impl UnwindSafe for Price
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> 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.