Skip to main content
Glama

fetchOrderBook

Retrieve real-time order book data for cryptocurrency trading pairs from exchanges like Binance or Coinbase to analyze market depth and liquidity.

Instructions

Fetch order book for a symbol on an exchange

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exchangeIdYesExchange ID (e.g., 'binance', 'coinbase')
symbolYesTrading symbol (e.g., 'BTC/USDT')
limitNoLimit the number of orders returned (optional)

Implementation Reference

  • The core handler function for the fetchOrderBook tool. It retrieves a public CCXT exchange instance, calls fetchOrderBook on the specified symbol with optional limit, and returns the order book as formatted JSON or an error message.
    async ({ exchangeId, symbol, limit }) => {
      try {
        // 공개 인스턴스 사용
        const exchange = ccxtServer.getPublicExchangeInstance(exchangeId);
        const orderbook = await exchange.fetchOrderBook(symbol, limit);
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(orderbook, null, 2)
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error fetching order book: ${(error as Error).message}`
            }
          ],
          isError: true
        };
      }
    }
  • Input schema definition using Zod for validating parameters: exchangeId (string), symbol (string), limit (optional number).
    {
      exchangeId: z.string().describe("Exchange ID (e.g., 'binance', 'coinbase')"),
      symbol: z.string().describe("Trading symbol (e.g., 'BTC/USDT')"),
      limit: z.number().optional().describe("Limit the number of orders returned (optional)")
    },
  • Registration of the fetchOrderBook tool on the MCP server within the registerMarketTools function, including name, description, input schema, and handler.
    server.tool(
      "fetchOrderBook",
      "Fetch order book for a symbol on an exchange",
      {
        exchangeId: z.string().describe("Exchange ID (e.g., 'binance', 'coinbase')"),
        symbol: z.string().describe("Trading symbol (e.g., 'BTC/USDT')"),
        limit: z.number().optional().describe("Limit the number of orders returned (optional)")
      },
      async ({ exchangeId, symbol, limit }) => {
        try {
          // 공개 인스턴스 사용
          const exchange = ccxtServer.getPublicExchangeInstance(exchangeId);
          const orderbook = await exchange.fetchOrderBook(symbol, limit);
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(orderbook, null, 2)
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error fetching order book: ${(error as Error).message}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • src/server.ts:372-372 (registration)
    Invocation of registerMarketTools in the CcxtMcpServer's registerTools method, which registers the fetchOrderBook tool (among others) to the main MCP server instance.
    registerMarketTools(this.server, this);
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't describe how it behaves: no information about rate limits, authentication requirements, error handling, response format, or whether it's a read-only operation. For a tool fetching financial data, this leaves significant gaps in understanding its operational characteristics.

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 a single, efficient sentence that states exactly what the tool does with zero wasted words. It's appropriately sized for a straightforward data-fetching tool and front-loads the core functionality without unnecessary elaboration.

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

Completeness2/5

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

Given the complexity of financial data fetching and the absence of both annotations and an output schema, the description is insufficiently complete. It doesn't explain what an order book contains (bids/asks), how the data is structured, whether real-time or historical, or any limitations. For a tool in a trading context with 3 parameters and no structured behavioral hints, more context is needed.

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?

The description doesn't add any parameter information beyond what's already in the schema, which has 100% coverage with clear descriptions for all three parameters. The baseline is 3 since the schema adequately documents exchangeId, symbol, and limit. No additional semantic context is provided about parameter constraints or usage patterns.

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

Purpose4/5

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

The description clearly states the action ('Fetch') and resource ('order book for a symbol on an exchange'), making the purpose immediately understandable. It distinguishes from siblings like fetchTicker or fetchTrades by specifying the order book resource. However, it doesn't explicitly differentiate from fetchMarkets or fetchOHLCV in terms of data type, which prevents a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose fetchOrderBook over fetchTicker for price data, fetchTrades for recent transactions, or fetchOpenOrders for user-specific orders. There's also no context about prerequisites like authentication or exchange availability.

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/lazy-dinosaur/ccxt-mcp'

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