Skip to main content
Glama
ethancod1ng
by ethancod1ng

get_orderbook

Retrieve real-time order book depth data for specified trading pairs from Binance to analyze market liquidity and price levels.

Instructions

获取订单簿深度数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo深度限制,默认100
symbolYes交易对符号,如 BTCUSDT

Implementation Reference

  • The main handler function for the 'get_orderbook' tool. It validates the input using GetOrderBookSchema, fetches the order book data from the Binance client, slices and maps the bids and asks to the requested limit, and returns formatted data with timestamp. Handles errors using handleBinanceError.
    handler: async (binanceClient: any, args: unknown) => { const input = validateInput(GetOrderBookSchema, args); validateSymbol(input.symbol); try { const orderBook = await binanceClient.book({ symbol: input.symbol, limit: input.limit, }); return { symbol: input.symbol, lastUpdateId: orderBook.lastUpdateId, bids: orderBook.bids.slice(0, input.limit).map((bid: any) => ({ price: bid.price, quantity: bid.quantity, })), asks: orderBook.asks.slice(0, input.limit).map((ask: any) => ({ price: ask.price, quantity: ask.quantity, })), timestamp: Date.now(), }; } catch (error) { handleBinanceError(error); } },
  • Zod schema definition for GetOrderBook input validation, used in the handler to parse and validate arguments: requires symbol (string), optional limit (number, default 100).
    export const GetOrderBookSchema = z.object({ symbol: z.string().describe('交易对符号,如 BTCUSDT'), limit: z.number().optional().default(100).describe('深度限制,默认100'), });
  • Tool registration within marketDataTools array: defines name 'get_orderbook', description, JSON inputSchema compatible with MCP, and references the handler function.
    { name: 'get_orderbook', description: '获取订单簿深度数据', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: '交易对符号,如 BTCUSDT', }, limit: { type: 'number', description: '深度限制,默认100', default: 100, }, }, required: ['symbol'], }, handler: async (binanceClient: any, args: unknown) => { const input = validateInput(GetOrderBookSchema, args); validateSymbol(input.symbol); try { const orderBook = await binanceClient.book({ symbol: input.symbol, limit: input.limit, }); return { symbol: input.symbol, lastUpdateId: orderBook.lastUpdateId, bids: orderBook.bids.slice(0, input.limit).map((bid: any) => ({ price: bid.price, quantity: bid.quantity, })), asks: orderBook.asks.slice(0, input.limit).map((ask: any) => ({ price: ask.price, quantity: ask.quantity, })), timestamp: Date.now(), }; } catch (error) { handleBinanceError(error); } }, },

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/ethancod1ng/binance-mcp-server'

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