get_order_book
Fetch real-time order book data for Binance cryptocurrency trading pairs, including price levels and quantities, to analyze market depth and liquidity efficiently.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Order book depth, default 100, max 5000 | |
| symbol | Yes | Trading pair symbol, e.g. BTCUSDT |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"limit": {
"description": "Order book depth, default 100, max 5000",
"type": "number"
},
"symbol": {
"description": "Trading pair symbol, e.g. BTCUSDT",
"type": "string"
}
},
"required": [
"symbol"
],
"type": "object"
}
Implementation Reference
- src/index.ts:20-38 (handler)The handler function for the 'get_order_book' tool. It makes an HTTP GET request to Binance's /api/v3/depth endpoint with the provided symbol and optional limit parameters, fetches the order book data, and returns it as formatted JSON. Handles errors by returning an error message.async (args: { symbol: string; limit?: number }) => { try { const response = await axios.get(`${BASE_URL}/api/v3/depth`, { params: { symbol: args.symbol, limit: args.limit }, proxy: getProxy(), }); return { content: [{ type: "text", text: JSON.stringify(response.data, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Failed to get order book: ${error.message}` }], isError: true }; } }
- src/index.ts:17-19 (schema)Zod schema defining the input parameters for the 'get_order_book' tool: 'symbol' (required string, e.g., BTCUSDT) and 'limit' (optional number, default 100, max 5000).symbol: z.string().describe("Trading pair symbol, e.g. BTCUSDT"), limit: z.number().optional().describe("Order book depth, default 100, max 5000") },
- src/index.ts:15-39 (registration)Registration of the 'get_order_book' tool using McpServer's tool() method, specifying the tool name, input schema, and handler function."get_order_book", { symbol: z.string().describe("Trading pair symbol, e.g. BTCUSDT"), limit: z.number().optional().describe("Order book depth, default 100, max 5000") }, async (args: { symbol: string; limit?: number }) => { try { const response = await axios.get(`${BASE_URL}/api/v3/depth`, { params: { symbol: args.symbol, limit: args.limit }, proxy: getProxy(), }); return { content: [{ type: "text", text: JSON.stringify(response.data, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Failed to get order book: ${error.message}` }], isError: true }; } } );