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
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes | Category (spot, linear, inverse, etc.) | |
| symbol | No | Symbol (e.g., BTCUSDT) |
Implementation Reference
- src/server.py:195-224 (handler)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)}
- src/service.py:127-142 (helper)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 )