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
| Name | Required | Description | Default |
|---|---|---|---|
| instId | Yes | Instrument ID, e.g. BTC-USDT | |
| mgnMode | Yes | Margin mode: `cross`/`isolated` | |
| posSide | No | 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 | No | Margin currency, required in the case of closing `cross` `MARGIN` position for `Futures mode` | |
| autoCxl | No | 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 | No | Client-supplied ID. A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters. | |
| tag | No | Order tag. A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters |
Implementation Reference
- mcp_okx/trading.py:234-259 (handler)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, )
- mcp_okx/__init__.py:25-27 (registration)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)