getOrderBook
Retrieve real-time order book data for a specified trading pair, including market depth, to analyze liquidity and price levels on Bitget cryptocurrency exchange.
Instructions
Get order book (market depth) for a trading pair
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| depth | No | Order book depth (default: 20) | |
| symbol | Yes | Trading pair symbol |
Implementation Reference
- src/server.ts:340-351 (handler)MCP tool handler for 'getOrderBook': parses input using GetOrderBookSchema, calls BitgetRestClient.getOrderBook(), returns JSON-formatted order book data.case 'getOrderBook': { const { symbol, depth = 20 } = GetOrderBookSchema.parse(args); const orderBook = await this.bitgetClient.getOrderBook(symbol, depth); return { content: [ { type: 'text', text: JSON.stringify(orderBook, null, 2), }, ], } as CallToolResult; }
- src/types/mcp.ts:17-20 (schema)Zod schema defining input parameters for getOrderBook tool: symbol (required string), depth (optional number). Used for validation in handler.export const GetOrderBookSchema = z.object({ symbol: z.string().describe('Trading pair symbol (BTCUSDT for spot, BTCUSDT_UMCBL for futures)'), depth: z.number().optional().describe('Order book depth (default: 20)') });
- src/server.ts:125-136 (registration)Tool registration in listTools handler: defines name, description, and JSON schema for getOrderBook input.{ name: 'getOrderBook', description: 'Get order book (market depth) for a trading pair', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: 'Trading pair symbol' }, depth: { type: 'number', description: 'Order book depth (default: 20)' } }, required: ['symbol'] }, },
- src/api/rest-client.ts:411-460 (helper)Core implementation in BitgetRestClient: fetches order book from appropriate API endpoint (spot or futures based on symbol), handles caching, formats response as OrderBook.async getOrderBook(symbol: string, depth: number = 20): Promise<OrderBook> { const cacheKey = `orderbook:${symbol}:${depth}`; // Try cache first const cachedOrderBook = orderbookCache.get(cacheKey); if (cachedOrderBook) { return cachedOrderBook; } let orderBook: OrderBook = { symbol: '', bids: [], asks: [], timestamp: 0 }; if (this.isFuturesSymbol(symbol)) { // Futures orderbook const futuresSymbol = symbol.includes('_UMCBL') ? symbol : `${symbol}_UMCBL`; const response = await this.request<any>('GET', '/api/mix/v1/market/depth', { symbol: futuresSymbol, limit: depth.toString() }); orderBook = { symbol: futuresSymbol, bids: response.data?.bids || [], asks: response.data?.asks || [], timestamp: response.data?.timestamp || Date.now() }; } else { // Spot orderbook const response = await this.request<any>('GET', '/api/v2/spot/market/orderbook', { symbol, type: 'step0', limit: depth.toString() }); orderBook = { symbol, bids: response.data?.bids || [], asks: response.data?.asks || [], timestamp: response.data?.ts || Date.now() }; } // Cache the result orderbookCache.set(cacheKey, orderBook); return orderBook; }