fetchOrderBook
Retrieve real-time order book data for a specific trading symbol on a cryptocurrency exchange using specified exchange ID and optional limit. Enables informed trading decisions through MCP server integration.
Instructions
Fetch order book for a symbol on an exchange
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| exchangeId | Yes | Exchange ID (e.g., 'binance', 'coinbase') | |
| limit | No | Limit the number of orders returned (optional) | |
| symbol | Yes | Trading symbol (e.g., 'BTC/USDT') |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"exchangeId": {
"description": "Exchange ID (e.g., 'binance', 'coinbase')",
"type": "string"
},
"limit": {
"description": "Limit the number of orders returned (optional)",
"type": "number"
},
"symbol": {
"description": "Trading symbol (e.g., 'BTC/USDT')",
"type": "string"
}
},
"required": [
"exchangeId",
"symbol"
],
"type": "object"
}
Implementation Reference
- src/tools/market-tools.ts:129-154 (handler)The handler function that fetches the order book data from the CCXT exchange instance for the given symbol and optional limit, formats it as JSON text response or returns an error.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)Zod input schema defining parameters for the fetchOrderBook tool: 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)Full registration of the fetchOrderBook MCP tool via server.tool(), specifying name, description, input schema, and inline handler function.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)Top-level call to registerMarketTools within the CcxtMcpServer's registerTools method, which includes registering the fetchOrderBook tool.registerMarketTools(this.server, this);