Skip to main content
Glama

get_hip4_orderbook_history

Read-onlyIdempotent

Retrieve historical L2 orderbook snapshots for HIP-4 outcome-market coins over a specified time range, with configurable depth and pagination.

Instructions

Get historical HIP-4 L2 orderbook snapshots for a coin (e.g. '0'). Bare numeric coins are canonical; legacy '#0' / '%230' forms are also accepted.Returns L2 snapshots over a time range. Pro+ tier required.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
coinYesHIP-4 outcome-market coin symbol. Canonical form is the bare numeric '<10*outcome_id + side>' (e.g. '0' for outcome 0 Yes, '1' for outcome 0 No, '10' for outcome 1 Yes). The legacy '#0' and '%230' forms are also accepted. Use get_hip4_instruments to list all.
startNoStart timestamp (Unix ms or ISO). Defaults to 24h ago.
endNoEnd timestamp (Unix ms or ISO). Defaults to now.
limitNoMax records to return (default 100, max 1000)
cursorNoPagination cursor from previous response's nextCursor
depthNoOrderbook depth — number of price levels per side

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
recordsYesArray of result records
countYesTotal number of records in the full result set
nextCursorNoCursor for next page, if more results available

Implementation Reference

  • src/index.ts:1637-1657 (registration)
    Registration of the 'get_hip4_orderbook_history' tool via registerTool(). It uses Hip4CoinParam for coin input, HistoryParams for time range, and DepthParam for optional depth. The handler builds query params via buildHistoryQuery() and calls hip4Request() against the REST API endpoint '/orderbook/{coin}/history'.
    // HIP-4 Orderbook History
    registerTool(
      "get_hip4_orderbook_history",
      "Get historical HIP-4 L2 orderbook snapshots for a coin (e.g. '0'). Bare numeric coins are canonical; legacy '#0' / '%230' forms are also accepted.Returns L2 snapshots over a time range. Pro+ tier required.",
      {
        coin: Hip4CoinParam,
        ...HistoryParams,
        depth: DepthParam,
      },
      ListOutputSchema,
      async (params) => {
        const q = buildHistoryQuery(params.start, params.end, params.limit, params.cursor, {
          depth: params.depth,
        });
        const result = await hip4Request(
          `/orderbook/${normalizeHip4Coin(params.coin)}/history`,
          q
        );
        return formatCursorResponse(result);
      }
    );
  • The handler function for get_hip4_orderbook_history. It calls buildHistoryQuery() to construct time-range/limit/cursor/depth params, then makes a GET request to `/orderbook/{coin}/history` via hip4Request(), and formats the response via formatCursorResponse().
    async (params) => {
      const q = buildHistoryQuery(params.start, params.end, params.limit, params.cursor, {
        depth: params.depth,
      });
      const result = await hip4Request(
        `/orderbook/${normalizeHip4Coin(params.coin)}/history`,
        q
      );
      return formatCursorResponse(result);
    }
  • hip4Request() is the helper that makes authenticated GET requests to the HIP-4 REST API (api.0xarchive.io) with the X-API-Key header. It handles 60s timeout, JSON parsing, error handling including OxArchiveError generation, and returns { data, nextCursor } objects.
    async function hip4Request(
      path: string,
      query?: Record<string, unknown>
    ): Promise<{ data: unknown; nextCursor?: string }> {
      const url = new URL(`${HIP4_BASE_PATH}${path}`, HIP4_BASE_URL);
      if (query) {
        for (const [k, v] of Object.entries(query)) {
          if (v === undefined || v === null) continue;
          url.searchParams.set(k, String(v));
        }
      }
      const headers: Record<string, string> = {
        "Content-Type": "application/json",
        "User-Agent": "0xarchive-mcp/1.9.0",
      };
      if (apiKey) headers["X-API-Key"] = apiKey;
    
      const controller = new AbortController();
      const timeout = setTimeout(() => controller.abort(), 60000);
      try {
        const response = await fetch(url.toString(), {
          method: "GET",
          headers,
          signal: controller.signal,
        });
        const text = await response.text();
        let body: any;
        try {
          body = text ? JSON.parse(text) : null;
        } catch {
          body = text;
        }
        if (!response.ok) {
          const requestId =
            response.headers.get("x-request-id") || body?.meta?.requestId;
          const message =
            (body && (body.error?.message || body.error || body.message)) ||
            `HTTP ${response.status}`;
          throw new OxArchiveError(message, response.status, requestId ?? undefined);
        }
        if (body && typeof body === "object" && "data" in body) {
          return {
            data: body.data,
            nextCursor: body.meta?.nextCursor,
          };
        }
        return { data: body };
      } finally {
        clearTimeout(timeout);
      }
    }
  • buildHistoryQuery() helper constructs the query parameters for paginated history endpoints. It resolves start/end timestamps via resolveTimeRange(), applies default limit=100, adds cursor if present, and merges extra parameters (like depth).
    function buildHistoryQuery(
      start?: number | string,
      end?: number | string,
      limit?: number,
      cursor?: string,
      extra?: Record<string, unknown>
    ): Record<string, unknown> {
      const range = resolveTimeRange(start, end);
      const q: Record<string, unknown> = {
        start: range.start,
        end: range.end,
        limit: resolveLimit(limit),
      };
      if (cursor) q.cursor = cursor;
      if (extra) {
        for (const [k, v] of Object.entries(extra)) {
          if (v !== undefined) q[k] = v;
        }
      }
      return q;
    }
  • Hip4CoinParam: Zod schema for HIP-4 coin symbols. Accepts bare numeric form (e.g., '0'), or legacy '#0' / '%230' forms.
    const Hip4CoinParam = z
      .string()
      .describe(
        "HIP-4 outcome-market coin symbol. Canonical form is the bare numeric '<10*outcome_id + side>' (e.g. '0' for outcome 0 Yes, '1' for outcome 0 No, '10' for outcome 1 Yes). The legacy '#0' and '%230' forms are also accepted. Use get_hip4_instruments to list all."
      );
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true, destructiveHint=false, idempotentHint=true, and openWorldHint=true, indicating safe, idempotent reads. The description adds behavioral context: it returns L2 snapshots over a time range, accepts legacy coin formats, and requires Pro+ tier. This supplements the annotations without contradiction.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded: three sentences cover purpose, coin format, and tier requirement. No extraneous text. Every sentence earns its place, providing essential information without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the existence of an output schema and comprehensive annotations, the description is complete. It mentions the key functionality (historical L2 snapshots, time range, coin formats, tier). Pagination and parameter defaults are covered in the schema. The description covers all essential aspects for an agent to use the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the parameters are fully documented in the schema. The description echoes the coin format details already present in the schema, adding no new semantic information. As per guidelines, baseline 3 is appropriate as the description does not enhance parameter understanding beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get historical HIP-4 L2 orderbook snapshots for a coin'. It specifies the resource (L2 orderbook snapshots), action (historical retrieval), and scope (HIP-4, specific coin). The mention of coin formats and Pro+ tier further clarifies the domain. The name and description effectively distinguish it from similar tools like get_hip4_orderbook (current) and get_hip4_l4_orderbook_history (L4).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides context on when to use the tool: for historical L2 snapshots, with specific coin format guidance ('Bare numeric coins are canonical; legacy forms accepted') and tier requirement ('Pro+ tier required'). However, it does not explicitly compare to siblings like get_hip4_orderbook (for current snapshot) or get_hip4_l4_orderbook_history (for L4), which would improve guidance. The recommendations are clear enough for a straightforward read tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/0xArchiveIO/0xarchive-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server