Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

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 | None

Example

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

userAddr. The user's account address.

include_equitybool, optional. Default: True.

include_available_marginbool, optional. Default: True.

include_maintenance_marginbool, optional. Default: True.

include_unrealized_pnlbool, optional. Default: True.

include_unrealized_fundingbool, optional. Default: True.

include_liquidation_pricebool, 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::UserStateExtended variant has an additional include_all boolean 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 fields
  • liquidate — call sites that need include_liquidation_price