Skip to main content
Glama

get_positions

Retrieve detailed position data from Bybit for specified categories and symbols to monitor and manage your trading portfolio effectively.

Instructions

Get position information

Args:
    category (str): Category (spot, linear, inverse, etc.)
    symbol (Optional[str]): Symbol (e.g., BTCUSDT)

Returns:
    Dict: Position information

Example:
    get_positions("spot", "BTCUSDT")

Reference:
    https://bybit-exchange.github.io/docs/v5/position

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryYesCategory (spot, linear, inverse, etc.)
symbolNoSymbol (e.g., BTCUSDT)

Implementation Reference

  • MCP tool handler for 'get_positions'. Decorated with @mcp.tool() for registration. Defines input schema using pydantic Field. Calls BybitService.get_positions and handles API response/errors.
    @mcp.tool()
    def get_positions(
        category: str = Field(description="Category (spot, linear, inverse, etc.)"),
        symbol: Optional[str] = Field(default=None, description="Symbol (e.g., BTCUSDT)")
    ) -> Dict:
        """
        Get position information
    
        Args:
            category (str): Category (spot, linear, inverse, etc.)
            symbol (Optional[str]): Symbol (e.g., BTCUSDT)
    
        Returns:
            Dict: Position information
    
        Example:
            get_positions("spot", "BTCUSDT")
    
        Reference:
            https://bybit-exchange.github.io/docs/v5/position
        """
        try:
            result = bybit_service.get_positions(category, symbol)
            if result.get("retCode") != 0:
                logger.error(f"Failed to get position information: {result.get('retMsg')}")
                return {"error": result.get("retMsg")}
            return result
        except Exception as e:
            logger.error(f"Failed to get position information: {e}", exc_info=True)
            return {"error": str(e)}
  • BybitService.get_positions method: core helper that directly calls the pybit.unified_trading.HTTP client.get_positions API.
    def get_positions(self, category: str, symbol: Optional[str] = None) -> Dict:
        """
        Get position information
    
        Args:
            category (str): Category (spot, linear, inverse, etc.)
            symbol (Optional[str]): Symbol (e.g., BTCUSDT)
    
        Returns:
            Dict: Position information
        """
        return self.client.get_positions(
            category=category,
            symbol=symbol
        )

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