get_orderbook
Retrieve real-time bid and ask price levels for perpetual markets on Hyperliquid exchange to analyze market depth and liquidity.
Instructions
Get the orderbook (bids and asks) for a perpetual market
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Market symbol (e.g. BTC, ETH) | |
| depth | No | Number of price levels (default 10) |
Implementation Reference
- src/hyperliquid_mcp/client.py:86-92 (handler)The main handler implementation of get_orderbook. Retrieves the L2 orderbook snapshot from Hyperliquid API, extracts bid/ask levels, and formats them into a clean dictionary response with price and size for each level.
def get_orderbook(self, symbol: str, depth: int = 10) -> dict[str, Any]: """Get orderbook for a market.""" book = self.info.l2_snapshot(symbol.upper()) levels = book.get("levels", [[], []]) bids = [{"price": b["px"], "size": b["sz"]} for b in levels[0][:depth]] asks = [{"price": a["px"], "size": a["sz"]} for a in levels[1][:depth]] return {"symbol": symbol.upper(), "bids": bids, "asks": asks} - src/hyperliquid_mcp/server.py:43-54 (registration)Registration of the get_orderbook tool in the MCP server. Defines the tool name, description, and input schema with symbol (required string) and depth (optional integer with default 10) parameters.
Tool( name="get_orderbook", description="Get the orderbook (bids and asks) for a perpetual market", inputSchema={ "type": "object", "properties": { "symbol": {"type": "string", "description": "Market symbol (e.g. BTC, ETH)"}, "depth": {"type": "integer", "description": "Number of price levels (default 10)", "default": 10}, }, "required": ["symbol"], }, ), - src/hyperliquid_mcp/server.py:139-140 (registration)Dispatch handler that routes get_orderbook tool calls to the client method. Extracts symbol and optional depth arguments and calls client.get_orderbook() with the appropriate parameters.
case "get_orderbook": return client.get_orderbook(args["symbol"], args.get("depth", 10))