get_l2_book
Retrieve the Level 2 order book for a specific cryptocurrency token on the Hyperliquid exchange to analyze market depth and liquidity.
Instructions
Get the L2 book of a token on Hyperliquid
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| required | No | ||
| symbol | No | The symbol of the token to get the price of |
Implementation Reference
- src/actions.ts:5-16 (handler)The main handler function that validates the input arguments using l2BookSchema and fetches the L2 book data from the Hyperliquid client, returning it as JSON text.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/schemas.ts:18-31 (schema)Zod schema used for input validation in the getL2Book handler, transforming 'symbol' to 'coin' and handling optional nSigFigs and mantissa parameters.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/tools.ts:40-53 (schema)MCP Tool object definition for get_l2_book, including the JSON inputSchema advertised to clients.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)Registration of the get_l2_book tool in the switch statement of the CallToolRequest handler, dispatching to the getL2Book function.case "get_l2_book": { return await getL2Book(hyperliquidClient, args); }
- src/index.ts:75-80 (registration)Registration in the ListToolsRequest handler, including L2_BOOK_TOOL in the list of available tools.server.setRequestHandler(ListToolsRequestSchema, async () => { console.error("Received ListToolsRequest"); return { tools: [ALL_MIDS_TOOL, CANDLE_SNAPSHOT_TOOL, L2_BOOK_TOOL], }; });