Struct mango_v4::state::PerpMarket

source ·
#[repr(C)]
pub struct PerpMarket {
Show 51 fields pub group: Pubkey, pub settle_token_index: TokenIndex, pub perp_market_index: PerpMarketIndex, pub blocked1: u8, pub group_insurance_fund: u8, pub bump: u8, pub base_decimals: u8, pub name: [u8; 16], pub bids: Pubkey, pub asks: Pubkey, pub event_queue: Pubkey, pub oracle: Pubkey, pub oracle_config: OracleConfig, pub stable_price_model: StablePriceModel, pub quote_lot_size: i64, pub base_lot_size: i64, pub maint_base_asset_weight: I80F48, pub init_base_asset_weight: I80F48, pub maint_base_liab_weight: I80F48, pub init_base_liab_weight: I80F48, pub open_interest: i64, pub seq_num: u64, pub registration_time: u64, pub min_funding: I80F48, pub max_funding: I80F48, pub impact_quantity: i64, pub long_funding: I80F48, pub short_funding: I80F48, pub funding_last_updated: u64, pub base_liquidation_fee: I80F48, pub maker_fee: I80F48, pub taker_fee: I80F48, pub fees_accrued: I80F48, pub fees_settled: I80F48, pub fee_penalty: f32, pub settle_fee_flat: f32, pub settle_fee_amount_threshold: f32, pub settle_fee_fraction_low_health: f32, pub settle_pnl_limit_factor: f32, pub padding3: [u8; 4], pub settle_pnl_limit_window_size_ts: u64, pub reduce_only: u8, pub force_close: u8, pub padding4: [u8; 6], pub maint_overall_asset_weight: I80F48, pub init_overall_asset_weight: I80F48, pub positive_pnl_liquidation_fee: I80F48, pub fees_withdrawn: u64, pub platform_liquidation_fee: I80F48, pub accrued_liquidation_fees: I80F48, pub reserved: [u8; 1848],
}

Fields§

§group: Pubkey§settle_token_index: TokenIndex

Token index that settlements happen in.

Currently required to be 0, USDC. In the future settlement may be allowed to happen in other tokens.

§perp_market_index: PerpMarketIndex

Index of this perp market. Other data, like the MangoAccount’s PerpPosition reference this market via this index. Unique for this group’s perp markets.

§blocked1: u8

Field used to contain the trusted_market flag and is now unused.

§group_insurance_fund: u8

Is this market covered by the group insurance fund?

§bump: u8

PDA bump

§base_decimals: u8

Number of decimals used for the base token.

Used to convert the oracle’s price into a native/native price.

§name: [u8; 16]

Name. Trailing zero bytes are ignored.

§bids: Pubkey

Address of the BookSide account for bids

§asks: Pubkey

Address of the BookSide account for asks

§event_queue: Pubkey

Address of the EventQueue account

§oracle: Pubkey

Oracle account address

§oracle_config: OracleConfig

Oracle configuration

§stable_price_model: StablePriceModel

Maintains a stable price based on the oracle price that is less volatile.

§quote_lot_size: i64

Number of quote native in a quote lot. Must be a power of 10.

Primarily useful for increasing the tick size on the market: A lot price of 1 becomes a native price of quote_lot_size/base_lot_size becomes a ui price of quote_lot_size*base_decimals/base_lot_size/quote_decimals.

§base_lot_size: i64

Number of base native in a base lot. Must be a power of 10.

Example: If base decimals for the underlying asset is 6, base lot size is 100 and and base position lots is 10_000 then base position native is 1_000_000 and base position ui is 1.

§maint_base_asset_weight: I80F48

These weights apply to the base position. The quote position has no explicit weight (but may be covered by the overall pnl asset weight).

§init_base_asset_weight: I80F48§maint_base_liab_weight: I80F48§init_base_liab_weight: I80F48§open_interest: i64

Number of base lots currently active in the market. Always >= 0.

Since this counts positive base lots and negative base lots, the more relevant number of open base lot pairs is half this value.

§seq_num: u64

Total number of orders seen

§registration_time: u64

Timestamp in seconds that the market was registered at.

§min_funding: I80F48

Minimal funding rate per day, must be <= 0.

§max_funding: I80F48

Maximal funding rate per day, must be >= 0.

§impact_quantity: i64

For funding, get the impact price this many base lots deep into the book.

§long_funding: I80F48

Current long funding value. Increasing it means that every long base lot needs to pay that amount of quote native in funding.

PerpPosition uses and tracks it settle funding. Updated by the perp keeper instruction.

§short_funding: I80F48

See long_funding.

§funding_last_updated: u64

timestamp that funding was last updated in

§base_liquidation_fee: I80F48

Fees Fee for base position liquidation

§maker_fee: I80F48

Fee when matching maker orders. May be negative.

§taker_fee: I80F48

Fee for taker orders, may not be negative.

§fees_accrued: I80F48

Fees accrued in native quote currency these are increased when new fees are paid and decreased when perp_settle_fees is called

§fees_settled: I80F48

Fees settled in native quote currency these are increased when perp_settle_fees is called, and never decreased

§fee_penalty: f32

Fee (in quote native) to charge for ioc orders

§settle_fee_flat: f32

In native units of settlement token, given to each settle call above the settle_fee_amount_threshold if settling at least 1% of perp base pos value.

§settle_fee_amount_threshold: f32

Pnl settlement amount needed to be eligible for the flat fee.

