Skip to main content
Glama
aahl

OKX MCP Server

by aahl

Close positions

close_positions

Liquidate all positions in a designated trading product at market price on OKX to manage risk or exit trades.

Instructions

Liquidate all positions in the designated trading product at market price on OKX

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instIdYesInstrument ID, e.g. BTC-USDT
mgnModeYesMargin mode: `cross`/`isolated`
posSideNoPosition side. This parameter can be omitted in `net` mode, and the default value is `net`. You can only fill with `net`. This parameter must be filled in under the `long/short` mode. Fill in `long` for close-long and `short` for close-short.
ccyNoMargin currency, required in the case of closing `cross` `MARGIN` position for `Futures mode`
autoCxlNoWhether any pending orders for closing out needs to be automatically canceled when close position via a market order.`false` or `true`, the default is `false`
clOrdIdNoClient-supplied ID. A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.
tagNoOrder tag. A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters

Implementation Reference

  • MCP tool handler function that implements the 'close_positions' logic by wrapping the OKX TradeAPI.close_positions method with input validation via Pydantic Fields.
    @mcp.tool(
        title="Close positions",
        description="Liquidate all positions in the designated trading product at market price on OKX",
    )
    def close_positions(
        instId: str = Field(description="Instrument ID, e.g. BTC-USDT"),
        mgnMode: str = Field(description="Margin mode: `cross`/`isolated`"),
        posSide: str = Field("", description="Position side. "
                                             "This parameter can be omitted in `net` mode, and the default value is `net`. You can only fill with `net`. "
                                             "This parameter must be filled in under the `long/short` mode. Fill in `long` for close-long and `short` for close-short."),
        ccy: str = Field("", description="Margin currency, required in the case of closing `cross` `MARGIN` position for `Futures mode`"),
        autoCxl: Any = Field("", description="Whether any pending orders for closing out needs to be automatically canceled when close position via a market order."
                                             "`false` or `true`, the default is `false`"),
        clOrdId: str = Field("", description="Client-supplied ID. A combination of case-sensitive alphanumerics, "
                                             "all numbers, or all letters of up to 32 characters."),
        tag: str = Field("", description="Order tag. A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters"),
    ):
        return ACCOUNT.close_positions(
            instId=instId,
            mgnMode=mgnMode,
            posSide=posSide,
            ccy=ccy,
            autoCxl=autoCxl in [True, "true", "yes", 1],
            clOrdId=clOrdId,
            tag=tag,
        )
  • Calls to add_tools from trading module, which defines and registers the 'close_positions' tool using FastMCP decorators.
    account.add_tools(mcp)
    trading.add_tools(mcp)
    market.add_tools(mcp)
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it mentions 'liquidate at market price' (implying immediate execution), it doesn't address critical aspects like whether this is irreversible, what permissions are required, potential rate limits, confirmation requirements, or what happens if the market is illiquid. For a high-stakes financial operation, this is insufficient.

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?

The description is a single, efficient sentence that immediately conveys the core functionality without any wasted words. It's perfectly front-loaded with the essential information about what the tool does.

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 high-risk financial operation with no annotations and no output schema, the description is inadequate. It doesn't explain what happens after liquidation (confirmation? balance updates?), error conditions, or the irreversible nature of the action. The agent lacks critical context about this destructive operation.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all 7 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema. The baseline of 3 is appropriate when the schema does all the parameter documentation work.

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 ('liquidate all positions'), target resource ('designated trading product'), method ('at market price'), and platform ('on OKX'). It uses precise terminology that distinguishes it from other trading tools like place_order or cancel_order.

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

Usage Guidelines4/5

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

The description implies this tool should be used when wanting to exit all positions in a specific instrument, but it doesn't explicitly state when NOT to use it or mention alternatives like partial position closing. It provides clear context but lacks explicit exclusion guidance.

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/aahl/mcp-okx'

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