Skip to main content
Glama

set-margin-mode

Configure futures trading margin mode (cross or isolated) on supported exchanges using the CCXT MCP Server. Specify exchange, symbol, and API credentials for precise margin management.

Instructions

Set margin mode for futures trading

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apiKeyYesAPI key for authentication
exchangeYesExchange ID (e.g., binance, bybit)
marginModeYesMargin mode: cross or isolated
marketTypeNoMarket type (default: future)future
passphraseNoPassphrase for authentication (required for some exchanges like KuCoin)
secretYesAPI secret for authentication
symbolYesTrading pair symbol (e.g., BTC/USDT)

Implementation Reference

  • Handler function that implements the 'set-margin-mode' tool. It authenticates with the exchange using provided credentials, applies rate limiting, logs the action, calls setMarginMode on the CCXT exchange instance for the specified symbol, and returns the result or error response.
    }, async ({ exchange, symbol, marginMode, apiKey, secret, passphrase, marketType }) => {
      try {
        return await rateLimiter.execute(exchange, async () => {
          // Get futures exchange
          const ex = getExchangeWithCredentials(exchange, apiKey, secret, marketType, passphrase);
          
          // Set margin mode
          log(LogLevel.INFO, `Setting margin mode to ${marginMode} for ${symbol} on ${exchange} (${marketType})`);
          const result = await ex.setMarginMode(marginMode, symbol);
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify(result, null, 2)
            }]
          };
        });
      } catch (error) {
        log(LogLevel.ERROR, `Error setting margin mode: ${error instanceof Error ? error.message : String(error)}`);
        return {
          content: [{
            type: "text",
            text: `Error: ${error instanceof Error ? error.message : String(error)}`
          }],
          isError: true
        };
      }
    });
  • Zod input schema defining parameters for the 'set-margin-mode' tool: exchange, symbol, marginMode (cross/isolated), credentials, and marketType.
    exchange: z.string().describe("Exchange ID (e.g., binance, bybit)"),
    symbol: z.string().describe("Trading pair symbol (e.g., BTC/USDT)"),
    marginMode: z.enum(["cross", "isolated"]).describe("Margin mode: cross or isolated"),
    apiKey: z.string().describe("API key for authentication"),
    secret: z.string().describe("API secret for authentication"),
    passphrase: z.string().optional().describe("Passphrase for authentication (required for some exchanges like KuCoin)"),
    marketType: z.enum(["future", "swap"]).default("future").describe("Market type (default: future)")
  • Registration of the 'set-margin-mode' tool using server.tool(), providing name, description, input schema, and inline handler function within registerPrivateTools.
    server.tool("set-margin-mode", "Set margin mode for futures trading", {
      exchange: z.string().describe("Exchange ID (e.g., binance, bybit)"),
      symbol: z.string().describe("Trading pair symbol (e.g., BTC/USDT)"),
      marginMode: z.enum(["cross", "isolated"]).describe("Margin mode: cross or isolated"),
      apiKey: z.string().describe("API key for authentication"),
      secret: z.string().describe("API secret for authentication"),
      passphrase: z.string().optional().describe("Passphrase for authentication (required for some exchanges like KuCoin)"),
      marketType: z.enum(["future", "swap"]).default("future").describe("Market type (default: future)")
    }, async ({ exchange, symbol, marginMode, apiKey, secret, passphrase, marketType }) => {
      try {
        return await rateLimiter.execute(exchange, async () => {
          // Get futures exchange
          const ex = getExchangeWithCredentials(exchange, apiKey, secret, marketType, passphrase);
          
          // Set margin mode
          log(LogLevel.INFO, `Setting margin mode to ${marginMode} for ${symbol} on ${exchange} (${marketType})`);
          const result = await ex.setMarginMode(marginMode, symbol);
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify(result, null, 2)
            }]
          };
        });
      } catch (error) {
        log(LogLevel.ERROR, `Error setting margin mode: ${error instanceof Error ? error.message : String(error)}`);
        return {
          content: [{
            type: "text",
            text: `Error: ${error instanceof Error ? error.message : String(error)}`
          }],
          isError: true
        };
      }
    });
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. 'Set' implies a mutation operation, but the description doesn't disclose whether this requires specific permissions, whether changes are reversible, what happens to existing positions when margin mode changes, or any rate limits. For a financial trading tool with zero annotation coverage, this is a significant gap.

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

Conciseness5/5

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

The description is a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for a tool with well-documented parameters in the schema.

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 mutation tool with no annotations and no output schema, the description is inadequate. It doesn't explain what the tool returns, what side effects occur, error conditions, or how this operation fits into broader trading workflows. The combination of mutation behavior, financial context, and lack of structured metadata requires more comprehensive description.

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 all parameters are documented in the schema itself. The description doesn't add any parameter semantics beyond what's already in the schema - it doesn't explain relationships between parameters (e.g., how 'exchange' affects which authentication parameters are needed) or provide usage examples. Baseline 3 is appropriate when schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the action ('Set') and resource ('margin mode for futures trading'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'set-leverage' or 'set-market-type' that also configure trading parameters, so it doesn't achieve full sibling differentiation.

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?

The description provides no guidance on when to use this tool versus alternatives. There's no mention of prerequisites (like needing authentication), when margin mode changes are appropriate, or how this relates to sibling tools like 'set-leverage' or 'set-market-type' that also configure trading settings.

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/doggybee/mcp-server-ccxt'

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