order_book
Retrieve live order book data showing top 20 bids and asks with spread to analyze market depth and liquidity for trading pairs.
Instructions
Get live order book — top 20 bids and asks with spread. Shows market depth and liquidity.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Trading pair (BTC, ETHUSDT, etc.) |
Implementation Reference
- index.js:101-120 (handler)Handler function that fetches and processes live order book data from Binance.
async function getOrderBook(symbol) { const pair = symbol.toUpperCase().replace('/', ''); const formatted = pair.includes('USDT') ? pair : pair + 'USDT'; try { const data = await fetch( `https://api.binance.us/api/v3/depth?symbol=${formatted}&limit=20` ); return { symbol: formatted, bids: data.bids.map(b => ({ price: parseFloat(b[0]), quantity: parseFloat(b[1]) })), asks: data.asks.map(a => ({ price: parseFloat(a[0]), quantity: parseFloat(a[1]) })), spread: parseFloat(data.asks[0][0]) - parseFloat(data.bids[0][0]), spread_pct: ((parseFloat(data.asks[0][0]) - parseFloat(data.bids[0][0])) / parseFloat(data.bids[0][0]) * 100).toFixed(4) + '%', mid_price: (parseFloat(data.asks[0][0]) + parseFloat(data.bids[0][0])) / 2, }; } catch (e) { return { error: `Could not fetch order book for ${formatted}: ${e.message}` }; } } - index.js:262-271 (schema)Tool registration and schema definition for 'order_book'.
name: 'order_book', description: 'Get live order book — top 20 bids and asks with spread. Shows market depth and liquidity.', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: 'Trading pair (BTC, ETHUSDT, etc.)' } }, required: ['symbol'] } }, - index.js:326-327 (registration)Switch case in handleToolCall that maps 'order_book' tool name to its handler.
case 'order_book': return await getOrderBook(args.symbol);