pub trait Currency: Copy + Send + Sized + Debug + Display + Add<Output = Self> + Sub<Output = Self> + Mul<Output = Self> + Div<Output = Self> + Add<Decimal, Output = Self> + Sub<Decimal, Output = Self> + Mul<Decimal, Output = Self> + Div<Decimal, Output = Self> + Rem<Output = Self> + AddAssign + SubAssign + for<'a> AddAssign<&'a Self> + for<'a> SubAssign<&'a Self> + 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§
sourcetype PairedCurrency: Currency<PairedCurrency = Self>
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§
sourcefn abs(self) -> Self
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
sourcefn fee_portion(&self, fee: Fee) -> Self
fn fee_portion(&self, fee: Fee) -> Self
Compute the fee denoted in the currency
sourcefn convert(&self, rate: QuoteCurrency) -> Self::PairedCurrency
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
sourcefn into_negative(self) -> Self
fn into_negative(self) -> Self
Convert the Currency to a negative value