General Rules for Perpetual and Futures contracts
Unrealised PNL = (Mark Price - Average Entry Price) * Quantity
Realised PNL = (Exit Price - Entry Price) * Quantity
Example 1, Buying
A trader buys 3 BTC_TUSD.CFX contracts with an average price of 8500. After some time, the mark price of the contract rises to 8600.
(8600 - 8500) * 3 = 300 TUSD (Unrealised PNL)
Example 2, Selling
The trader then decides to close the position by selling 3 BTC_TUSD.CFX contracts with an average price of 8700.
(8700 - 8500) * 3 = 600 TUSD (Realised PNL)