PositionModel

Struct PositionModel 

Source
pub struct PositionModel { /* private fields */ }
Expand description

Position Model.

Implementations§

Source§

impl PositionModel

Source

pub fn new( market: MarketModel, position: Arc<Position>, ) -> Result<PositionModel, Error>

Create from MarketModel and Position.

Source

pub fn position(&self) -> &Position

Get position.

Source

pub fn position_arc(&self) -> &Arc<Position>

Returns a reference to the position wrapped in an Arc.

Source

pub fn swap_history(&self) -> &[Arc<SwapReport<u128, i128>>]

Returns the swap history.

Source

pub fn clear(&mut self)

Clear the swap history.

Source

pub fn update(&mut self, new_state: &PositionState, force_update: bool) -> bool

Updates the current state with the given PositionState if its trade_id is newer.

Skips the trade ID check if force_update is true.

Returns true if an update was made.

Source

pub fn market_model(&self) -> &MarketModel

Get the market model.

Source

pub fn set_market_model(&mut self, market: &MarketModel)

Set market model to the given.

Trait Implementations§

Source§

impl Clone for PositionModel

Source§

fn clone(&self) -> PositionModel

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PositionModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<PositionModel> for JsPositionModel

Available on crate feature js only.
Source§

fn from(model: PositionModel) -> Self

Converts to this type from the input type.
Source§

