Trait lfest::prelude::Currency

source ·
pub trait Currency: Copy + Default + Send + Sized + Ord + Debug + Display + Add<Output = Self> + Sub<Output = Self> + Mul<Output = Self> + Div<Output = Self> + Rem<Output = Self> + Add<Decimal, Output = Self> + Sub<Decimal, Output = Self> + Mul<Decimal, Output = Self> + Div<Decimal, Output = Self> + Div<Leverage, Output = Self> + Mul<Fee, Output = Self> + Add<Fee, Output = Self> + AddAssign + SubAssign + PartialEq + PartialOrd {
    type PairedCurrency: Currency<PairedCurrency = Self>;

    // Required methods
    fn new(val: Decimal) -> Self;
    fn inner(self) -> Decimal;
    fn new_zero() -> Self;
    fn is_zero(&self) -> bool;
    fn abs(self) -> Self;
    fn fee_portion(&self, fee: Fee) -> Self;
    fn convert(&self, rate: QuoteCurrency) -> Self::PairedCurrency;
    fn into_negative(self) -> Self;
}
Expand description

Every unit of account must implement this trait

Required Associated Types§

source

type PairedCurrency: Currency<PairedCurrency = Self>

The paired currency. e.g.: for the BTCUSD market the BTC currency is paired with USD, so the PairedCurrency would be USD

Required Methods§

source

fn new(val: Decimal) -> Self

Create a new instance from a Rational value TODO: change return type to be Result<Self>, beacuse inputting a Decimal that it LTE zero could happen.

source

fn inner(self) -> Decimal

Return the inner Decimal

source

fn new_zero() -> Self

Create a new currency instance with zero value

source

fn is_zero(&self) -> bool

Check if the value is zero

source

fn abs(self) -> Self

TODO: it may be smart to remove this here and use another type that can be negative Get the absolute value

source

fn fee_portion(&self, fee: Fee) -> Self

Compute the fee denoted in the currency

source

fn convert(&self, rate: QuoteCurrency) -> Self::PairedCurrency

Convert this Currency’s value into its pair at the conversion rate. E.g: 1 BTC @ 20_000 USD means that 1 USD = 1 / 20_000 BTC

source

fn into_negative(self) -> Self

Convert the Currency to a negative value TODO: rename for greater clarity

Object Safety§

This trait is not object safe.

Implementors§