get_user_trade_history
Retrieve trade history for a Hyperliquid account to analyze past transactions, view trade details including symbol, size, price, and timestamps.
Instructions
Fetch the trade fill history for a specific user account.
Parameters:
account_address (str): The Hyperliquid account address (e.g., '0xcd5051944f780a621ee62e39e493c489668acf4d').
ctx (Context): The MCP context object for accessing server state.
Returns:
str: A JSON string containing a list of trade fills, each with details such as symbol, size, price, timestamp,
and trade ID. Returns a JSON string with an error message if the query fails.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_address | Yes |
Input Schema (JSON Schema)
{
"properties": {
"account_address": {
"title": "Account Address",
"type": "string"
}
},
"required": [
"account_address"
],
"type": "object"
}
Implementation Reference
- main.py:84-102 (handler)The handler function for the 'get_user_trade_history' tool. It is decorated with @mcp.tool() for registration in the FastMCP server. The function fetches the user's trade fills using the Hyperliquid Info SDK's user_fills method and returns the data as a JSON string, handling errors appropriately. The function signature and docstring define the input schema and output format.@mcp.tool() async def get_user_trade_history(account_address: str, ctx: Context) -> str: """ Fetch the trade fill history for a specific user account. Parameters: account_address (str): The Hyperliquid account address (e.g., '0xcd5051944f780a621ee62e39e493c489668acf4d'). ctx (Context): The MCP context object for accessing server state. Returns: str: A JSON string containing a list of trade fills, each with details such as symbol, size, price, timestamp, and trade ID. Returns a JSON string with an error message if the query fails. """ try: fills = info.user_fills(account_address) return json.dumps(fills) except Exception as e: return json.dumps({"error": f"Failed to fetch user fills: {str(e)}"})
- main.py:392-397 (helper)A helper prompt function 'analyze_positions' that instructs the use of the 'get_user_trade_history' tool among others for analyzing user trading positions.base.UserMessage(f"Please analyze the trading positions for account {account_address}:"), base.UserMessage("Use the get_user_state, get_user_open_orders, get_user_trade_history, get_user_funding_history, and get_user_fees tools to fetch data."), base.AssistantMessage( "I'll analyze the user's trading positions, open orders, trade history, funding payments, and fees to provide insights on risk and performance." ) ]