get_orderbook
Retrieve current Hyperliquid L2 orderbook snapshot with bids, asks, mid price, and spread. Optionally specify depth for number of price levels per side.
Instructions
Get the current Hyperliquid L2 orderbook snapshot for a coin. Returns bids, asks, mid price, and spread. Optionally specify depth (price levels per side). Requires Pro tier or higher for full depth.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coin | Yes | Coin/market symbol, e.g. 'BTC', 'ETH', 'SOL' | |
| depth | No | Orderbook depth — number of price levels per side |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | Result data object |
Implementation Reference
- src/index.ts:478-485 (registration)Registration of the 'get_orderbook' tool via the registerOrderbookTool helper. It binds the Hyperliquid orderbook SDK call, uses CoinParam schema (uppercased string), passes optional depth param, and normalizes coin to uppercase.
// 2. Current Orderbook registerOrderbookTool( "get_orderbook", "Get the current Hyperliquid L2 orderbook snapshot for a coin. Returns bids, asks, mid price, and spread. Optionally specify depth (price levels per side). Requires Pro tier or higher for full depth.", (coin, params) => api().hyperliquid.orderbook.get(coin, params), CoinParam, normalizeHLCoin ); - src/index.ts:53-55 (schema)Input schema for the coin parameter: a simple string describing the market symbol.
const CoinParam = z .string() .describe("Coin/market symbol, e.g. 'BTC', 'ETH', 'SOL'"); - src/index.ts:98-101 (schema)Optional depth parameter schema used by get_orderbook to limit price levels per side.
const DepthParam = z .number() .optional() .describe("Orderbook depth — number of price levels per side"); - src/index.ts:386-405 (helper)Helper function registerOrderbookTool that encapsulates the common pattern for orderbook tools. Takes an SDK call, coin schema, and normalization function; passes optional depth param; formats the response as a single object.
// Pattern 3: Orderbook snapshot (coin + optional depth) function registerOrderbookTool( name: string, description: string, sdkCall: (coin: string, params?: { depth?: number }) => Promise<unknown>, coinSchema: z.ZodString, normFn: (coin: string) => string ): void { registerTool( name, description, { coin: coinSchema, depth: DepthParam }, ObjectOutputSchema, async (params) => { const sdkParams = params.depth ? { depth: params.depth } : undefined; const data = await sdkCall(normFn(params.coin), sdkParams); return formatResponse(data); } ); } - src/index.ts:139-141 (schema)Output schema for orderbook (and other single-object) tools: returns a 'data' key with the result object.
const ObjectOutputSchema: ZodRawShape = { data: z.record(z.unknown()).describe("Result data object"), };