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

Get Account Object

This section shows how to get account object and information of this account object.
Can reference Quick Start to know how to create reader.
CallStatic method provided by ethers.js. callStatic is a useful method that submits a state-changing transaction to an Ethereum node, but asks the node to simulate the state change, rather than to execute it. Our script can then return the result of the simulated state change.

Function

getAccountStorage(liquidityPoolAddress, perpetualIndex, traderAddress)
parameters
type
description
liquidityPoolAddress
string
address of liquidity pool
perpetualIndex
number
index of perpetual in the liquidity pool
traderAddress
string
address of trader
Return information from account object
returns
type
description
isSynced
bool
true if the liquidity pool is synced
cash(reserved)
number
cash(collateral) of the account
position
number
position of the account
availableMargin(reserved)
number
the available margin of the account
margin
number
the margin of the account
settleableMargin
number
the 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(reserved)
number
the target leverage for opening position

Example

1
const account = await reader.callStatic.getAccountStorage(liquidityPoolAddress, 0, traderAddress)
Copied!
After getting account object, can get useful information like previous section. EX: position, margin.
1
const position = fromWei(account.accountStorage.position.toString())
2
const margin = fromWei(account.accountStorage.margin.toString())
Copied!

Sample Code

Account
Last modified 23d ago