get_l2_snapshot
Fetch Level 2 order book snapshots for cryptocurrency trading pairs to analyze market depth with bid and ask price data.
Instructions
Fetch the Level 2 order book snapshot for a specific coin.
Parameters:
coin_name (str): The trading symbol (e.g., 'BTC', 'ETH').
ctx (Context): The MCP context object for accessing server state.
Returns:
str: A JSON string containing the Level 2 order book snapshot, including bids and asks with prices and sizes.
Returns a JSON string with an error message if the query fails.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"coin_name": "<coin_name>"
},
"name": "get_l2_snapshot"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coin_name | Yes |
Implementation Reference
- main.py:172-189 (handler)The handler function for the 'get_l2_snapshot' tool. It is decorated with @mcp.tool(), which registers it in the FastMCP server. The function fetches the L2 order book snapshot using the Hyperliquid Info SDK and returns it as a JSON string, with error handling.
@mcp.tool() async def get_l2_snapshot(coin_name: str, ctx: Context) -> str: """ Fetch the Level 2 order book snapshot for a specific coin. Parameters: coin_name (str): The trading symbol (e.g., 'BTC', 'ETH'). ctx (Context): The MCP context object for accessing server state. Returns: str: A JSON string containing the Level 2 order book snapshot, including bids and asks with prices and sizes. Returns a JSON string with an error message if the query fails. """ try: data = info.l2_snapshot(coin_name) return json.dumps(data) except Exception as e: return json.dumps({"error": f"Failed to fetch L2 snapshot: {str(e)}"})