Skip to main content
Glama
gagarinyury

MCP Bitget Trading Server

by gagarinyury

unsubscribeFromChannel

Stop receiving real-time market data updates for a specific trading pair and channel on Bitget exchange. Specify channel type and symbol to end WebSocket subscriptions.

Instructions

Unsubscribe from a WebSocket channel

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channelYesChannel name (ticker, books, etc.)
symbolYesTrading pair symbol
instTypeNoInstrument type (default: SPOT)

Implementation Reference

  • Handler for unsubscribeFromChannel tool: parses arguments, calls wsClient.unsubscribe, and returns success message.
    case 'unsubscribeFromChannel': {
      const { channel, symbol, instType = 'SPOT' } = args as any;
      this.wsClient.unsubscribe(channel, symbol, instType);
      return {
        content: [
          {
            type: 'text',
            text: `Unsubscribed from ${channel} for ${symbol} (${instType})`,
          },
        ],
      } as CallToolResult;
    }
  • src/server.ts:281-293 (registration)
    Tool registration including name, description, and input schema definition in the listTools handler.
    {
      name: 'unsubscribeFromChannel',
      description: 'Unsubscribe from a WebSocket channel',
      inputSchema: {
        type: 'object',
        properties: {
          channel: { type: 'string', description: 'Channel name (ticker, books, etc.)' },
          symbol: { type: 'string', description: 'Trading pair symbol' },
          instType: { type: 'string', enum: ['SPOT', 'UMCBL'], description: 'Instrument type (default: SPOT)' }
        },
        required: ['channel', 'symbol']
      },
    },
  • Core unsubscribe implementation in BitgetWebSocketClient: constructs unsubscribe message, removes local subscription tracking, sends to WS if connected.
    unsubscribe(channel: string, symbol: string, instType: 'SPOT' | 'UMCBL' | 'DMCBL' = 'SPOT'): void {
      const subscription: WSSubscription = {
        op: 'unsubscribe',
        args: [{
          instType,
          channel,
          instId: symbol
        }]
      };
    
      const subKey = `${instType}:${channel}:${symbol}`;
      this.subscriptions.delete(subKey);
    
      if (this.isConnected && this.ws) {
        logger.debug('Unsubscribing from channel', { channel, symbol, instType });
        this.ws.send(JSON.stringify(subscription));
      }
    }

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