pub struct Position {
pub collateral: IFixed,
pub base_asset_amount: IFixed,
pub quote_asset_notional_amount: IFixed,
pub cum_funding_rate_long: IFixed,
pub cum_funding_rate_short: IFixed,
pub asks_quantity: IFixed,
pub bids_quantity: IFixed,
pub pending_orders: u64,
pub maker_fee: IFixed,
pub taker_fee: IFixed,
pub initial_margin_ratio: IFixed,
}Expand description
Stores information about an open position
Fields§
§collateral: IFixedAmount of allocated tokens (e.g., USD stables) backing this account’s position.
base_asset_amount: IFixedThe perpetual contract size, controlling the amount of exposure to the underlying asset. Positive implies long position and negative, short. Represented as a signed fixed-point number.
quote_asset_notional_amount: IFixedThe entry value for this position, including leverage. Represented as a signed fixed-point number.
cum_funding_rate_long: IFixedLast long cumulative funding rate used to update this position. The market’s latest long cumulative funding rate minus this gives the funding rate this position must pay. This rate multiplied by this position’s value (base asset amount * market price) gives the total funding owed, which is deducted from the trader account’s margin. This debt is accounted for in margin ratio calculations, which may lead to liquidation. Represented as a signed fixed-point number.
cum_funding_rate_short: IFixedLast short cumulative funding rate used to update this position. The market’s latest short cumulative funding rate minus this gives the funding rate this position must pay. This rate multiplied by this position’s value (base asset amount * market price) gives the total funding owed, which is deducted from the trader account’s margin. This debt is accounted for in margin ratio calculations, which may lead to liquidation. Represented as a signed fixed-point number.
asks_quantity: IFixedBase asset amount resting in ask orders in the orderbook. Represented as a signed fixed-point number.
bids_quantity: IFixedBase asset amount resting in bid orders in the orderbook. Represented as a signed fixed-point number.
pending_orders: u64Number of pending orders in this position.
maker_fee: IFixedCustom maker fee for this position, set at default value of 100%
taker_fee: IFixedCustom taker fee for this position, set at default value of 100%
initial_margin_ratio: IFixedInitial Margin Ratio set by user for the position. Must always be less or equal than market’s IMR. Used as a desired reference margin ratio when managing collateral in the position during all the actions. Can be changed by the user at any moment (between the allowed limits).
Implementations§
Source§impl Position
impl Position
Sourcepub fn liquidation_price(
&self,
coll_price: IFixed,
cum_funding_rate_long: IFixed,
cum_funding_rate_short: IFixed,
maintenance_margin_ratio: IFixed,
) -> Option<IFixed>
pub fn liquidation_price( &self, coll_price: IFixed, cum_funding_rate_long: IFixed, cum_funding_rate_short: IFixed, maintenance_margin_ratio: IFixed, ) -> Option<IFixed>
At which index price the position should be (partially) liquidated, assuming all the input variables stay the same.
Sourcepub fn entry_price(&self) -> Option<IFixed>
pub fn entry_price(&self) -> Option<IFixed>
Entry price of the position’s contracts; in the same units as the oracle index price.
This function returns None if the position has no open contracts, i.e., if
Self::base_asset_amount is zero.
Sourcepub fn unrealized_funding(
&self,
cum_funding_rate_long: IFixed,
cum_funding_rate_short: IFixed,
) -> IFixed
pub fn unrealized_funding( &self, cum_funding_rate_long: IFixed, cum_funding_rate_short: IFixed, ) -> IFixed
The funding yet to be settled in this position given the market’s current cumulative fundings.
The return value is in the same quote currency that the index price uses. E.g., if the index price is USD/BTC, then the unrealized funding is in USD units.
Sourcepub fn unrealized_pnl(&self, price: IFixed) -> IFixed
pub fn unrealized_pnl(&self, price: IFixed) -> IFixed
Unrealized PnL given an index price.
The returned value is in the same currency as what the index price is quoted at. E.g., if the index price is a ratio of BTC/ETH, then the PnL is in BTC units.
Source§impl Position
impl Position
Sourcepub fn new(
collateral: IFixed,
base_asset_amount: IFixed,
quote_asset_notional_amount: IFixed,
cum_funding_rate_long: IFixed,
cum_funding_rate_short: IFixed,
asks_quantity: IFixed,
bids_quantity: IFixed,
pending_orders: u64,
maker_fee: IFixed,
taker_fee: IFixed,
initial_margin_ratio: IFixed,
) -> Self
pub fn new( collateral: IFixed, base_asset_amount: IFixed, quote_asset_notional_amount: IFixed, cum_funding_rate_long: IFixed, cum_funding_rate_short: IFixed, asks_quantity: IFixed, bids_quantity: IFixed, pending_orders: u64, maker_fee: IFixed, taker_fee: IFixed, initial_margin_ratio: IFixed, ) -> Self
Constructs a new Position.
Source§impl Position
impl Position
pub fn move_instance(self, address: Address) -> MoveInstance<Self>
pub fn type_(address: Address) -> PositionTypeTag
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Position
impl<'de> Deserialize<'de> for Position
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 MoveStruct for Position
impl MoveStruct for Position
type StructTag = PositionTypeTag
Source§impl MoveType for Position
impl MoveType for Position
Source§impl StaticModule for Position
impl StaticModule for Position
fn module() -> Identifier
Source§impl StaticName for Position
impl StaticName for Position
fn name() -> Identifier
Source§impl StaticTypeParams for Position
impl StaticTypeParams for Position
fn type_params() -> Vec<TypeTag>
impl Eq for Position
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnwindSafe for Position
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<'de, T> FromBcs for Twhere
T: Deserialize<'de>,
impl<'de, T> FromBcs for Twhere
T: Deserialize<'de>,
fn from_bcs<'de>(bytes: &'de [u8]) -> Result<Self, Error>where
Self: Deserialize<'de>,
fn from_bcs_base64(base64: &str) -> Result<Self, Error>where
Self: DeserializeOwned,
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> 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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.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.