pub struct SignedLeverageToBase(/* private fields */);
Expand description
The user-specified leverage for a position, with direction expressed as the signed value
Leverage is always specified by the user in terms of the base currency. In a collateral-is-quote market, that directly becomes the exposure to notional. In a collateral-is-base market, we need to convert that exposure from collateral to notional for internal calculations.
Implementations§
source§impl SignedLeverageToBase
impl SignedLeverageToBase
sourcepub fn into_notional(
self,
market_type: MarketType,
) -> Result<SignedLeverageToNotional>
pub fn into_notional( self, market_type: MarketType, ) -> Result<SignedLeverageToNotional>
Get the leverage in terms of the notional currency.
If the MarketType is MarketType::CollateralIsQuote, the value is already in terms of notional, and no change is needed. Otherwise, in a MarketType::CollateralIsBase, we have to convert from leverage in terms of base/collateral into a notional value.
The formula for converting is leverage_to_notional = 1 - leverage_to_base
. The motivation for that is:
- Going long on notional is equivalent to going short on collateral and vice-versa, therefore we have a negative sign.
- By holding the collateral asset, the trader already has exposure to its price fluctuation, so we need to represent that by adding 1.
sourcepub fn split(self) -> (DirectionToBase, LeverageToBase)
pub fn split(self) -> (DirectionToBase, LeverageToBase)
Split up this value into the direction and absolute leverage.
Trait Implementations§
source§impl Clone for SignedLeverageToBase
impl Clone for SignedLeverageToBase
source§fn clone(&self) -> SignedLeverageToBase
fn clone(&self) -> SignedLeverageToBase
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SignedLeverageToBase
impl Debug for SignedLeverageToBase
source§impl<'de> Deserialize<'de> for SignedLeverageToBase
impl<'de> Deserialize<'de> for SignedLeverageToBase
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for SignedLeverageToBase
impl Display for SignedLeverageToBase
source§impl FromStr for SignedLeverageToBase
impl FromStr for SignedLeverageToBase
source§impl JsonSchema for SignedLeverageToBase
impl JsonSchema for SignedLeverageToBase
source§fn schema_name() -> String
fn schema_name() -> String
source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§impl PartialEq for SignedLeverageToBase
impl PartialEq for SignedLeverageToBase
source§fn eq(&self, other: &SignedLeverageToBase) -> bool
fn eq(&self, other: &SignedLeverageToBase) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for SignedLeverageToBase
impl Serialize for SignedLeverageToBase
impl Copy for SignedLeverageToBase
impl StructuralPartialEq for SignedLeverageToBase
Auto Trait Implementations§
impl Freeze for SignedLeverageToBase
impl RefUnwindSafe for SignedLeverageToBase
impl Send for SignedLeverageToBase
impl Sync for SignedLeverageToBase
impl Unpin for SignedLeverageToBase
impl UnwindSafe for SignedLeverageToBase
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self
to type T
. The semantics of numeric casting with the as
operator are followed, so <T as As>::as_::<U>
can be used in the same way as T as U
for numeric conversions. Read moresource§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: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more