/// @notice Margin requirement types
enum MarginRequirementType {
INITIAL,
MAINTENANCE
}
/// @notice margin ratio = account value / open notional
function getMarginRatio(
uint256 marketId,
address trader,
uint256 price
)
returns (
int256 marginRatio
)
/// @notice free collateral (for withdrawal) = min(free margin, account value) - initial margin requirement
/// @notice See free collateral for trades below
function getFreeCollateral(
uint256 marketId,
address trader,
uint256 price
)
returns (
uint256 freeCollateral
)
/// @notice free collateral (for trades) = min(margin, account value) - initial or maintenance margin requirement
/// INITIAL is for increasing position, MAINTENANCE is for reducing position
function getFreeCollateralForTrade(
uint256 marketId,
address trader,
uint256 price, // User supplied price (recommend using latest Pyth price)
MarginRequirementType marginRequirementType
)
returns (
int256 freeCollateralForTrade
);
/// @notice margin requirement = open notional * required margin ratio (initial or maintenance)
function getMarginRequirement(
uint256 marketId,
address trader,
MarginRequirementType marginRequirementType
) external view returns (uint256);
/// @notice unrealized pnl = position value + open notional
function getUnrealizedPnl(uint256 marketId, address trader, uint256 price) external view returns (int256);
/// @notice account value = margin (note it should include unsettled pnl and borrowing fee) + unrealized pnl
function getAccountValue(uint256 marketId, address trader, uint256 price) external view returns (int256);
/// @notice the margin trader can use for trading. when positive, it's always greater than or equal to "free margin"
function getMargin(uint256 marketId, address trader) external view returns (int256);
/// @notice the margin trader can access in any cases. it may be less than margin when pnl pool doesn't has enough
/// liquidity for unsettled profit
function getFreeMargin(uint256 marketId, address trader) external view returns (uint256);
function getOpenNotional(uint256 marketId, address trader) external view returns (int256);
function getPositionSize(uint256 marketId, address trader) external view returns (int256);