BY

Bybit MCP Server for Trading & Market Data

Integrate AI assistants with Bybit via an MCP server for automated trading, real-time market data access, and streamlined account management.

Quick Install
npx -y @ethancod1ng/bybit-mcp-server

Overview

This MCP (Model Context Protocol) server exposes Bybit trading and market-data operations as machine-actionable tools so AI assistants and automation frameworks can interact with Bybit accounts, stream live market data, and execute orders programmatically. The server translates MCP tool calls into authenticated Bybit REST/WebSocket requests and returns structured responses suitable for models and orchestrators.

By abstracting Bybit API complexity (signature generation, rate-limiting, streaming sessions) behind a consistent MCP surface, the server makes it easier to prototype trading agents, build monitoring assistants, and integrate exchange data into larger multi-tool AI workflows without rewriting exchange integrations for each new agent.

Features

  • Exposes trading actions (place/cancel orders, adjust leverage) via MCP tools
  • Real-time market data streaming (order book, trades, candles) through WebSocket-backed tools
  • Account management tools: balances, positions, margin, and open orders
  • Configurable sandbox/testnet support for safe development
  • API key / secret configuration with optional per-session isolation
  • Rate limiting and basic request validation to protect accounts
  • JSON-structured responses suitable for model consumption
  • Example client snippets for quick integration

Installation / Configuration

Prerequisites: Node.js (16+ recommended), npm, and a Bybit API key/secret (use testnet keys for development).

  1. Clone the repository and install dependencies:
git clone https://github.com/ethancod1ng/bybit-mcp-server.git
cd bybit-mcp-server
npm install
  1. Create a .env file or export environment variables:
# .env
BYBIT_API_KEY=your_api_key_here
BYBIT_API_SECRET=your_api_secret_here
MCP_PORT=8080
BYBIT_ENV=testnet   # options: mainnet | testnet
ENABLE_SANDBOX=true
  1. Start the server:
npm run start
# or for development
npm run dev

The server listens on the configured MCP_PORT and exposes a set of MCP-compatible endpoints.

Available Tools / Resources

The server exposes multiple MCP tools for trading and data access. Below is a summary table of commonly available endpoints (paths are examples; consult the server’s /tools or OpenAPI resource for exact names).

Tool / EndpointMethodDescription
/tools/getBalancePOSTReturn account balances and available margin
/tools/getPositionsPOSTCurrent open positions with PnL and leverage
/tools/placeOrderPOSTPlace market/limit orders (BTCUSD, USDT pairs)
/tools/cancelOrderPOSTCancel an order by ID
/tools/orderBookStreamPOSTStart order book / depth streaming session
/tools/tradeStreamPOSTSubscribe to trade ticks for a symbol
/tools/historicalCandlesPOSTQuery OHLCV candlesticks for backtesting

Quick example: place an order from a client (MCP tool call payload):

POST /tools/placeOrder
Content-Type: application/json

{
  "symbol": "BTCUSDT",
  "side": "Buy",
  "type": "Market",
  "quantity": 0.001
}

Server response:

{
  "order_id": "1234567890",
  "status": "filled",
  "filled_qty": 0.001,
  "avg_price": "56000.12"
}

Additional resources:

  • GitHub repo: https://github.com/ethancod1ng/bybit-mcp-server
  • Bybit API docs (for underlying behavior and limits)

Use Cases

  • Automated trading agents: Let an LLM-driven trading agent issue MCP-tool calls to open/close positions, adjust risk, and maintain targets. The agent receives structured confirmations and can reason over account state.
  • Real-time alerting assistants: An assistant subscribes to trade and order-book streams to detect abnormal liquidity events and notify a user or take protective actions (e.g., reduce leverage).
  • Strategy prototyping and backtesting: Query historical candles via the MCP tool to run strategy simulations, then switch to live market streams for paper- or live-trading.
  • Portfolio monitoring dashboards: Periodically poll balances and positions to populate dashboards, reconcile trades, or trigger rebalancing workflows.
  • Safe development with sandbox: Use testnet mode to test agents and tools against Bybit’s test environment before enabling real funds.

Integration example (JavaScript)

Sample client that calls the balance tool and places a market order:

import fetch from 'node-fetch';

const MCP_BASE = 'http://localhost:8080';

async function getBalance() {
  const res = await fetch(`${MCP_BASE}/tools/getBalance`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({})
  });
  return res.json();
}

async function placeMarketOrder(symbol, qty) {
  const res = await fetch(`${MCP_BASE}/tools/placeOrder`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ symbol, type: 'Market', side: 'Buy', quantity: qty })
  });
  return res.json();
}

(async () => {
  console.log(await getBalance());
  console.log(await placeMarketOrder('BTCUSDT', 0.001));
})();

Security & Best Practices

  • Use testnet keys until your agent logic is fully validated.
  • Limit API key permissions (e.g., restrict withdrawal).
  • Monitor rate limits and enable server-side throttling.
  • Run the MCP server and AI agents in secured environments; rotate keys periodically.

For full API details, tool names, and advanced configuration options, refer to the repository README and the /tools discovery endpoint once the server is running.

Tags:finance