Calculate and expose liquidationPrice in JupiterPerpsPosition
#24
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
The Jupiter Perps API should expose the liquidation price for an open position.
Unlike other fields in
JupiterPerpsPosition, the liquidation price is not expected to be stored directly in the Position account. Instead, it is calculated from several other values.This issue implements the liquidation price calculation once all required input values have been exposed through the API.
Prerequisites
This issue depends on the following completed issues:
borrowFeeUsdcloseFeeUsdThe following values are already available:
entryPricesizeUsdcollateralUsddirectionRequired changes
Add a new field to
JupiterPerpsPosition:ΩUSDCPriceΩ liquidationPriceImplement the liquidation price calculation using the documented Jupiter Perps formula.
Return the calculated liquidation price as part of
JupiterPerpsPosition.Liquidation formula
Let:
price= entry pricecollateral_size= collateral in USDclose_fee= closing fee in USDborrow_fee= accumulated borrow fee in USDsize= position size in USDmax_lev= 500For LONG positions:
For SHORT positions:
Validation
Verify the calculated liquidation price against the Jupiter web UI for multiple LONG and SHORT positions.
The calculated value should closely match the value presented by Jupiter.
Notes
The liquidation price is expected to change over time because the accumulated borrow fee increases while a position remains open.
The implementation should therefore calculate the liquidation price each time the position is decoded rather than storing a cached value.