Skip to main content
Glama
qeinfinity

Binance MCP Server

subscribe_market_data

Subscribe to real-time cryptocurrency market data from Binance for trading pairs, including spot and futures markets. Receive live updates on ticker prices, trades, order book depth, candlestick charts, and other market indicators through WebSocket streams.

Instructions

Subscribe to real-time market data updates

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesTrading pair symbol (e.g., BTCUSDT)
typeYesMarket type
streamsYesList of data streams to subscribe to

Implementation Reference

  • Tool handler that validates input parameters using isStreamParams, calls wsManager.subscribe to start WebSocket subscription, sets up a logging callback for stream data, and returns a success message.
    case "subscribe_market_data": {
      if (!isStreamParams(request.params.arguments)) {
        throw new Error('Invalid stream parameters');
      }
      const { symbol, type, streams } = request.params.arguments;
      wsManager.subscribe(symbol, type, streams);
      
      // Set up message handler
      wsManager.onStreamData(symbol, streams[0], (data: StreamEventData) => {
        // Handle real-time data updates
        logger.info(`Received WebSocket data for ${symbol}:`, data);
      });
    
      return {
        content: [{
          type: "text",
          text: `Successfully subscribed to ${streams.join(", ")} for ${symbol}`
        }]
      };
    }
  • src/index.ts:136-162 (registration)
    Tool registration in ListToolsRequestHandler, defining name, description, and input schema for validation.
    {
      name: "subscribe_market_data",
      description: "Subscribe to real-time market data updates",
      inputSchema: {
        type: "object",
        properties: {
          symbol: { 
            type: "string", 
            description: "Trading pair symbol (e.g., BTCUSDT)" 
          },
          type: { 
            type: "string", 
            enum: ["spot", "futures"], 
            description: "Market type" 
          },
          streams: {
            type: "array",
            items: {
              type: "string",
              enum: ["ticker", "trade", "kline", "depth", "forceOrder", "markPrice", "openInterest"]
            },
            description: "List of data streams to subscribe to"
          }
        },
        required: ["symbol", "type", "streams"]
      }
    }
  • TypeScript interface defining the input parameters for the subscribe_market_data tool.
    export interface StreamParams {
      symbol: string;
      type: 'spot' | 'futures';
      streams: string[];
    }
  • Type guard function used in the handler to validate input parameters match StreamParams.
    export function isStreamParams(params: any): params is StreamParams {
      return (
        typeof params === 'object' &&
        typeof params.symbol === 'string' &&
        (params.type === 'spot' || params.type === 'futures') &&
        Array.isArray(params.streams)
      );
    }
  • Core subscription method in BinanceWebSocketManager that initializes subscription state, sets up callbacks, and triggers WebSocket connection.
    public subscribe(symbol: string, type: 'spot' | 'futures', streams: StreamEventType[]): void {
      const subscription: StreamSubscription = {
        symbol,
        type,
        streams,
        reconnectAttempts: 0
      };
      
      if (!this.messageCallbacks.has(symbol)) {
        this.messageCallbacks.set(symbol, new Map());
      }
      
      const symbolCallbacks = this.messageCallbacks.get(symbol)!;
      streams.forEach(stream => {
        if (!symbolCallbacks.has(stream)) {
          symbolCallbacks.set(stream, []);
        }
      });
    
      this.subscriptions.set(symbol, subscription);
      this.connectWebSocket(subscription);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'real-time updates' and 'subscribe,' hinting at a streaming or push-based operation, but fails to detail critical aspects like authentication requirements, rate limits, how to handle or stop subscriptions, or the format of incoming data. This leaves significant gaps for an agent to understand the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('subscribe to real-time market data updates') with zero wasted words. It is appropriately sized for the tool's complexity, making it easy to parse and understand quickly without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (involving real-time subscriptions with multiple parameters) and the absence of both annotations and an output schema, the description is incomplete. It lacks details on behavioral traits (e.g., how updates are delivered, error handling), does not explain return values or subscription management, and fails to provide context on when to use it versus siblings. This leaves the agent with insufficient information for effective tool invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, clearly documenting all three parameters with enums and examples. The description adds no additional parameter semantics beyond what the schema provides, such as explaining interactions between parameters or usage nuances. However, with high schema coverage, a baseline score of 3 is appropriate as the schema adequately handles parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('subscribe to') and resource ('real-time market data updates'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'get_market_data' (which likely retrieves static data), but the 'subscribe' verb implies a continuous stream versus a one-time fetch, providing some implicit distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance is provided on when to use this tool versus alternatives. The description lacks context about prerequisites (e.g., authentication), frequency of updates, or comparisons to sibling tools like 'get_market_data' for static data. Usage is implied by the verb 'subscribe,' but no when-not-to-use scenarios or clear alternatives are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/qeinfinity/binance-mcp-server'

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