MCP HubMCP Hub
sammcj

bybit-mcp

by: sammcj

Ollama MCP server for bybit

7created 13/12/2024
Visit
Ollama
Bybit

📌Overview

Purpose: The Bybit MCP Server aims to provide users with read-only access to Bybit's cryptocurrency exchange API, facilitating the retrieval of various market data.

Overview: This server offers a Model Context Protocol (MCP) solution allowing developers to interact with Bybit's API efficiently in a read-only capacity. It is designed to pull real-time cryptocurrency data securely and facilitates integration with various client applications.

Key Features:

  • Get Ticker: Fetches real-time ticker information for a specified trading pair, enabling users to monitor current market prices effortlessly.

  • Get Orderbook: Provides market depth data for trading pairs, helping users understand the supply and demand dynamics at any given moment.

  • Get Kline Data: Retrieves historical candlestick data for a trading pair, allowing users to perform technical analysis.

  • Get Market Info: Supplies detailed information about trading pairs within the market, essential for informed trading decisions.

  • Get Trades: Lists recent trades for a trading pair, giving insights into market activity.

  • Get Wallet Balance: Offers information on the user's wallet balance, crucial for managing assets.

  • Get Positions: Displays current positions for authenticated users, aiding in portfolio management.

  • Get Order History: Provides a history of orders placed by the user, ensuring tracking and review of past trading activities.


Bybit MCP Server

A Model Context Protocol (MCP) server that provides read-only access to Bybit's cryptocurrency exchange API.

THIS IS ALPHA QUALITY SOFTWARE - USE AT YOUR OWN RISK!

Only ever use a read-only API key with this server.

Started integrated server
Chatting with llama-3.2-11b-instruct:Q8_0 (Ctrl+C to exit)
Tools are available - ask about cryptocurrency data!

You: Whats the current spot price for USDT/BTC?

Assistant: <tool>get_ticker</tool>
<arguments>
{
  "category": "spot",
  "symbol": "BTCUSDT"
}
</arguments>

Tool result: {
  "timestamp": "2024-12-14T12:32:30.628Z",
  "meta": {
    "requestId": "ad5177bc-93d1-49ed-80a1-dd95b3ec970b"
  },
  "symbol": "BTCUSDT",
  "category": "spot",
  "lastPrice": "101368.71",
  "price24hPcnt": "0.0107",
  "highPrice24h": "102661.3",
  "lowPrice24h": "99683.96",
  "prevPrice24h": "100292.67",
  "volume24h": "22543.911683",
  "turnover24h": "2285318788.68303381",
  "bid1Price": "101366.07",
  "bid1Size": "0.136049",
  "ask1Price": "101366.08",
  "ask1Size": "0.648039",
  "usdIndexPrice": "101365.707576"
}

Processing result...

The current spot price for USDT/BTC is $101,368.71.

Features

This MCP server provides the following tools for interacting with Bybit's API:

  • get_ticker: Get real-time ticker information for a trading pair
  • get_orderbook: Get orderbook (market depth) data for a trading pair
  • get_kline: Get kline/candlestick data for a trading pair
  • get_market_info: Get detailed market information for trading pairs
  • get_trades: Get recent trades for a trading pair
  • get_instrument_info: Get detailed instrument information for a specific trading pair
  • get_wallet_balance: Get wallet balance information for the authenticated user
  • get_positions: Get current positions information for the authenticated user
  • get_order_history: Get order history for the authenticated user

Requirements & Installation

  1. Node.js (v20+)
  2. pnpm (npm i -g pnpm)
  3. If you want to run the Ollama client as shown below, you'll need Ollama installed and running, as well as your model of choice.
pnpm i

Quick Start

To install packages, build everything, and start the interactive client:

pnpm i

Copy the .env.example file to .env and fill in your details:

cp .env.example .env
code .env

MCP-Server Only

pnpm serve

MCP-Server and Ollama Client

Install required client packages:

(cd client && pnpm i)

Copy client .env.example file to .env and fill in your details:

cp client/.env.example client/.env
code client/.env

Start client and server in one command:

pnpm start

Configuration

Environment Variables

Set the following environment variables for the server:

  • BYBIT_API_KEY: Your Bybit API key (required)
  • BYBIT_API_SECRET: Your Bybit API secret (required) - Only create a read-only API key!
  • BYBIT_USE_TESTNET: "true" to use testnet instead of mainnet (optional)
  • DEBUG: "true" to enable debug logging (optional)

