Entry Price and PnL
Last updated
Last updated
On the AlloX, entry price, unrealized pnl, and closed pnl are purely frontend components provided for user convenience. The fundamental accounting is based on margin (balance for spot) and trades.
Perp trades are considered opening
when the absolute value of the position increases. In other words, longing when already long or shorting when already short.
For opening trades, the entry price is updated to an average of the current entry price, and the trade price is weighted by size.
For closing trades, the entry price is kept the same.
Unrealized pnl is defined as side * (mark_price - entry_price) * position_size
where side = 1
for a long position and side = -1
for a short position
Closed pnl is fee + side * (mark_price - entry_price) * position_size
for a closing trade, and only the fee for an opening trade.
Spot trades use the same formulas as perps, with the following modifications: Spot trades are considered opening
for buys and closing
for sale. Transfers are treated as buys or sells at the market price, and genesis distributions are treated as having an entry price at 10000 USDC
the market cap. Note that while 0 is the correct answer as genesis distributions are not bought, it leads to an undefined return on equity.
Preexisting spot balances are assigned an entry price equal to the first trade or send after the feature is enabled around July 3, 08:00 UTC.