Skip to main content
Glama

cancel_order

Cancel open cryptocurrency orders on the Zaif exchange using the specified order ID. Modify strategies, correct errors, or remove long-pending orders. Supports BTC/JPY, ETH/JPY, and XYM/JPY pairs.

Instructions

    未約定の暗号資産取引注文をキャンセルします。

    このツールは、既に発注済みで未約定(一部約定を含む)の注文をキャンセルするために使用します。
    注文IDを指定してキャンセルでき、任意で通貨ペアも指定できます。

    使用例:
    - 価格変動により注文戦略を変更したい場合
    - 誤った注文をキャンセルしたい場合
    - 長時間約定しない注文を取り消したい場合

    注意: このツールを使用するには、環境変数にAPIキーとシークレットが設定されている必要があります。

    Args:
        order_id: キャンセルする注文のID(get_open_ordersで取得可能)
        currency_pair: 通貨ペア('btc_jpy': ビットコイン/円、'eth_jpy': イーサリアム/円、'xym_jpy': シンボル/円)
                      指定しない場合、システムは注文IDから自動的に判断します

    Returns:
        CancelOrderResponse: キャンセル結果情報
            - order_id: キャンセルした注文ID
            - balances: キャンセル後の各通貨の残高情報

    Raises:
        ValueError: 認証情報が設定されていない場合や、APIエラーが発生した場合
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
currency_pairNo
order_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
balancesYes
order_idYes

Implementation Reference

  • The main handler function for the 'cancel_order' MCP tool. It is decorated with @mcp.tool() to register it, performs auth check, and calls the underlying Zaif API.
    @mcp.tool()
    def cancel_order(
        order_id: int, currency_pair: SupportedPair = None
    ) -> CancelOrderResponse:
        """
        未約定の暗号資産取引注文をキャンセルします。
    
        このツールは、既に発注済みで未約定(一部約定を含む)の注文をキャンセルするために使用します。
        注文IDを指定してキャンセルでき、任意で通貨ペアも指定できます。
    
        使用例:
        - 価格変動により注文戦略を変更したい場合
        - 誤った注文をキャンセルしたい場合
        - 長時間約定しない注文を取り消したい場合
    
        注意: このツールを使用するには、環境変数にAPIキーとシークレットが設定されている必要があります。
    
        Args:
            order_id: キャンセルする注文のID(get_open_ordersで取得可能)
            currency_pair: 通貨ペア('btc_jpy': ビットコイン/円、'eth_jpy': イーサリアム/円、'xym_jpy': シンボル/円)
                          指定しない場合、システムは注文IDから自動的に判断します
    
        Returns:
            CancelOrderResponse: キャンセル結果情報
                - order_id: キャンセルした注文ID
                - balances: キャンセル後の各通貨の残高情報
    
        Raises:
            ValueError: 認証情報が設定されていない場合や、APIエラーが発生した場合
        """
        if not api.trade.http.auth_provider:
            raise ValueError(
                "認証情報が設定されていません。APIキーとシークレットを.envファイルに設定してください。"
            )
    
        return api.trade.cancel_order(order_id, currency_pair)
  • Output schema definition: dataclass CancelOrderResponse, including from_dict and to_dict for serialization.
    class CancelOrderResponse:
        """
        注文キャンセル結果を表すデータクラス。
        cancel_orderの戻り値に対応します。
    
        Attributes:
            order_id: キャンセルした注文ID
            balances: キャンセル後の各通貨の残高情報
        """
    
        order_id: int
        balances: Dict[str, Decimal]
    
        @classmethod
        def from_dict(cls, data: Dict[str, Any]) -> "CancelOrderResponse":
            """
            APIレスポンスからCancelOrderResponseインスタンスを作成します。
    
            Args:
                data: APIレスポンスの辞書
    
            Returns:
                CancelOrderResponseインスタンス
            """
            balances = {k: Decimal(str(v)) for k, v in data.get("funds", {}).items()}
            return cls(order_id=int(data.get("order_id", 0)), balances=balances)
    
        def to_dict(self) -> Dict[str, Any]:
            """
            CancelOrderResponseインスタンスを辞書に変換します。
    
            Returns:
                APIレスポンス形式の辞書
            """
            return {
                "order_id": self.order_id,
                "funds": {k: str(v) for k, v in self.balances.items()},
            }
  • Registration of trade tools (including cancel_order) by calling register_trade_tools during server initialization.
    from zaifer_mcp.tools.trade import register_trade_tools
    from zaifer_mcp.tools.chart import register_chart_tools
    
    register_market_tools(mcp, zaif_api)
    register_account_tools(mcp, zaif_api)
    register_trade_tools(mcp, zaif_api)
  • Input schema: SupportedPair type definition, used for currency_pair parameter.
    SupportedPair = Literal["btc_jpy", "eth_jpy", "xym_jpy"]
  • Helper function: TradeApi.cancel_order method that makes the actual HTTP POST to Zaif API, called by the tool handler.
    def cancel_order(
        self, order_id: int, currency_pair: str = None, is_token: bool = None
    ) -> CancelOrderResponse:
        """
        注文をキャンセル
    
        Args:
            order_id: 注文ID
            currency_pair: 通貨ペア
            is_token: トークン種別(トークンの場合True)
    
        Returns:
            CancelOrderResponseオブジェクト
    
        Note:
            TODO: MCP利用者にis_tokenパラメータを意識させないように隠蔽する方法を検討する。
            将来的には通貨ペアやorder_idから自動的にトークン種別を判定する機能を実装するか、
            または内部的にAPIを呼び分けるなどの方法で対応する。
        """
        params = {"order_id": order_id}
    
        if currency_pair:
            params["currency_pair"] = currency_pair
    
        if is_token is not None:
            params["is_token"] = is_token
    
        params["method"] = "cancel_order"
        data = self.http.post(self.base_url, params)
        return CancelOrderResponse.from_dict(data)
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing authentication requirements, error conditions (ValueError for missing credentials or API errors), and the tool's behavior (cancels orders including partially executed ones, automatically determines currency pair if not specified). It doesn't mention rate limits or whether cancellation is reversible, but covers most critical behavioral aspects.

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 (purpose, usage, prerequisites, parameters, returns, errors) and every sentence adds value. It could be slightly more concise by combining some of the use case examples, but overall it's efficiently organized with no wasted text.

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 this is a mutation tool with no annotations, 2 parameters (one optional), and an output schema, the description provides excellent context. It covers authentication needs, error conditions, parameter semantics, usage scenarios, and references the output structure (CancelOrderResponse with order_id and balances). The presence of an output schema means the description doesn't need to detail return values, which it appropriately references instead.

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 adds significant value beyond the input schema, which has 0% description coverage. It explains that 'order_id' can be obtained from 'get_open_orders', provides the meaning and format of 'currency_pair' values with Japanese translations, and clarifies that currency_pair is optional with system fallback behavior. This fully compensates for the schema's lack of documentation.

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 ('cancel'), target resource ('unexecuted cryptocurrency trading orders'), and scope ('including partially executed orders'). It distinguishes from siblings like 'get_open_orders' (which lists orders) and 'place_order' (which creates orders) by focusing on cancellation of existing orders.

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?

The description explicitly states when to use this tool ('for orders that are already placed and unexecuted'), provides three concrete use cases (price changes, wrong orders, long-unfilled orders), and mentions prerequisites (API key/secret must be configured). It clearly differentiates from alternatives by specifying it works on orders obtained from 'get_open_orders'.

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/curio184/zaifer-mcp'

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