Skip to main content
Glama
Muvon

mcp-binance-futures

by Muvon

cancel_all_orders

Cancel all open orders for a trading pair on Binance Futures. Remove regular orders, conditional orders, or both simultaneously to manage risk and clear order books.

Instructions

Cancel all open orders for a symbol.

With source='all' (default), cancels both regular and algo (conditional) orders in parallel.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesTrading pair, e.g. 'BTCUSDT'
sourceNoWhich orders to cancel: 'regular' = standard orders only, 'algo' = conditional orders only (STOP_MARKET/TAKE_PROFIT_MARKET/etc.), 'all' = both (default).all

Implementation Reference

  • Main handler function for the 'cancel_all_orders' MCP tool. Implements order cancellation logic with support for canceling regular orders, algo (conditional) orders, or both in parallel. Uses Annotated types with Field for inline schema validation of parameters (symbol and source).
    @mcp.tool
    async def cancel_all_orders(
        ctx: Context,
        symbol: Annotated[str, Field(description="Trading pair, e.g. 'BTCUSDT'")],
        source: Annotated[
            Literal["regular", "algo", "all"],
            Field(
                description=(
                    "Which orders to cancel: "
                    "'regular' = standard orders only, "
                    "'algo' = conditional orders only (STOP_MARKET/TAKE_PROFIT_MARKET/etc.), "
                    "'all' = both (default)."
                )
            ),
        ] = "all",
    ) -> dict:
        """Cancel all open orders for a symbol.
    
        With source='all' (default), cancels both regular and algo (conditional) orders in parallel.
        """
        c = _client(ctx)
        if source == "regular":
            return await c.delete_signed("/fapi/v1/allOpenOrders", {"symbol": symbol})
        if source == "algo":
            return await c.delete_signed("/fapi/v1/algoOpenOrders", {"symbol": symbol})
        # "all": cancel both in parallel
        regular_result, algo_result = await _gather(
            c.delete_signed("/fapi/v1/allOpenOrders", {"symbol": symbol}),
            c.delete_signed("/fapi/v1/algoOpenOrders", {"symbol": symbol}),
        )
    
        return {"regular": regular_result, "algo": algo_result}
  • Helper function that extracts the BinanceClient instance from the MCP context lifespan, enabling the handler to make authenticated API calls to Binance.
    def _client(ctx: Context) -> BinanceClient:
        """Extract BinanceClient from lifespan context."""
        assert ctx.request_context is not None
        return cast(BinanceClient, ctx.request_context.lifespan_context["client"])
  • Helper function that wraps asyncio.gather to run multiple API calls concurrently, used by cancel_all_orders when canceling both regular and algo orders in parallel.
    async def _gather(*coros):
        """Run coroutines concurrently and return results in order."""
        import asyncio
    
        return await asyncio.gather(*coros)

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

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