Calculate and expose liquidationPrice in JupiterPerpsPosition #24

Open
opened 2026-06-30 06:56:49 +02:00 by minimons · 0 comments
Owner

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.

### 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.
minimons added the enhancement label 2026-06-30 06:56:49 +02:00
minimons self-assigned this 2026-06-30 06:56:49 +02:00
minimons added this to the AssetAZ project 2026-06-30 06:56:49 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: r35157/com_r35157_nenjim-hubd-impl_ref#24