user_state_extended
user_state plus computed equity, margin, PnL fields. Each computed field is gated by an include_* flag so the contract can skip the work when not needed.
Derivations come straight from the book:
equity = collateral_value + Σ unrealised_pnl − Σ accrued_funding,
MM = Σ |size| × oracle × mmr, and a user is liquidatable when
equity < MM. See protocol book: perps/1-margin §4–§6.
Signature
def user_state_extended(
self,
user: Addr,
*,
include_equity: bool = True,
include_available_margin: bool = True,
include_maintenance_margin: bool = True,
include_unrealized_pnl: bool = True,
include_unrealized_funding: bool = True,
include_liquidation_price: bool = False,
) -> UserStateExtended | NoneExample
from dango.info import Info
from dango.utils.constants import MAINNET_API_URL
from dango.utils.types import Addr
info = Info(MAINNET_API_URL, skip_ws=True)
state = info.user_state_extended(Addr("0x..."), include_liquidation_price=True)
if state is not None:
print("equity:", state["equity"], "available:", state["available_margin"])Parameters
user — Addr. The user's account address.
include_equity — bool, optional. Default: True.
include_available_margin — bool, optional. Default: True.
include_maintenance_margin — bool, optional. Default: True.
include_unrealized_pnl — bool, optional. Default: True.
include_unrealized_funding — bool, optional. Default: True.
include_liquidation_price — bool, optional. Default: False.
Returns
UserStateExtended | None — TypedDict including equity, available_margin, maintenance_margin, and per-position unrealized_pnl / unrealized_funding / liquidation_price (per the flags). None if the user has no margin record. See UserStateExtended.
Notes
- The Rust
QueryMsg::UserStateExtendedvariant has an additionalinclude_allboolean that overrides every per-flag knob; the Python SDK deliberately omits it — there should be one canonical way to ask for everything.
See also
user_state— base shape without computed fieldsliquidate— call sites that needinclude_liquidation_price