Skip to main content
Glama

set_trading_stop

Set take profit, stop loss, and trailing stop parameters for trades on Bybit Server. Specify category, symbol, and optional settings to manage risk and automate trading strategies effectively.

Instructions

Set trading stop

Args:
    category (str): Category (spot, linear, inverse, etc.)
    symbol (str): Symbol (e.g., BTCUSDT)
    takeProfit (Optional[str]): Take profit price
    stopLoss (Optional[str]): Stop loss price
    trailingStop (Optional[str]): Trailing stop
    positionIdx (Optional[int]): Position index

Returns:
    Dict: Setting result

Example:
    set_trading_stop("spot", "BTCUSDT", "55000", "45000", "1000", 0)

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryYesCategory (spot, linear, inverse, etc.)
positionIdxNoPosition index
stopLossNoStop loss price
symbolYesSymbol (e.g., BTCUSDT)
takeProfitNoTake profit price
trailingStopNoTrailing stop

Implementation Reference

  • MCP tool handler for set_trading_stop. Includes input schema via Field annotations and logic that calls the service helper.
    @mcp.tool()
    def set_trading_stop(
        category: str = Field(description="Category (spot, linear, inverse, etc.)"),
        symbol: str = Field(description="Symbol (e.g., BTCUSDT)"),
        takeProfit: Optional[str] = Field(default=None, description="Take profit price"),
        stopLoss: Optional[str] = Field(default=None, description="Stop loss price"),
        trailingStop: Optional[str] = Field(default=None, description="Trailing stop"),
        positionIdx: Optional[int] = Field(default=None, description="Position index")
    ) -> Dict:
        """
        Set trading stop
    
        Args:
            category (str): Category (spot, linear, inverse, etc.)
            symbol (str): Symbol (e.g., BTCUSDT)
            takeProfit (Optional[str]): Take profit price
            stopLoss (Optional[str]): Stop loss price
            trailingStop (Optional[str]): Trailing stop
            positionIdx (Optional[int]): Position index
    
        Returns:
            Dict: Setting result
    
        Example:
            set_trading_stop("spot", "BTCUSDT", "55000", "45000", "1000", 0)
    
        Reference:
            https://bybit-exchange.github.io/docs/v5/position/trading-stop
        """
        try:
            result = bybit_service.set_trading_stop(
                category, symbol, takeProfit, stopLoss, trailingStop, positionIdx
            )
            if result.get("retCode") != 0:
                logger.error(f"Failed to set trading stop: {result.get('retMsg')}")
                return {"error": result.get("retMsg")}
            return result
        except Exception as e:
            logger.error(f"Failed to set trading stop: {e}", exc_info=True)
            return {"error": str(e)}
  • BybitService helper method that wraps the underlying client.set_trading_stop call to set trading stops.
    def set_trading_stop(self, category: str, symbol: str,
                         takeProfit: Optional[str] = None,
                         stopLoss: Optional[str] = None,
                         trailingStop: Optional[str] = None,
                         positionIdx: Optional[int] = None) -> Dict:
        """
        Set trading stop
    
        Args:
            category (str): Category (spot, linear, inverse, etc.)
            symbol (str): Symbol (e.g., BTCUSDT)
            takeProfit (Optional[str]): Take profit price
            stopLoss (Optional[str]): Stop loss price
            trailingStop (Optional[str]): Trailing stop
            positionIdx (Optional[int]): Position index
    
        Returns:
            Dict: Setting result
        """
        return self.client.set_trading_stop(
            category=category,
            symbol=symbol,
            takeProfit=takeProfit,
            stopLoss=stopLoss,
            trailingStop=trailingStop,
            positionIdx=positionIdx
        )
  • src/server.py:484-484 (registration)
    The @mcp.tool() decorator registers the set_trading_stop function as an MCP tool.
    @mcp.tool()
  • Input schema defined via Pydantic Field annotations in the handler function signature.
        category: str = Field(description="Category (spot, linear, inverse, etc.)"),
        symbol: str = Field(description="Symbol (e.g., BTCUSDT)"),
        takeProfit: Optional[str] = Field(default=None, description="Take profit price"),
        stopLoss: Optional[str] = Field(default=None, description="Stop loss price"),
        trailingStop: Optional[str] = Field(default=None, description="Trailing stop"),
        positionIdx: Optional[int] = Field(default=None, description="Position index")
    ) -> Dict:
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions 'Setting result' but doesn't disclose critical behaviors: whether this is a mutation (likely yes), authentication needs, rate limits, error conditions, or what happens to existing stops. The example implies it sets prices, but behavioral context is minimal.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with clear sections (Args, Returns, Example, Reference). The core description is just two words, but the structured format adds value. Some redundancy exists between Args and schema, but overall efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a trading tool with 6 parameters, no annotations, and no output schema, the description is inadequate. It lacks context on permissions, side effects, error handling, and relationship to other trading operations. The reference link helps but doesn't compensate for missing behavioral details.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are documented in the schema. The description repeats parameter info in the Args section but adds no additional meaning beyond what's in the schema. The example shows usage but doesn't clarify semantics like price format or position index meaning.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states 'Set trading stop' which is a verb+resource, but it's vague about what exactly is being set (stop-loss, take-profit, trailing stop) and doesn't distinguish from sibling trading tools like 'place_order' or 'cancel_order'. The title is null, leaving the name as the only identifier.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives like modifying orders or positions directly. The example shows usage but doesn't explain context or prerequisites. Sibling tools include position management tools, but no comparison is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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