Skip to main content
Glama
mixuechu

Binance MCP Server

by mixuechu

execute_hedge_arbitrage_strategy

Execute automated cryptocurrency arbitrage by exploiting funding rate differentials between trading pairs on Binance to capture profit opportunities.

Instructions

Execute hedge arbitrage based on funding rate.

Args: symbol: The trading pair. quantity: Amount to trade.

Returns: Summary of the arbitrage result.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes
quantityYes

Implementation Reference

  • The handler function decorated with @mcp.tool() implements the execute_hedge_arbitrage_strategy. It performs hedge arbitrage by balancing spot and futures positions based on funding rate, using other tools for data and orders.
    @mcp.tool()
    def execute_hedge_arbitrage_strategy(symbol: str, quantity: str) -> Any:
        """
        Execute hedge arbitrage based on funding rate.
    
        Args:
            symbol: The trading pair.
            quantity: Amount to trade.
    
        Returns:
            Summary of the arbitrage result.
        """
        asset = symbol.replace("USDT", "")
        balance_result = mcp.use_tool("get_account_balance", asset)
        try:
            available_balance = float(balance_result.get("balance", 0))
        except:
            available_balance = 0
    
        actual_quantity = min(float(quantity), available_balance) if available_balance > 0 else 0
        if actual_quantity <= 0:
            return {"error": f"Insufficient {asset} balance."}
    
        funding_rate_data = mcp.use_tool("get_funding_rate_history", symbol)
        funding_rate = float(funding_rate_data[0]['fundingRate'])
        spot_price_data = mcp.use_tool("get_symbol_price", symbol)
        spot_price = float(spot_price_data["price"])
    
        if funding_rate > 0:
            mcp.use_tool("place_market_order", symbol, "BUY", actual_quantity)
            place_futures_order(symbol, "SELL", actual_quantity)
        else:
            mcp.use_tool("place_market_order", symbol, "SELL", actual_quantity)
            place_futures_order(symbol, "BUY", actual_quantity)
    
        time.sleep(10)
    
        if funding_rate > 0:
            place_futures_order(symbol, "BUY", actual_quantity)
            mcp.use_tool("place_market_order", symbol, "SELL", actual_quantity)
        else:
            place_futures_order(symbol, "SELL", actual_quantity)
            mcp.use_tool("place_market_order", symbol, "BUY", actual_quantity)
    
        SPOT_FEE = 0.001
        FUTURES_FEE = 0.0002
        fee = (spot_price * actual_quantity * SPOT_FEE * 2) + (spot_price * actual_quantity * FUTURES_FEE * 2)
        profit = abs(funding_rate) * spot_price * actual_quantity
        net_profit = profit - fee
    
        return {
            "net_profit": round(net_profit, 4),
            "fees": round(fee, 4),
            "message": f"Arbitrage executed. Estimated net profit: {net_profit:.4f} USDT"
        }
  • Supporting helper function place_futures_order used by the arbitrage handler to execute futures market orders on Binance.
    def place_futures_order(symbol: str, side: str, quantity: str) -> Any:
        """
        Place a perpetual futures market order.
    
        Args:
            symbol: Futures pair.
            side: BUY or SELL.
            quantity: Amount.
    
        Returns:
            Order placement result.
        """
        url = "https://fapi.binance.com/fapi/v1/order"
        timestamp = int(time.time() * 1000)
        params = {
            "symbol": symbol,
            "side": side,
            "type": "MARKET",
            "quantity": quantity,
            "timestamp": timestamp
        }
        query_string = "&".join([f"{k}={v}" for k, v in params.items()])
        signature = hmac.new(BINANCE_SECRET_KEY.encode(), query_string.encode(), hashlib.sha256).hexdigest()
        params["signature"] = signature
        headers = {"X-MBX-APIKEY": BINANCE_API_KEY}
        response = requests.post(url, headers=headers, params=params)
        return response.json() if response.status_code == 200 else {"error": response.text}
Behavior2/5

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

With no annotations provided, the description carries full burden but provides minimal behavioral information. It mentions 'Execute hedge arbitrage' which implies a trading action, but doesn't disclose critical details like whether this executes trades, requires specific permissions, has rate limits, involves risk, or what happens on failure. The description is insufficient for understanding the tool's behavior beyond basic purpose.

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 appropriately concise with a clear three-part structure: purpose statement, args section, and returns section. Each sentence serves a purpose, though the content within each section is minimal. No wasted words or unnecessary elaboration.

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 execution tool with no annotations, no output schema, and 2 parameters with 0% schema coverage, the description is incomplete. It doesn't explain what 'hedge arbitrage' means operationally, what the tool actually does (executes trades? calculates positions?), what the return summary contains, or any error conditions. The minimal description leaves too many questions unanswered for safe use.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate but provides minimal parameter semantics. It lists 'symbol' and 'quantity' with brief labels but no meaningful context about format, units, constraints, or examples. For a trading tool with 2 parameters, this leaves significant gaps in understanding what values are appropriate or how they're used in the arbitrage strategy.

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 'Execute hedge arbitrage based on funding rate' which provides a general purpose (verb+resource), but it's vague about what 'hedge arbitrage' specifically entails and doesn't distinguish from sibling tools like 'find_arbitrage_pairs' or 'place_market_order'. It mentions funding rate but doesn't explain how this differentiates from other trading strategies.

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. The description doesn't mention prerequisites, timing considerations, or when this strategy is appropriate versus other sibling tools like 'place_market_order' or 'find_arbitrage_pairs'. It provides no context about when this tool should or shouldn't be used.

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

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/mixuechu/binance-mcp'

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