impl Position<gmsol_programs::::model::position::{impl#5}::{constant#0}> for PositionModel

Source§

type Market = MarketModel

Market type.
Source§

fn market( &self, ) -> &<PositionModel as Position<gmsol_programs::::model::position::{impl#5}::{constant#0}>>::Market

Get a reference to the market.
Source§

fn is_long(&self) -> bool

Returns whether the position is a long position.
Source§

fn is_collateral_token_long(&self) -> bool

Returns whether the collateral token is the long token of the market.
Source§

fn are_pnl_and_collateral_tokens_the_same(&self) -> bool

Returns whether the pnl and collateral tokens are the same.
Source§

fn on_validate(&self) -> Result<(), Error>

Called from validate_position to add supplementary checks.
Source§

impl PositionCalculations for PositionModel

Source§

fn status(&self, prices: &Prices<u128>) -> Result<PositionStatus>

Calculate position status.
Source§

impl PositionMut<gmsol_programs::::model::position::{impl#6}::{constant#0}> for PositionModel

Source§

fn market_mut( &mut self, ) -> &mut <PositionModel as Position<gmsol_programs::::model::position::{impl#6}::{constant#0}>>::Market

Get a mutable reference to the market.
Source§

fn on_increased(&mut self) -> Result<(), Error>

Increased callback.
Source§

fn on_decreased(&mut self) -> Result<(), Error>

Decreased callback.
Source§

fn on_swapped( &mut self, _ty: DecreasePositionSwapType, report: &SwapReport<<PositionModel as PositionState<gmsol_programs::::model::position::{impl#6}::{constant#0}>>::Num, <<PositionModel as PositionState<gmsol_programs::::model::position::{impl#6}::{constant#0}>>::Num as Unsigned>::Signed>, ) -> Result<(), Error>

Swapped callback.
Source§

fn on_swap_error( &mut self, _ty: DecreasePositionSwapType, _error: Error, ) -> Result<(), Error>

Handle swap error.
Source§

impl PositionState<gmsol_programs::::model::position::{impl#3}::{constant#0}> for PositionModel

Source§

type Num = u128

Unsigned number type.
Source§

type Signed = i128

Signed number type.
Source§

fn collateral_amount( &self, ) -> &<PositionModel as PositionState<gmsol_programs::::model::position::{impl#3}::{constant#0}>>::Num

Get the collateral amount.
Source§

fn size_in_usd( &self, ) -> &<PositionModel as PositionState<gmsol_programs::::model::position::{impl#3}::{constant#0}>>::Num

Get a reference to the size (in USD) of the position.
Source§

fn size_in_tokens( &self, ) -> &<PositionModel as PositionState<gmsol_programs::::model::position::{impl#3}::{constant#0}>>::Num

Get a reference to the size (in tokens) of the position.
Source§

fn borrowing_factor( &self, ) -> &<PositionModel as PositionState<gmsol_programs::::model::position::{impl#3}::{constant#0}>>::Num

Get a reference to last borrowing factor applied by the position.
Source§

fn funding_fee_amount_per_size( &self, ) -> &<PositionModel as PositionState<gmsol_programs::::model::position::{impl#3}::{constant#0}>>::Num

Get a reference to the funding fee amount per size.
Source§

fn claimable_funding_fee_amount_per_size( &self, is_long_collateral: bool, ) -> &<PositionModel as PositionState<gmsol_programs::::model::position::{impl#3}::{constant#0}>>::Num

Get a reference to claimable funding fee amount per size of the given collateral.
Source§

impl PositionStateMut<gmsol_programs::::model::position::{impl#4}::{constant#0}> for PositionModel

Source§

fn collateral_amount_mut( &mut self, ) -> &mut <PositionModel as PositionState<gmsol_programs::::model::position::{impl#4}::{constant#0}>>::Num

Get a mutable reference to the collateral amount.
Source§

fn size_in_usd_mut( &mut self, ) -> &mut <PositionModel as PositionState<gmsol_programs::::model::position::{impl#4}::{constant#0}>>::Num

Get a mutable reference to the size (in USD) of the position.
Source§

fn size_in_tokens_mut( &mut self, ) -> &mut <PositionModel as PositionState<gmsol_programs::::model::position::{impl#4}::{constant#0}>>::Num

Get a mutable reference to the size (in tokens) of the position.
Source§

fn borrowing_factor_mut( &mut self, ) -> &mut <PositionModel as PositionState<gmsol_programs::::model::position::{impl#4}::{constant#0}>>::Num

Get a mutable reference to last borrowing factor applied by the position.
Source§

fn funding_fee_amount_per_size_mut( &mut self, ) -> &mut <PositionModel as PositionState<gmsol_programs::::model::position::{impl#4}::{constant#0}>>::Num

Get a mutable reference to the funding fee amount per size.
Source§

fn claimable_funding_fee_amount_per_size_mut( &mut self, is_long_collateral: bool, ) -> &mut <PositionModel as PositionState<gmsol_programs::::model::position::{impl#4}::{constant#0}>>::Num

Get a mutable reference to claimable funding fee amount per size of the given collateral.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<const DECIMALS: u8, P> PositionExt<DECIMALS> for P
where P: Position<DECIMALS>,

Source§

fn will_collateral_be_sufficient( &self, prices: &Prices<Self::Num>, delta: &CollateralDelta<Self::Num>, ) -> Result<WillCollateralBeSufficient<Self::Signed>, Error>

Check that whether the collateral will be sufficient after paying the given realized_pnl and applying delta_size. Read more
Source§

fn collateral_price<'a>( &self, prices: &'a Prices<Self::Num>, ) -> &'a Price<Self::Num>

Get collateral price.
Source§

fn collateral_value( &self, prices: &Prices<Self::Num>, ) -> Result<Self::Num, Error>

Get collateral value.
Source§

fn pnl_value( &self, prices: &Prices<Self::Num>, size_delta_usd: &Self::Num, ) -> Result<(Self::Signed, Self::Signed, Self::Num), Error>

Calculate the pnl value when decreased by the given delta size. Read more
Source§

fn validate( &self, prices: &Prices<Self::Num>, should_validate_min_position_size: bool, should_validate_min_collateral_usd: bool, ) -> Result<(), Error>

Validate the position.
Source§

fn check_liquidatable( &self, prices: &Prices<Self::Num>, should_validate_min_collateral_usd: bool, for_liquidation: bool, ) -> Result<Option<LiquidatableReason>, Error>

Check if the position is liquidatable. Read more
Source§

fn position_price_impact( &self, size_delta_usd: &Self::Signed, include_virtual_inventory_impact: bool, ) -> Result<PriceImpact<Self::Signed>, Error>

Get position price impact.
Source§

fn capped_positive_position_price_impact( &self, index_token_price: &Price<Self::Num>, size_delta_usd: &Self::Signed, include_virtual_inventory_impact: bool, ) -> Result<PriceImpact<Self::Signed>, Error>

Get position price impact usd and cap the value if it is positive.
Source§

fn capped_position_price_impact( &self, index_token_price: &Price<Self::Num>, size_delta_usd: &Self::Signed, include_virtual_inventory_impact: bool, ) -> Result<(PriceImpact<Self::Signed>, Self::Num), Error>

Get capped position price impact usd. Read more
Source§

fn pending_borrowing_fee_value(&self) -> Result<Self::Num, Error>

Get pending borrowing fee value of this position.
Source§

fn pending_funding_fees(&self) -> Result<FundingFees<Self::Num>, Error>

Get pending funding fees.
Source§

fn position_fees( &self, collateral_token_price: &Price<Self::Num>, size_delta_usd: &Self::Num, balance_change: BalanceChange, is_liquidation: bool, ) -> Result<PositionFees<Self::Num>, Error>

Calculates the PositionFees generated by changing the position size by the specified size_delta_usd.
Source§

impl<const DECIMALS: u8, P> PositionStateExt<DECIMALS> for P
where P: PositionState<DECIMALS> + ?Sized,

Source§

fn is_empty(&self) -> bool

Return whether the position is considered to be empty during the decrease position action.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,