get_l2_book
Retrieve the Level 2 order book for a specific token on Hyperliquid to analyze market depth and liquidity.
Instructions
Get the L2 book of a token on Hyperliquid
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | No | The symbol of the token to get the price of | |
| required | No |
Implementation Reference
- src/actions.ts:5-16 (handler)The handler function that executes the get_l2_book tool: parses args with l2BookSchema, fetches L2 book data from Hyperliquid client, stringifies to JSON, and returns as MCP content block.export async function getL2Book( hyperliquidClient: PublicClient, args: unknown ) { const validatedArgs = l2BookSchema.parse(args); let l2Book = await hyperliquidClient.l2Book(validatedArgs); return { content: [{ type: "text", text: JSON.stringify(l2Book) }], isError: false, }; }
- src/tools.ts:40-53 (schema)Defines the MCP Tool schema for get_l2_book, including name, description, and inputSchema requiring a 'symbol' string.export const L2_BOOK_TOOL: Tool = { name: "get_l2_book", description: "Get the L2 book of a token on Hyperliquid", inputSchema: { type: "object", properties: { symbol: { type: "string", description: "The symbol of the token to get the price of", }, required: ["symbol"], }, }, };
- src/index.ts:43-45 (registration)Registers the getL2Book handler for the 'get_l2_book' tool name in the CallToolRequest switch statement.case "get_l2_book": { return await getL2Book(hyperliquidClient, args); }
- src/schemas.ts:18-31 (schema)Zod schema used in the handler for input validation and transformation (symbol to coin, optional nSigFigs and mantissa).export const l2BookSchema = z .object({ symbol: z.string(), nSigFigs: z .union([z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.null()]) .optional(), mantissa: z.union([z.literal(2), z.literal(5), z.null()]).optional(), }) .strict() .transform((data) => ({ coin: data.symbol, nSigFigs: data.nSigFigs, mantissa: data.mantissa, }));
- src/index.ts:78-79 (registration)The get_l2_book tool (as L2_BOOK_TOOL) is registered/returned in the ListToolsRequest handler.tools: [ALL_MIDS_TOOL, CANDLE_SNAPSHOT_TOOL, L2_BOOK_TOOL], };