Skip to main content
Glama

set_margin_mode

Configure margin mode for Bybit trades by specifying category, symbol, trade mode (isolated or cross), and leverage for buying and selling. Adjust risk management settings effectively.

Instructions

Set margin mode

Args:
    category (str): Category (spot, linear, inverse, etc.)
    symbol (str): Symbol (e.g., BTCUSDT)
    tradeMode (int): Trading mode (0: Isolated, 1: Cross)
    buyLeverage (str): Buying leverage
    sellLeverage (str): Selling leverage

Returns:
    Dict: Setting result

Example:
    set_margin_mode("spot", "BTCUSDT", 0, "10", "10")

Reference:
    https://bybit-exchange.github.io/docs/v5/account/set-margin-mode

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
buyLeverageYesBuying leverage
categoryYesCategory (spot, linear, inverse, etc.)
sellLeverageYesSelling leverage
symbolYesSymbol (e.g., BTCUSDT)
tradeModeYesTrading mode (0: Isolated, 1: Cross)

Implementation Reference

  • The main handler function for the 'set_margin_mode' MCP tool, decorated with @mcp.tool() for automatic registration. Includes input schema via Field annotations and implements the core logic by delegating to the service layer.
    def set_margin_mode(
        category: str = Field(description="Category (spot, linear, inverse, etc.)"),
        symbol: str = Field(description="Symbol (e.g., BTCUSDT)"),
        tradeMode: int = Field(description="Trading mode (0: Isolated, 1: Cross)"),
        buyLeverage: str = Field(description="Buying leverage"),
        sellLeverage: str = Field(description="Selling leverage")
    ) -> Dict:
        """
        Set margin mode
    
        Args:
            category (str): Category (spot, linear, inverse, etc.)
            symbol (str): Symbol (e.g., BTCUSDT)
            tradeMode (int): Trading mode (0: Isolated, 1: Cross)
            buyLeverage (str): Buying leverage
            sellLeverage (str): Selling leverage
    
        Returns:
            Dict: Setting result
    
        Example:
            set_margin_mode("spot", "BTCUSDT", 0, "10", "10")
    
        Reference:
            https://bybit-exchange.github.io/docs/v5/account/set-margin-mode
        """
        try:
            result = bybit_service.set_margin_mode(
                category, symbol, tradeMode, buyLeverage, sellLeverage
            )
            if result.get("retCode") != 0:
                logger.error(f"Failed to set margin mode: {result.get('retMsg')}")
                return {"error": result.get("retMsg")}
            return result
        except Exception as e:
            logger.error(f"Failed to set margin mode: {e}", exc_info=True)
            return {"error": str(e)}
  • Helper method in BybitService class that wraps and forwards the set_margin_mode call to the underlying Bybit client library.
    def set_margin_mode(self, category: str, symbol: str,
                        tradeMode: int, buyLeverage: str,
                        sellLeverage: str) -> Dict:
        """
        Set margin mode
    
        Args:
            category (str): Category (spot, linear, inverse, etc.)
            symbol (str): Symbol (e.g., BTCUSDT)
            tradeMode (int): Trading mode (0: Isolated, 1: Cross)
            buyLeverage (str): Buying leverage
            sellLeverage (str): Selling leverage
    
        Returns:
            Dict: Setting result
        """
        return self.client.set_margin_mode(
            category=category,
            symbol=symbol,
            tradeMode=tradeMode,
            buyLeverage=buyLeverage,
            sellLeverage=sellLeverage
        )
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Set' implies a write/mutation operation, the description doesn't disclose important behavioral traits: whether this requires specific permissions, if it's reversible, potential rate limits, authentication requirements, or what happens to existing positions when changing margin mode. The example shows parameter values but doesn't explain the implications of those choices.

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?

The description is well-structured with clear sections (Args, Returns, Example, Reference) and efficiently presents information. However, the core description 'Set margin mode' is overly terse and could benefit from slightly more context about what margin mode represents in this trading system.

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 financial trading tool with 5 required parameters and no annotations or output schema, the description is inadequate. It doesn't explain what 'margin mode' means, the implications of changing it, error conditions, or what the 'Setting result' dictionary contains. The reference link is helpful but doesn't compensate for the lack of essential context in the description itself.

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 the schema already documents all 5 parameters. The description repeats the same parameter information without adding meaningful context beyond what's in the schema. It doesn't explain the relationship between parameters (e.g., how category affects other parameters) or provide guidance on valid combinations. The baseline of 3 is appropriate when the schema does the heavy lifting.

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 margin mode' which is a specific verb+resource, but it's quite minimal and doesn't distinguish this from sibling tools. While it's clear this configures margin settings, it doesn't explain what 'margin mode' means in this trading context or how it differs from related tools like 'set_trading_stop'.

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 is provided about when to use this tool versus alternatives. The description doesn't mention prerequisites, timing considerations, or relationship to sibling tools like 'place_order' or 'set_trading_stop'. The example shows usage but doesn't explain the context in which this operation is appropriate.

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