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
| Name | Required | Description | Default |
|---|---|---|---|
| exchangeId | Yes | Exchange ID (e.g., 'binance', 'coinbase') | |
| symbol | Yes | Trading symbol (e.g., 'BTC/USDT') | |
| limit | No | Limit the number of orders returned (optional) |
Implementation Reference
- src/tools/market-tools.ts:129-154 (handler)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 }; } }
- src/tools/market-tools.ts:124-128 (schema)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)") },
- src/tools/market-tools.ts:121-155 (registration)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);