Skip to main content
Glama
ethancod1ng

Binance MCP Server

by ethancod1ng

get_klines

Retrieve historical candlestick data for specified trading pairs and time intervals from Binance exchange to analyze market trends and price movements.

Instructions

获取K线历史数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
intervalYes时间间隔
limitNo数量限制,默认500
symbolYes交易对符号,如 BTCUSDT

Implementation Reference

  • The core handler function implementing the get_klines tool logic: validates input, fetches K-line (candlestick) data from Binance API, formats the response with mapped fields, and handles errors.
    handler: async (binanceClient: any, args: unknown) => {
      const input = validateInput(GetKlinesSchema, args);
      validateSymbol(input.symbol);
    
      try {
        const klines = await binanceClient.candles({
          symbol: input.symbol,
          interval: input.interval,
          limit: input.limit,
        });
    
        return {
          symbol: input.symbol,
          interval: input.interval,
          data: klines.map((kline: any) => ({
            openTime: kline.openTime,
            open: kline.open,
            high: kline.high,
            low: kline.low,
            close: kline.close,
            volume: kline.volume,
            closeTime: kline.closeTime,
            quoteAssetVolume: kline.quoteAssetVolume,
            numberOfTrades: kline.numberOfTrades,
            takerBuyBaseAssetVolume: kline.takerBuyBaseAssetVolume,
            takerBuyQuoteAssetVolume: kline.takerBuyQuoteAssetVolume,
          })),
          timestamp: Date.now(),
        };
      } catch (error) {
        handleBinanceError(error);
      }
    },
  • Tool registration object within marketDataTools array, defining name, description, inputSchema (JSON Schema for MCP), and handler reference.
    {
      name: 'get_klines',
      description: '获取K线历史数据',
      inputSchema: {
        type: 'object',
        properties: {
          symbol: {
            type: 'string',
            description: '交易对符号,如 BTCUSDT',
          },
          interval: {
            type: 'string',
            enum: ['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '8h', '12h', '1d', '3d', '1w', '1M'],
            description: '时间间隔',
          },
          limit: {
            type: 'number',
            description: '数量限制,默认500',
            default: 500,
          },
        },
        required: ['symbol', 'interval'],
      },
      handler: async (binanceClient: any, args: unknown) => {
        const input = validateInput(GetKlinesSchema, args);
        validateSymbol(input.symbol);
    
        try {
          const klines = await binanceClient.candles({
            symbol: input.symbol,
            interval: input.interval,
            limit: input.limit,
          });
    
          return {
            symbol: input.symbol,
            interval: input.interval,
            data: klines.map((kline: any) => ({
              openTime: kline.openTime,
              open: kline.open,
              high: kline.high,
              low: kline.low,
              close: kline.close,
              volume: kline.volume,
              closeTime: kline.closeTime,
              quoteAssetVolume: kline.quoteAssetVolume,
              numberOfTrades: kline.numberOfTrades,
              takerBuyBaseAssetVolume: kline.takerBuyBaseAssetVolume,
              takerBuyQuoteAssetVolume: kline.takerBuyQuoteAssetVolume,
            })),
            timestamp: Date.now(),
          };
        } catch (error) {
          handleBinanceError(error);
        }
      },
    },
  • Zod schema (GetKlinesSchema) used for input validation inside the handler.
    export const GetKlinesSchema = z.object({
      symbol: z.string().describe('交易对符号,如 BTCUSDT'),
      interval: z.enum(['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '8h', '12h', '1d', '3d', '1w', '1M']).describe('时间间隔'),
      limit: z.number().optional().default(500).describe('数量限制,默认500'),
    });
  • src/server.ts:41-51 (registration)
    Top-level MCP server registration: spreads marketDataTools (including get_klines) into allTools and registers each by name in the server's tools Map.
    private setupTools(): void {
      const allTools = [
        ...marketDataTools,
        ...accountTools,
        ...tradingTools,
      ];
    
      for (const tool of allTools) {
        this.tools.set(tool.name, tool);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. '获取' (get) implies a read operation, but the description doesn't disclose rate limits, authentication requirements, data freshness, or what happens when parameters are invalid. For a data retrieval tool with zero annotation coverage, this leaves significant behavioral questions unanswered about performance, reliability, and constraints.

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 Chinese phrase that directly states the tool's purpose without any wasted words. It's appropriately sized for a straightforward data retrieval tool and gets straight to the point. Every character earns its place in conveying the core function.

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 this is a data retrieval tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what K-line data actually returns (open, high, low, close, volume, timestamps), whether results are paginated, time range capabilities, or data source limitations. For a tool that retrieves complex financial time series data, the description should provide more context about the nature and structure of the returned information.

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?

Schema description coverage is 100%, with all parameters well-documented in the schema itself (symbol, interval with enum values, limit with default). The description adds no parameter information beyond what's already in the schema - it doesn't explain what K-line data includes, how intervals affect results, or typical use cases for different limit values. The baseline of 3 is appropriate when the schema does all the parameter documentation work.

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 '获取K线历史数据' (Get K-line historical data) clearly states the verb ('获取' - get) and resource ('K线历史数据' - K-line historical data). It distinguishes this tool from siblings like get_price (current price) or get_orderbook (order book data), but doesn't explicitly mention the distinction. The purpose is specific to retrieving historical candlestick data rather than other market data types.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose get_klines over get_24hr_ticker (24-hour statistics) or get_price (current price), nor does it specify prerequisites like needing market data access. There's no context about appropriate use cases for historical K-line data versus other market data tools.

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

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