Skip to main content
Glama
demwick

polymarket-trader-mcp

orders.cancel

Cancel all open/pending limit orders on Polymarket with a single call. Use as an emergency stop, before changing strategy, or when unwinding positions. Returns the count of cancelled orders. Not reversible.

Instructions

Cancel ALL open/pending limit orders on Polymarket for this account in a single call. Use as an emergency stop, before changing strategy, after a sudden price move, or when unwinding positions. Not reversible — cancelled orders must be re-placed via orders.buy, wta.bid, or orders.batch. Returns the count of cancelled orders. Call orders.list first if you want to preview what will be cancelled. Only works in live mode (no-op in preview). No parameters. Pro feature.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • src/index.ts:274-279 (registration)
    Registers the 'orders.cancel' MCP tool with the server, linking it to cancelOrdersSchema for input validation and the handleCancelOrders function for execution.
    server.tool(
      "orders.cancel",
      "Cancel ALL open/pending limit orders on Polymarket for this account in a single call. Use as an emergency stop, before changing strategy, after a sudden price move, or when unwinding positions. Not reversible — cancelled orders must be re-placed via orders.buy, wta.bid, or orders.batch. Returns the count of cancelled orders. Call orders.list first if you want to preview what will be cancelled. Only works in live mode (no-op in preview). No parameters. Pro feature.",
      cancelOrdersSchema.shape,
      safe("orders.cancel", async () => ({ content: [{ type: "text" as const, text: await handleCancelOrders(tradeExecutor) }] }))
    );
  • Defines the cancelOrdersSchema as an empty Zod object (no parameters required) for the 'orders.cancel' tool.
    export const cancelOrdersSchema = z.object({});
  • The handleCancelOrders function: checks Pro license, validates live mode, calls executor.cancelAllOrders(), and returns the count of cancelled orders or an error message.
    export async function handleCancelOrders(executor: TradeExecutor): Promise<string> {
      const isPro = await checkLicense();
      if (!isPro) return requirePro("cancel_orders");
    
      if (executor.getMode() !== "live") {
        return "Cancel orders only works in live mode. Use `go_live` to switch to live trading first.";
      }
    
      try {
        const result = await executor.cancelAllOrders();
    
        if (result.cancelled === 0) {
          return "No open orders to cancel.";
        }
    
        log("trade", `Cancelled ${result.cancelled} open orders`);
        return `Cancelled ${result.cancelled} open orders.`;
      } catch (err: any) {
        log("error", `Cancel orders failed: ${err}`);
        const hint = err?.message?.includes("credentials") ? " Verify your API credentials are configured correctly." : "";
        return `Failed to cancel orders. The Polymarket API returned an error.${hint} Check the event log for details.`;
      }
    }
  • The cancelAllOrders() method on TradeExecutor: fetches open orders via the CLOB client, cancels them all, and returns the count of cancelled orders.
    async cancelAllOrders(): Promise<{ cancelled: number }> {
      const client = await this.getClobClient();
      const openOrders = await client.getOpenOrders();
      if (!openOrders || openOrders.length === 0) return { cancelled: 0 };
      await client.cancelAll();
      return { cancelled: openOrders.length };
    }
  • The 'safe' wrapper used by the tool registration to catch errors and return user-friendly error messages.
    export function safe(
      toolName: string,
      handler: (...args: any[]) => McpResult | Promise<McpResult>
    ): (...args: any[]) => Promise<McpResult> {
      return async (...args: any[]) => {
        try {
          return await handler(...args);
        } catch (err: any) {
          const message = err?.message ?? String(err);
          log("error", `Tool "${toolName}" failed: ${message}`);
          return { content: [{ type: "text" as const, text: `An error occurred while running "${toolName}". Please try again or check the event log for details.` }] };
        }
      };
    }
Behavior5/5

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

With no annotations, the description fully covers behavior: irreversible, live-mode-only, returns count of cancelled orders, no parameters, pro feature. No contradictions.

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?

Five well-structured sentences; action verb front-loaded. Every sentence adds value: purpose, use cases, constraints, return info, and procedural suggestion. No redundancy.

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

Completeness5/5

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

Given the tool's simplicity (no params, no output schema), the description is complete—covers purpose, usage, side effects, return value, and mode restrictions. No gaps.

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

Parameters4/5

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

No parameters exist (schema is empty, coverage 100%). Baseline is 4 for zero parameters. Description explicitly states 'No parameters', which adds clarity.

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 verb ('Cancel') and resource ('ALL open/pending limit orders on Polymarket for this account in a single call'). It distinguishes from siblings by naming alternative re-placement tools (orders.buy, wta.bid, orders.batch) and preview suggestion (orders.list). No ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly lists when to use: emergency stop, before strategy change, after price move, unwinding positions. Also states it is not reversible and only works in live mode (no-op in preview). Provides clear guidance and alternatives.

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/demwick/polymarket-trader-mcp'

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