binance mcp server

Local 2025-08-31 23:58:42 0

A server implementation that streams real-time Binance market data (spot and futures) via WebSockets, enabling applications to receive and process cryptocurrency market information through the Model Context Protocol.


A Model Context Protocol (MCP) server implementation for Binance market data with WebSocket support.

Features

  • Real-time market data streaming via WebSocket
  • Support for both spot and futures markets
  • Automatic reconnection with exponential backoff
  • Type-safe message handling
  • Comprehensive error handling

Installation

npm install

Usage

Starting the Server

npm start

WebSocket Stream Types

The following stream types are supported:

  • trade: Real-time trade data
  • ticker: 24-hour rolling window price change statistics
  • bookTicker: Best bid/ask price and quantity
  • kline: Candlestick data
  • markPrice: Mark price and funding rate (futures only)
  • fundingRate: Funding rate data (futures only)

Example Usage in Claude Desktop

// Subscribe to trade and ticker streams for BTC/USDT
await server.subscribe('BTCUSDT', 'spot', ['trade', 'ticker']);

// Handle incoming data
server.onStreamData('BTCUSDT', 'trade', (data) => {
  console.log('New trade:', data);
});

Development

Running Tests

npm test

Building

npm run build

License

Private

[
  {
    "description": "Get comprehensive market data for a trading pair",
    "inputSchema": {
      "properties": {
        "symbol": {
          "description": "Trading pair symbol (e.g., BTCUSDT)",
          "type": "string"
        },
        "type": {
          "description": "Market type",
          "enum": [
            "spot",
            "futures"
          ],
          "type": "string"
        }
      },
      "required": [
        "symbol",
        "type"
      ],
      "type": "object"
    },
    "name": "get_market_data"
  },
  {
    "description": "Test individual futures endpoints",
    "inputSchema": {
      "properties": {
        "symbol": {
          "description": "Trading pair symbol (e.g., BTCUSDT)",
          "type": "string"
        }
      },
      "required": [
        "symbol"
      ],
      "type": "object"
    },
    "name": "test_futures_endpoints"
  },
  {
    "description": "Get current open interest for a futures trading pair",
    "inputSchema": {
      "properties": {
        "symbol": {
          "description": "Trading pair symbol (e.g., BTCUSDT)",
          "type": "string"
        }
      },
      "required": [
        "symbol"
      ],
      "type": "object"
    },
    "name": "get_futures_open_interest"
  },
  {
    "description": "Get current funding rate for a futures trading pair",
    "inputSchema": {
      "properties": {
        "symbol": {
          "description": "Trading pair symbol (e.g., BTCUSDT)",
          "type": "string"
        }
      },
      "required": [
        "symbol"
      ],
      "type": "object"
    },
    "name": "get_futures_funding_rate"
  },
  {
    "description": "Get historical candlestick data",
    "inputSchema": {
      "properties": {
        "interval": {
          "description": "Kline/candlestick chart interval",
          "enum": [
            "1m",
            "5m",
            "15m",
            "30m",
            "1h",
            "4h",
            "1d",
            "1w",
            "1M"
          ],
          "type": "string"
        },
        "limit": {
          "description": "Number of klines to retrieve (default 500, max 1000)",
          "type": "number"
        },
        "symbol": {
          "description": "Trading pair symbol (e.g., BTCUSDT)",
          "type": "string"
        },
        "type": {
          "description": "Market type",
          "enum": [
            "spot",
            "futures"
          ],
          "type": "string"
        }
      },
      "required": [
        "symbol",
        "type",
        "interval"
      ],
      "type": "object"
    },
    "name": "get_klines"
  },
  {
    "description": "Subscribe to real-time market data updates",
    "inputSchema": {
      "properties": {
        "streams": {
          "description": "List of data streams to subscribe to",
          "items": {
            "enum": [
              "ticker",
              "trade",
              "kline",
              "depth",
              "forceOrder",
              "markPrice",
              "openInterest"
            ],
            "type": "string"
          },
          "type": "array"
        },
        "symbol": {
          "description": "Trading pair symbol (e.g., BTCUSDT)",
          "type": "string"
        },
        "type": {
          "description": "Market type",
          "enum": [
            "spot",
            "futures"
          ],
          "type": "string"
        }
      },
      "required": [
        "symbol",
        "type",
        "streams"
      ],
      "type": "object"
    },
    "name": "subscribe_market_data"
  }
]