Skip to main content
Glama

get_orderbook

Retrieve current bid and ask price levels for cryptocurrency markets to analyze market depth and liquidity for trading decisions.

Instructions

Get the current orderbook (bid/ask levels) for a market.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesMarket symbol, e.g. "BTC-KRW"
depthNoNumber of price levels (default 20)

Implementation Reference

  • The handler function for get_orderbook tool that executes the tool logic. It makes an API GET request to fetch orderbook data for a specific market symbol with configurable depth, then returns the data as JSON text content.
    async ({ symbol, depth }) => {
      const data = await apiGet<unknown>(`/markets/${symbol}/orderbook?depth=${depth}`);
      return {
        content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
      };
    }
  • Zod schema definition for get_orderbook tool inputs: 'symbol' (required string, e.g., 'BTC-KRW') and 'depth' (optional number with default value 20 for number of price levels).
    {
      symbol: z.string().describe('Market symbol, e.g. "BTC-KRW"'),
      depth: z.number().optional().default(20).describe("Number of price levels (default 20)"),
    },
  • src/index.ts:322-335 (registration)
    Complete registration of get_orderbook tool with the MCP server using server.tool(). Includes tool name, description, schema, and handler function.
    server.tool(
      "get_orderbook",
      "Get the current orderbook (bid/ask levels) for a market.",
      {
        symbol: z.string().describe('Market symbol, e.g. "BTC-KRW"'),
        depth: z.number().optional().default(20).describe("Number of price levels (default 20)"),
      },
      async ({ symbol, depth }) => {
        const data = await apiGet<unknown>(`/markets/${symbol}/orderbook?depth=${depth}`);
        return {
          content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
        };
      }
    );
  • The apiGet helper function used by get_orderbook handler to make authenticated HTTP GET requests to the API. Handles response validation and error handling.
    async function apiGet<T>(path: string): Promise<T> {
      const res = await fetch(`${API_BASE}${path}`, {
        headers: getAuthHeaders(),
      });
      if (!res.ok) {
        const text = await res.text();
        throw new Error(`API GET ${path} failed (${res.status}): ${text}`);
      }
      return res.json() as Promise<T>;
    }

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/mikusnuz/pexbot-mcp'

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