Skip to main content
Glama
gagarinyury

MCP Bitget Trading Server

by gagarinyury

subscribeToOrderBook

Subscribe to real-time order book updates for cryptocurrency trading pairs to monitor market depth and price levels.

Instructions

Subscribe to real-time order book updates

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesTrading pair symbol
instTypeNoInstrument type (default: SPOT)

Implementation Reference

  • Handler for the subscribeToOrderBook MCP tool. Extracts symbol and optional instType from arguments, subscribes to the 'books' WebSocket channel via wsClient, and returns a confirmation message.
    case 'subscribeToOrderBook': {
      const { symbol, instType = 'SPOT' } = args as any;
      this.wsClient.subscribe('books', symbol, instType);
      return {
        content: [
          {
            type: 'text',
            text: `Subscribed to order book updates for ${symbol} (${instType})`,
          },
        ],
      } as CallToolResult;
    }
  • src/server.ts:269-280 (registration)
    Registration of the subscribeToOrderBook tool in the listTools response, including name, description, and input schema definition.
    {
      name: 'subscribeToOrderBook',
      description: 'Subscribe to real-time order book updates',
      inputSchema: {
        type: 'object',
        properties: {
          symbol: { type: 'string', description: 'Trading pair symbol' },
          instType: { type: 'string', enum: ['SPOT', 'UMCBL'], description: 'Instrument type (default: SPOT)' }
        },
        required: ['symbol']
      },
    },
  • Core subscribe helper method in BitgetWebSocketClient. Constructs and sends the WebSocket subscription message (op: 'subscribe') for the given channel ('books' for order book), tracks subscriptions for automatic resubscribe on reconnect.
    subscribe(channel: string, symbol: string, instType: 'SPOT' | 'UMCBL' | 'DMCBL' = 'SPOT'): void {
      const subscription: WSSubscription = {
        op: 'subscribe',
        args: [{
          instType,
          channel,
          instId: symbol
        }]
      };
    
      const subKey = `${instType}:${channel}:${symbol}`;
      this.subscriptions.add(subKey);
    
      if (this.isConnected && this.ws) {
        logger.debug('Subscribing to channel', { channel, symbol, instType });
        this.ws.send(JSON.stringify(subscription));
      } else {
        logger.warn('WebSocket not connected, subscription will be sent on reconnect', { channel, 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/gagarinyury/MCP-bitget-trading'

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