Skip to main content
Glama

get_orderbook

Retrieve real-time orderbook data for specified symbols and categories on Bybit. Input symbol, limit, and category to access market depth and trading insights instantly.

Instructions

Get orderbook data :parameter symbol: Symbol (e.g., BTCUSDT) limit: Number of orderbook entries to retrieve category: Category (spot, linear, inverse, etc.) Args: category: Category (spot, linear, inverse, etc.) symbol (str): Symbol (e.g., BTCUSDT) limit (int): Number of orderbook entries to retrieve Returns: Dict: Orderbook data Example: get_orderbook("spot", "BTCUSDT", 10) Reference: https://bybit-exchange.github.io/docs/v5/market/orderbook

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryYesCategory (spot, linear, inverse, etc.)
limitNoNumber of orderbook entries to retrieve
symbolYesSymbol (e.g., BTCUSDT)

Implementation Reference

  • MCP tool handler for 'get_orderbook'. Decorated with @mcp.tool(), defines input schema using Field annotations, fetches orderbook data via bybit_service, handles API errors and exceptions.
    @mcp.tool() def get_orderbook( category: str = Field(description="Category (spot, linear, inverse, etc.)"), symbol: str = Field(description="Symbol (e.g., BTCUSDT)"), limit: int = Field(default=50, description="Number of orderbook entries to retrieve") ) -> Dict: """ Get orderbook data :parameter symbol: Symbol (e.g., BTCUSDT) limit: Number of orderbook entries to retrieve category: Category (spot, linear, inverse, etc.) Args: category: Category (spot, linear, inverse, etc.) symbol (str): Symbol (e.g., BTCUSDT) limit (int): Number of orderbook entries to retrieve Returns: Dict: Orderbook data Example: get_orderbook("spot", "BTCUSDT", 10) Reference: https://bybit-exchange.github.io/docs/v5/market/orderbook """ try: result = bybit_service.get_orderbook(category, symbol, limit) if result.get("retCode") != 0: logger.error(f"Failed to get orderbook: {result.get('retMsg')}") return {"error": result.get("retMsg")} return result except Exception as e: logger.error(f"Failed to get orderbook: {e}", exc_info=True) return {"error": str(e)}
  • Input schema definitions using Pydantic Field for the get_orderbook tool parameters.
    category: str = Field(description="Category (spot, linear, inverse, etc.)"), symbol: str = Field(description="Symbol (e.g., BTCUSDT)"), limit: int = Field(default=50, description="Number of orderbook entries to retrieve")
  • BybitService helper method that wraps the pybit client's get_orderbook call.
    def get_orderbook(self, category: str, symbol: str, limit: int = 50) -> Dict: """ Get orderbook data Args: category (str): Category (spot, linear, inverse, etc.) symbol (str): Symbol (e.g., BTCUSDT) limit (int): Number of orderbook entries to retrieve Returns: Dict: Orderbook data """ return self.client.get_orderbook( category=category, symbol=symbol, limit=limit )
  • src/server.py:54-54 (registration)
    Registration of the get_orderbook tool using the @mcp.tool() decorator.
    @mcp.tool()

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/dlwjdtn535/mcp-bybit-server'

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