get_l2_orderbook_history
Retrieve Hyperliquid L2 orderbook history snapshots over a specified time range and coin. Get periodic aggregated orderbook data for analysis or backtesting.
Instructions
Get Hyperliquid L2 full-depth orderbook checkpoints (Build+ tier). Returns periodic aggregated orderbook snapshots over a time range.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coin | Yes | Coin/market symbol, e.g. 'BTC', 'ETH', 'SOL' | |
| start | No | Start timestamp (Unix ms or ISO). Defaults to 24h ago. | |
| end | No | End timestamp (Unix ms or ISO). Defaults to now. | |
| limit | No | Max records to return (default 100, max 1000) | |
| cursor | No | Pagination cursor from previous response's nextCursor | |
| depth | No | Orderbook depth — number of price levels per side |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| records | Yes | Array of result records | |
| count | Yes | Total number of records in the full result set | |
| nextCursor | No | Cursor for next page, if more results available |
Implementation Reference
- src/index.ts:1136-1145 (registration)Registration of the 'get_l2_orderbook_history' tool using the registerHistoryTool helper. It delegates to the SDK's hyperliquid.l2Orderbook.history() method with a coin parameter (normalized to uppercase), time range params, and an optional depth parameter. Uses the HistoryParams pattern for start/end/limit/cursor.
// Hyperliquid L2 Orderbook History registerHistoryTool( "get_l2_orderbook_history", "Get Hyperliquid L2 full-depth orderbook checkpoints (Build+ tier). Returns periodic aggregated orderbook snapshots over a time range.", (coin, params) => api().hyperliquid.l2Orderbook.history(coin, params as any), CoinParam, normalizeHLCoin, { depth: DepthParam } ); - src/index.ts:97-98 (schema)DepthParam schema used as optional input for the depth parameter in the L2 orderbook history tool.
const DepthParam = z - src/index.ts:113-122 (schema)HistoryParams shared schema providing start/end/limit/cursor fields used by the L2 orderbook history tool.
const HistoryParams = { start: TimestampParam.describe( "Start timestamp (Unix ms or ISO). Defaults to 24h ago." ), end: TimestampParam.describe( "End timestamp (Unix ms or ISO). Defaults to now." ), limit: LimitParam, cursor: CursorParam, }; - src/index.ts:129-136 (schema)Output schema for the L2 orderbook history tool, returning an array of records with count and optional pagination cursor.
const ListOutputSchema: ZodRawShape = { records: z.array(z.record(z.unknown())).describe("Array of result records"), count: z.number().describe("Total number of records in the full result set"), nextCursor: z .string() .optional() .describe("Cursor for next page, if more results available"), }; - src/index.ts:407-438 (helper)registerHistoryTool helper function that the L2 orderbook history tool uses. It builds the input schema with coin + HistoryParams + extraSchema, resolves time range, builds SDK params, calls the provided SDK function, and formats the cursor-paginated response.
// Pattern 4: History with cursor pagination (coin + time range) function registerHistoryTool( name: string, description: string, sdkCall: (coin: string, params: Record<string, unknown>) => Promise<{ data: unknown; nextCursor?: string }>, coinSchema: z.ZodString, normFn: (coin: string) => string, extraSchema?: ZodRawShape ): void { const schema: ZodRawShape = { coin: coinSchema, ...HistoryParams }; if (extraSchema) Object.assign(schema, extraSchema); registerTool(name, description, schema, ListOutputSchema, async (params) => { const { coin, start, end, limit, cursor, ...extra } = params; const timeRange = resolveTimeRange(start, end); const sdkParams: Record<string, unknown> = { ...timeRange, limit: resolveLimit(limit), }; if (cursor) sdkParams.cursor = cursor; // Pass through extra params (interval, side, etc.) for (const [k, v] of Object.entries(extra)) { if (v !== undefined) sdkParams[k] = v; } const result = await sdkCall(normFn(coin), sdkParams); return formatCursorResponse(result); }); }