Struct mango_v4::state::PerpMarket
source · #[repr(C)]pub struct PerpMarket {Show 48 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 reserved: [u8; 1888],
}
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 lot pairs currently active in the market. Always >= 0.
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
fees_settled: I80F48
Fees settled in native quote currency
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.
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.
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
§reserved: [u8; 1888]
Implementations§
source§impl PerpMarket
impl PerpMarket
pub fn name(&self) -> &str
pub fn is_reduce_only(&self) -> bool
pub fn is_force_close(&self) -> bool
pub fn elligible_for_group_insurance_fund(&self) -> bool
pub fn set_elligible_for_group_insurance_fund(&mut self, v: bool)
pub fn settle_pnl_limit_factor(&self) -> I80F48
pub fn gen_order_id(&mut self, side: Side, price_data: u64) -> u128
pub fn oracle_price( &self, oracle_acc: &impl KeyedAccountReader, staleness_slot: Option<u64> ) -> Result<I80F48>
pub fn oracle_price_and_state( &self, oracle_acc: &impl KeyedAccountReader, staleness_slot: Option<u64> ) -> Result<(I80F48, OracleState)>
pub fn stable_price(&self) -> I80F48
sourcepub fn update_funding_and_stable_price(
&mut self,
book: &Orderbook<'_>,
oracle_price: I80F48,
oracle_state: OracleState,
now_ts: u64
) -> Result<()>
pub fn update_funding_and_stable_price( &mut self, book: &Orderbook<'_>, oracle_price: I80F48, oracle_state: OracleState, now_ts: u64 ) -> Result<()>
Use current order book price and index price to update the instantaneous funding
sourcepub fn lot_to_native_price(&self, price: i64) -> I80F48
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
pub fn native_price_to_lot(&self, price: I80F48) -> i64
sourcepub fn inside_price_limit(
&self,
side: Side,
native_price: I80F48,
oracle_price: I80F48
) -> bool
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
?
Socialize the loss in this account across all longs and shorts
sourcepub fn compute_settle_fee(
&self,
settlement: I80F48,
source_liq_end_health: I80F48,
source_maint_health: I80F48
) -> Result<I80F48>
pub fn compute_settle_fee( &self, settlement: I80F48, source_liq_end_health: I80F48, source_maint_health: I80F48 ) -> Result<I80F48>
Returns the fee for settling settlement
when the negative-pnl side has the given
health values.
sourcepub fn default_for_tests() -> PerpMarket
pub fn default_for_tests() -> PerpMarket
Creates default market for tests
Trait Implementations§
source§impl AccountDeserialize for PerpMarket
impl AccountDeserialize for PerpMarket
source§fn try_deserialize(buf: &mut &[u8]) -> Result<Self>
fn try_deserialize(buf: &mut &[u8]) -> Result<Self>
Mint
account into a token
Account
.source§fn try_deserialize_unchecked(buf: &mut &[u8]) -> Result<Self>
fn try_deserialize_unchecked(buf: &mut &[u8]) -> Result<Self>
source§impl Clone for PerpMarket
impl Clone for PerpMarket
source§fn clone(&self) -> PerpMarket
fn clone(&self) -> PerpMarket
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PerpMarket
impl Debug for PerpMarket
source§impl Discriminator for PerpMarket
impl Discriminator for PerpMarket
fn discriminator() -> [u8; 8]
impl Copy for PerpMarket
impl Pod for PerpMarket
impl ZeroCopy for PerpMarket
Auto Trait Implementations§
impl RefUnwindSafe for PerpMarket
impl Send for PerpMarket
impl Sync for PerpMarket
impl Unpin for PerpMarket
impl UnwindSafe for PerpMarket
Blanket Implementations§
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,
§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere T: AnyBitPattern,
§type Bits = T
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
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self
.