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:
borrowFeeUsd
closeFeeUsd
The following values are already available:
entryPrice
sizeUsd
collateralUsd
direction
Required changes
Add a new field to JupiterPerpsPosition:
ΩUSDCPriceΩ liquidationPrice
Implement the liquidation price calculation using the documented Jupiter Perps formula.
Return the calculated liquidation price as part of JupiterPerpsPosition.
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.
### 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:
* `borrowFeeUsd`
* `closeFeeUsd`
The following values are already available:
* `entryPrice`
* `sizeUsd`
* `collateralUsd`
* `direction`
### Required changes
* Add a new field to `JupiterPerpsPosition`:
* `ΩUSDCPriceΩ liquidationPrice`
* Implement the liquidation price calculation using the documented Jupiter Perps formula.
* Return the calculated liquidation price as part of `JupiterPerpsPosition`.
### Liquidation formula
Let:
* `price` = entry price
* `collateral_size` = collateral in USD
* `close_fee` = closing fee in USD
* `borrow_fee` = accumulated borrow fee in USD
* `size` = position size in USD
* `max_lev` = 500
For **LONG** positions:
```
liquidationPrice =
price
- (
abs(
collateral_size
- close_fee
- borrow_fee
- (size / max_lev)
)
* price
) / size
```
For **SHORT** positions:
```
liquidationPrice =
price
+ (
abs(
collateral_size
- close_fee
- borrow_fee
- (size / max_lev)
)
* price
) / size
```
### 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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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.