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§
§impl SignedLeverageToBase
impl SignedLeverageToBase
pub fn into_notional(
self,
market_type: MarketType
) -> Result<SignedLeverageToNotional, Error>
pub fn into_notional( self, market_type: MarketType ) -> Result<SignedLeverageToNotional, Error>
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.
pub fn split(self) -> (DirectionToBase, LeverageToBase)
pub fn split(self) -> (DirectionToBase, LeverageToBase)
Split up this value into the direction and absolute leverage.
Trait Implementations§
§impl Clone for SignedLeverageToBase
impl Clone for SignedLeverageToBase
§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 more§impl Debug for SignedLeverageToBase
impl Debug for SignedLeverageToBase
§impl<'de> Deserialize<'de> for SignedLeverageToBase
impl<'de> Deserialize<'de> for SignedLeverageToBase
§fn deserialize<__D>(
__deserializer: __D
) -> Result<SignedLeverageToBase, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>( __deserializer: __D ) -> Result<SignedLeverageToBase, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,
§impl Display for SignedLeverageToBase
impl Display for SignedLeverageToBase
§impl FromStr for SignedLeverageToBase
impl FromStr for SignedLeverageToBase
§impl JsonSchema for SignedLeverageToBase
impl JsonSchema for SignedLeverageToBase
§fn schema_name() -> String
fn schema_name() -> String
§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
§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 more§impl PartialEq for SignedLeverageToBase
impl PartialEq for SignedLeverageToBase
§fn eq(&self, other: &SignedLeverageToBase) -> bool
fn eq(&self, other: &SignedLeverageToBase) -> bool
self
and other
values to be equal, and is used
by ==
.§impl Serialize for SignedLeverageToBase
impl Serialize for SignedLeverageToBase
§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 SignedLeverageToBase
impl StructuralPartialEq for SignedLeverageToBase
Auto Trait Implementations§
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 more