Skip to main content
Glama

get_latest_liquidations

Retrieve Binance liquidation events in a table format to monitor market volatility and risk exposure.

Instructions

Retrieve the latest liquidation events from Binance in a table format.

Args:
    limit (int): The maximum number of liquidation events to return (default: 10, max: 1000).
    ctx (Context, optional): The MCP context for logging and server interaction. Defaults to None.

Returns:
    str: A Markdown table containing the latest liquidation events, sorted by timestamp in descending order.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
ctxNo

Implementation Reference

  • main.py:88-114 (handler)
    The handler function for the 'get_latest_liquidations' tool, decorated with @mcp.tool() for registration. It extracts liquidation events from the application lifespan context, sorts them by timestamp descending, limits to the specified number, logs the count if context provided, and formats the data into a Markdown table.
    @mcp.tool()
    def get_latest_liquidations(limit: int = 10, ctx: Context | None = None) -> str:
        """Retrieve the latest liquidation events from Binance in a table format.
    
        Args:
            limit (int): The maximum number of liquidation events to return (default: 10, max: 1000).
            ctx (Context, optional): The MCP context for logging and server interaction. Defaults to None.
    
        Returns:
            str: A Markdown table containing the latest liquidation events, sorted by timestamp in descending order.
        """
        app_ctx = ctx.request_context.lifespan_context if ctx else mcp.get_context().request_context.lifespan_context
        filtered = [vars(event) for event in app_ctx.liquidations]
        filtered = sorted(filtered, key=lambda x: x['timestamp'], reverse=True)[:min(limit, MAX_LIQUIDATIONS)]
        if ctx:
            ctx.info(f"Retrieved {len(filtered)} latest liquidation events")
        
        # Generate Markdown table
        if not filtered:
            return "No liquidation events available."
        table = "| Symbol | Side | Price | Quantity | Time |\n"
        table += "|--------|------|-------|----------|------|\n"
        for event in filtered:
            dt = datetime.fromtimestamp(event['timestamp'] / 1000.0)
            time_str = dt.strftime("%H:%M:%S")
            table += f"| {event['symbol']} | {event['side']} | {event['price']} | {event['quantity']} | {time_str} |\n"
        return table
  • main.py:17-23 (helper)
    Dataclass defining the structure for individual liquidation events stored in the application context, used by the tool indirectly.
    @dataclass
    class LiquidationEvent:
        symbol: str
        side: str  # BUY or SELL
        price: float
        quantity: float
        timestamp: int
  • main.py:52-78 (helper)
    Helper function that listens to the Binance WebSocket stream for force liquidation orders and populates the liquidations list in the app context, providing the data source for the tool.
    async def listen_binance_liquidations(ctx: AppContext):
        """Listen for liquidation events from Binance WebSocket"""
        if not ctx.binance_ws:
            return
        try:
            async for message in ctx.binance_ws:
                data = json.loads(message)
                event_data = data.get('o', {})
                event = LiquidationEvent(
                    symbol=event_data.get('s', ''),
                    side=event_data.get('S', ''),
                    price=float(event_data.get('p', 0)),
                    quantity=float(event_data.get('q', 0)),
                    timestamp=int(event_data.get('T', 0))
                )
                ctx.liquidations.append(event)
                # Maintain max 1000 events
                if len(ctx.liquidations) > MAX_LIQUIDATIONS:
                    ctx.liquidations.pop(0)
        except Exception as e:
            ctx.liquidations.append(LiquidationEvent(
                symbol="ERROR",
                side="NONE",
                price=0.0,
                quantity=0.0,
                timestamp=int(asyncio.get_event_loop().time() * 1000),
            ))
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It does reveal that results are sorted by timestamp in descending order and returned as a Markdown table, which are useful behavioral traits. However, it doesn't mention rate limits, authentication requirements, data freshness, error conditions, or whether this is a read-only operation (though 'retrieve' implies it). The description adds some value but leaves significant behavioral aspects unspecified.

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) and front-loaded the core purpose. Every sentence adds value: the first states what the tool does, followed by parameter explanations and return format. It could be slightly more concise by integrating the default values more seamlessly, but overall it's efficient and well-organized.

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

Completeness4/5

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

Given the tool's moderate complexity (2 parameters, no output schema, no annotations), the description provides good contextual coverage. It explains the tool's purpose, parameters, and return format clearly. The main gap is the lack of behavioral details like rate limits or authentication, but for a data retrieval tool with well-documented parameters, this is reasonably complete. The absence of an output schema is mitigated by the clear return value description.

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

Parameters5/5

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

The description provides excellent parameter semantics beyond the input schema. While schema description coverage is 0%, the description clearly explains both parameters: 'limit' with its default (10) and maximum (1000) values, and 'ctx' as optional with its purpose ('MCP context for logging and server interaction'). This fully compensates for the lack of schema descriptions and adds meaningful context about parameter usage.

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

Purpose5/5

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

The description clearly states the specific action ('retrieve'), resource ('latest liquidation events from Binance'), and output format ('table format'). It distinguishes itself by specifying the source (Binance) and format (Markdown table), making the purpose unambiguous even without sibling tools for comparison.

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. While there are no sibling tools listed, it doesn't mention any prerequisites, constraints, or scenarios where this tool would be appropriate versus other data retrieval methods. The only implicit guidance is the focus on 'latest' events, but no explicit usage context 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

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/kukapay/crypto-liquidations-mcp'

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