Skip to main content
Glama

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
NameRequiredDescriptionDefault
symbolYesTrading pair (BTC, ETHUSDT, etc.)

Implementation Reference

  • 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}` };
      }
    }
  • 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);

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/ShipItAndPray/mcp-market-data'

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