MCDEX
Search…
Get Account
This guide shows how to get account by using the ILiquidityPoolFull interface and get related information from account object.

Get Account Object

Function

function getMarginAccount(uint256 perpetualIndex, address trader)
parameters
type
description
perpetualIndex
uint256
index of perpetual in the liquidity pool
trader
address
address of trader
Return information from account object
returns
type
description
cash
int256
cash(collateral) of the account
position
int256
position of the account
availableMargin
int256
available margin of the account
margin
int256
margin of the account
settleableMargin
int256
settleable margin of the account
isInitialMarginSafe
bool
true if the account is initial margin safe
isMaintenanceMarginSafe
bool
true if the account is maintenance margin safe
isMarginSafe
bool
true if the total value of margin account is beyond 0
targetLeverage
int256
(reserved) target leverage for openning position.

Example

WARN: before calling getLiquidityPoolInfo(), need to sync the state by using the forceToSyncState function.
1
ILiquidityPoolFull liquidityPool = ILiquidityPoolFull(liquidityPoolAddress)
2
liquidityPool.forceToSyncState()
3
// WARN: If show stack too deep, try split the returns values
4
(cash, position, availableMargin, margin, settleableMargin, isInitialMarginSafe, isMaintenanceMarginSafe, isMarginSafe, targetLeverage) = liquidityPool.getMarginAccount(perpetualIndex, trader)
Copied!

Sample Code

Github
Last modified 5d ago