Skip to main content
Glama
gagarinyury

MCP Bitget Trading Server

by gagarinyury

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
NameRequiredDescriptionDefault
depthNoOrder book depth (default: 20)
symbolYesTrading pair symbol

Implementation Reference

  • 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; }
  • 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'] }, },
  • 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; }

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/gagarinyury/MCP-bitget-trading'

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