Lighter Docs
  • About Lighter
    • Introduction
    • API Docs (Coming Soon)
    • Whitepaper
    • Technical Architecture (Coming Soon)
  • Perpetual Futures
    • Contract Specifications
    • Order Types and Matching
    • Fair Price Marking
    • PnL And Total Account Value
    • Liquidations & Insurance Fund
    • Funding
    • Fees
    • Self-Trade Prevention
    • Sub-Accounts and API Keys
    • Public Pools
  • Points Program
  • security
    • Security Audits
Powered by GitBook
On this page
  • PnL (Profit and Loss)
  • Total Account Value
  1. Perpetual Futures

PnL And Total Account Value

PreviousFair Price MarkingNextLiquidations & Insurance Fund

Last updated 8 months ago

PnL (Profit and Loss)

Unrealized PnL represents the potential gain or loss an account would incur by closing all its open positions. It is calculated based on the difference between the average entry price of the positions and the current .

Let posipos_iposi​ be the current position size of an account. posipos_iposi​ is positive if the account position is long and negative if it is short. The unrealized PnL of the account can be calculated as:

Unrealized PnL:=∑(markPricei−avgEntryPricei)×positioni \text{Unrealized PnL} := \sum(\text{markPrice}_i - \text{avgEntryPrice}_i) \times position_i Unrealized PnL:=∑(markPricei​−avgEntryPricei​)×positioni​

Realized PnL is the gain / loss that has already been captured from the position after closing or due to funding payments. It is calculated based on the difference in USDC value between your average entry price and exit price. Additionally, all funding payments for the position are immediately applied to its realized PNL.

  • When the user is closing a portion of an existing long or short position, average entry price stays the same and exchange realizes the difference in average exit and entry prices.

ΔCollateral:=(exitPricei−avgEntryPricei)×Δpositioni\Delta Collateral := (\text{exitPrice}_i - \text{avgEntryPrice}_i) \times \Delta position_i ΔCollateral:=(exitPricei​−avgEntryPricei​)×Δpositioni​
  • When the user is increasing the size of their open position, no PnL is realized. Exchange updates the average entry price according to the following formula

avgEntryPricei,new:=avgEntryPricei,old×positioni,old+tradePrice×tradeSizepositioni,new \text{avgEntryPrice}_{i, new} := \frac{{avgEntryPrice}_{i, old }\times {position_{i, old}} + {tradePrice\times tradeSize}}{position_{i, new}}avgEntryPricei,new​:=positioni,new​avgEntryPricei,old​×positioni,old​+tradePrice×tradeSize​

Total Account Value

Total Account Value represents the total USDC value of an account in Lighter, including all open positions and collateral. It is calculated as follows:

Total Account Value=Collateral+Unrealized PnL\text{Total Account Value} = \text{Collateral} + \text{Unrealized PnL}Total Account Value=Collateral+Unrealized PnL

mark price