Skip to content

Commit

Permalink
include oracle price in LiquidationAndPnlInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
jordy25519 committed Oct 24, 2024
1 parent 3086a9a commit 15c4fad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion crates/src/math/account_map_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ impl AccountsListBuilder {

/// Constructs an account map from `user` positions
///
/// It relies on the `client` being subscribed to all the necessary markets and oracles
/// like `try_build` but will fall back to network queries to fetch market/oracle accounts as required
/// if the client is already subscribed to necessary market/oracles then no network requests are made.
pub async fn build(&mut self, client: &DriftClient, user: &User) -> SdkResult<AccountsList> {
let mut oracle_markets =
HashMap::<Pubkey, MarketId>::with_capacity_and_hasher(16, Default::default());
Expand Down
6 changes: 5 additions & 1 deletion crates/src/math/liquidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ use crate::{
DriftClient, MarketId, SdkError, SdkResult, SpotPosition,
};

/// Info on a positions liquidation price and unrealized PnL
/// Info on a position's liquidation price and unrealized PnL
#[derive(Debug)]
pub struct LiquidationAndPnlInfo {
// PRICE_PRECISION
pub liquidation_price: i64,
// PRICE_PRECISION
pub unrealized_pnl: i128,
// The oracle price used in calculations
// BASE_PRECISION
pub oracle_price: i64,
}

/// Calculate the liquidation price and unrealized PnL of a user's perp position (given by `market_index`)
Expand Down Expand Up @@ -79,6 +82,7 @@ pub async fn calculate_liquidation_price_and_unrealized_pnl(
oracle_price,
&mut accounts_list,
)?,
oracle_price,
})
}

Expand Down

0 comments on commit 15c4fad

Please sign in to comment.