Skip to main content
Glama
kukapay

hyperliquid-info-mcp

get_user_state

Retrieve user trading positions, margin details, and withdrawable balance from Hyperliquid to monitor account status and manage risk.

Instructions

Query user state including trading positions, margin, and withdrawable balance. Parameters: account_address (str): The Hyperliquid account address (e.g., '0xcd5051944f780a621ee62e39e493c489668acf4d'). check_spot (bool, optional): If True, queries spot user state; otherwise, queries perpetuals state. Defaults to False. ctx (Context, optional): The MCP context object for accessing server state. Returns: str: A JSON string containing the user state, including a list of positions (with symbol, size, entry_price, current_price, unrealized_pnl), margin_summary, and withdrawable balance. Returns a JSON string with an error message if the query fails.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_addressYes
check_spotNo

Implementation Reference

  • main.py:23-42 (handler)
    The handler function implementing the 'get_user_state' tool logic. It conditionally queries spot or perpetuals user state via the Hyperliquid Info API, serializes to JSON, and handles exceptions.
    @mcp.tool() async def get_user_state(account_address: str, check_spot: bool=False, ctx: Context=None) -> str: """ Query user state including trading positions, margin, and withdrawable balance. Parameters: account_address (str): The Hyperliquid account address (e.g., '0xcd5051944f780a621ee62e39e493c489668acf4d'). check_spot (bool, optional): If True, queries spot user state; otherwise, queries perpetuals state. Defaults to False. ctx (Context, optional): The MCP context object for accessing server state. Returns: str: A JSON string containing the user state, including a list of positions (with symbol, size, entry_price, current_price, unrealized_pnl), margin_summary, and withdrawable balance. Returns a JSON string with an error message if the query fails. """ try: user_state = info.spot_user_state(account_address) if check_spot else info.user_state(account_address) return json.dumps(user_state) except Exception as e: return json.dumps({"error": f"Failed to fetch user state: {str(e)}"})

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kukapay/hyperliquid-info-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server