2.2 Closing Trade & Trade PnL

IVX Diem Contract

function closeTrade(uint256 _optionId, uint256 _amountContracts)
        external

Same requirements as the open trade function. This will close an open trade in the users portfolio.

To get the Profits and Losses of a trade,

 function calculatePnl(Trade memory _trade, uint256 closedUnits, bool _isLiquidation)
        public
        view
        returns (int256 PNL, uint premiumValue)

closedUnits is how many option contracts would the user be closing, insert full amount of contracts opened to get the full PnL of that trade.

_isLiquidation should be set to false, unless it's a liquidation calculation.

This takes into account that the frontend queried the parameter _trade from the user's portfolio.

IVX Portfolio =>

    struct Trade {
        bool closed;
        uint256 timestamp; //last block.timestamp of a position trade
        uint256 optionID;
        uint256 contractsOpen; //number of contracts open
        uint256 averageEntry; //average premium price paid on all contracts
        uint256 totalUnits; //total number of contracts entered in the trade, only incremented never reduced
        uint256 totalFee;
        uint256 borrowedAmount; //amount of collateral borrowed, used to calculate borrowing fees only
    }

Last updated