Client environment variables (./client/.env):

  • OLLAMA_HOST: Host of the Ollama server (default: http://localhost:11434)
  • DEFAULT_MODEL: Default model for chat (default: llama-3.2-11b-instruct:Q8_0)

MCP Settings Configuration

Add this server to your MCP client settings file.

Example for Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "bybit": {
      "command": "node",
      "args": ["/path/to/bybit-mcp/build/index.js"],
      "env": {
        "BYBIT_API_KEY": "your-api-key",
        "BYBIT_API_SECRET": "your-api-secret",
        "BYBIT_USE_TESTNET": "false"
      }
    }
  }
}

Example for gomcp (~/.config/gomcp/config.yaml):

mcp_servers:
  - name: "bybit"
    command: "cd /path/to/bybit-mcp && pnpm run serve"
    arguments: []
    env:
      BYBIT_API_KEY: ""      # Bybit API **READ ONLY** key
      BYBIT_API_SECRET: ""   # Bybit API **READ ONLY** secret
      BYBIT_USE_TESTNET: "true"  # false for production
      DEBUG: "false"         # true for debug logging

Client Integration

Includes a TypeScript client CLI for interacting with Ollama models and bybit-mcp server. Features:

  • Interactive chat with Ollama models
  • Access to Bybit trading tools
  • Automatic server management
  • Environment-based configuration
  • Debug logging

Running the Server

Production

  1. Build the server:
pnpm build
  1. Run the server:
node build/index.js

Development

For automatic TypeScript recompilation:

pnpm watch

To inspect the MCP server during development:

pnpm inspector

Tool Documentation

Get Ticker Information

{
  "name": "get_ticker",
  "arguments": {
    "symbol": "BTCUSDT",
    "category": "spot" // optional, defaults to "spot"
  }
}

Get Orderbook Data

{
  "name": "get_orderbook",
  "arguments": {
    "symbol": "BTCUSDT",
    "category": "spot", // optional, defaults to "spot"
    "limit": 25 // optional, defaults to 25 (1, 25, 50, 100, 200)
  }
}

Get Kline/Candlestick Data

{
  "name": "get_kline",
  "arguments": {
    "symbol": "BTCUSDT",
    "category": "spot", // optional, defaults to "spot"
    "interval": "1", // optional, defaults to "1" (various intervals available)
    "limit": 200 // optional, defaults to 200 (max 1000)
  }
}

Get Market Information

{
  "name": "get_market_info",
  "arguments": {
    "category": "spot", // optional, defaults to "spot"
    "symbol": "BTCUSDT", // optional, defaults to all symbols
    "limit": 200 // optional, defaults to 200 (max 1000)
  }
}

Get Recent Trades

{
  "name": "get_trades",
  "arguments": {
    "symbol": "BTCUSDT",
    "category": "spot", // optional, defaults to "spot"
    "limit": 200 // optional, defaults to 200 (max 1000)
  }
}

Get Instrument Information

{
  "name": "get_instrument_info",
  "arguments": {
    "symbol": "BTCUSDT", // required
    "category": "spot" // optional, defaults to "spot"
  }
}

Returns detailed instrument information including base/quote currencies, trading status, lot size and price filters, leverage (futures), and contract details (futures).

Get Wallet Balance

{
  "name": "get_wallet_balance",
  "arguments": {
    "accountType": "UNIFIED", // required (UNIFIED, CONTRACT, SPOT)
    "coin": "BTC" // optional, returns all coins if omitted
  }
}

Get Positions

{
  "name": "get_positions",
  "arguments": {
    "category": "linear", // required (linear, inverse)
    "symbol": "BTCUSDT", // optional
    "baseCoin": "BTC", // optional
    "settleCoin": "USDT", // optional
    "limit": 200 // optional, defaults to 200
  }
}

Get Order History

{
  "name": "get_order_history",
  "arguments": {
    "category": "spot", // required (spot, linear, inverse)
    "symbol": "BTCUSDT", // optional
    "baseCoin": "BTC", // optional
    "orderId": "1234567890", // optional
    "orderLinkId": "myCustomId", // optional
    "orderStatus": "Filled", // optional (several statuses available)
    "orderFilter": "Order", // optional (Order, StopOrder)
    "limit": 200 // optional, defaults to 200
  }
}

Supported Categories

  • spot: Spot trading
  • linear: Linear perpetual contracts
  • inverse: Inverse perpetual contracts

License

MIT