§settle_fee_fraction_low_health: f32

Fraction of pnl to pay out as fee if +pnl account has low health. (limited to 2x settle_fee_flat)

§settle_pnl_limit_factor: f32

Controls the strictness of the settle limit. Set to a negative value to disable the limit.

This factor applies to the settle limit in two ways

  • for the unrealized pnl settle limit, the factor is multiplied with the stable perp base value (i.e. limit_factor * base_native * stable_price)
  • when increasing the realized pnl settle limit (stored per PerpPosition), the factor is multiplied with the stable value of the perp pnl being realized (i.e. limit_factor * reduced_native * stable_price)

See also PerpPosition::settle_pnl_limit_realized_trade

§padding3: [u8; 4]§settle_pnl_limit_window_size_ts: u64

Window size in seconds for the perp settlement limit

§reduce_only: u8

If true, users may no longer increase their market exposure. Only actions that reduce their position are still allowed.

§force_close: u8§padding4: [u8; 6]§maint_overall_asset_weight: I80F48

Weights for full perp market health, if positive

§init_overall_asset_weight: I80F48§positive_pnl_liquidation_fee: I80F48§fees_withdrawn: u64§platform_liquidation_fee: I80F48

Additional to liquidation_fee, but goes to the group owner instead of the liqor

§accrued_liquidation_fees: I80F48

Platform fees that were accrued during liquidation (in native tokens)

These fees are also added to fees_accrued, this is just for bookkeeping the total liquidation fees that happened. So never decreases (different to fees_accrued).

§reserved: [u8; 1848]

Implementations§

source§

impl PerpMarket

source

pub fn name(&self) -> &str

source

pub fn is_reduce_only(&self) -> bool

source

pub fn is_force_close(&self) -> bool

source

pub fn elligible_for_group_insurance_fund(&self) -> bool

source

pub fn set_elligible_for_group_insurance_fund(&mut self, v: bool)

source

pub fn settle_pnl_limit_factor(&self) -> I80F48

source

pub fn gen_order_id(&mut self, side: Side, price_data: u64) -> u128

source

pub fn oracle_price<T: KeyedAccountReader>( &self, oracle_acc_infos: &OracleAccountInfos<'_, T>, staleness_slot: Option<u64> ) -> Result<I80F48>

source

pub fn oracle_state<T: KeyedAccountReader>( &self, oracle_acc_infos: &OracleAccountInfos<'_, T>, staleness_slot: Option<u64> ) -> Result<OracleState>

source

pub fn stable_price(&self) -> I80F48

source

pub fn update_funding_and_stable_price( &mut self, book: &Orderbook<'_>, oracle_state: &OracleState, now_ts: u64 ) -> Result<()>

Use current order book price and index price to update the instantaneous funding

source

pub fn lot_to_native_price(&self, price: i64) -> I80F48

Convert from the price stored on the book to the price used in value calculations

source

pub fn native_price_to_lot(&self, price: I80F48) -> i64

source

pub fn inside_price_limit( &self, side: Side, native_price: I80F48, oracle_price: I80F48 ) -> bool

Is native_price an acceptable order for the side of this market, given oracle_price?

source

pub fn socialize_loss(&mut self, loss: I80F48) -> Result<I80F48>

Socialize the loss in this account across all longs and shorts

loss is in settle token native units

source

pub fn compute_settle_fee( &self, settlement: I80F48, source_pnl_value: I80F48, source_position_value: I80F48, source_liq_end_health: I80F48, source_maint_health: I80F48 ) -> Result<I80F48>

Returns the fee for settling settlement when the account with positive unsettled pnl has the given source pnl/position/health values.

source

pub fn default_for_tests() -> PerpMarket

Creates default market for tests

Trait Implementations§

source§

impl AccountDeserialize for PerpMarket

source§

fn try_deserialize(buf: &mut &[u8]) -> Result<Self>

Deserializes previously initialized account data. Should fail for all uninitialized accounts, where the bytes are zeroed. Implementations should be unique to a particular account type so that one can never successfully deserialize the data of one account type into another. For example, if the SPL token program were to implement this trait, it should be impossible to deserialize a Mint account into a token Account.
source§

fn try_deserialize_unchecked(buf: &mut &[u8]) -> Result<Self>

Deserializes account data without checking the account discriminator. This should only be used on account initialization, when the bytes of the account are zeroed.
source§

impl Clone for PerpMarket

source§

fn clone(&self) -> PerpMarket

Returns a copy 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 PerpMarket

source§

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

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

impl Discriminator for PerpMarket

source§

const DISCRIMINATOR: [u8; 8] = _

§

fn discriminator() -> [u8; 8]

source§

impl Owner for PerpMarket

source§

fn owner() -> Pubkey

source§

impl Zeroable for PerpMarket

§

fn zeroed() -> Self

source§

impl Copy for PerpMarket

source§

impl Pod for PerpMarket

source§

impl ZeroCopy for PerpMarket

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

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

§

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

§

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

source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dstwhere T: Cast<Dst>,

Casts the value.
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dstwhere Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,

Casts the value.
§

impl<T> CheckedBitPattern for Twhere T: AnyBitPattern,

§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> DynClone for Twhere T: Clone,

source§

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

source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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<Src, Dst> LosslessTryInto<Dst> for Srcwhere Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Srcwhere Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Srcwhere Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

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

§

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> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> AnyBitPattern for Twhere T: Pod,

§

impl<T> NoUninit for Twhere T: Pod,