Skip to main content
Glama
gagarinyury

MCP Bitget Trading Server

by gagarinyury

getOrderBook

Retrieve real-time market depth and order book data for cryptocurrency trading pairs on Bitget exchange to analyze buy/sell pressure and liquidity.

Instructions

Get order book (market depth) for a trading pair

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesTrading pair symbol
depthNoOrder book depth (default: 20)

Implementation Reference

  • MCP tool handler for getOrderBook: parses input with schema, calls BitgetRestClient.getOrderBook, returns JSON response
    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/server.ts:126-136 (registration)
    Tool registration in ListTools handler: defines name, description, and input schema for getOrderBook
      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']
      },
    },
  • Zod schema for validating getOrderBook tool input parameters
    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)')
    });
  • Core implementation of getOrderBook in BitgetRestClient: handles spot/futures detection, caching, API requests to Bitget endpoints, parses order book data
    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