close_positions
Liquidate all positions at market price on OKX cryptocurrency exchange. Specify instrument ID and margin mode to execute immediate closure of trading positions.
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)The handler function decorated with @mcp.tool that defines and implements the close_positions tool. It validates inputs using Pydantic Fields and delegates to the OKX TradeAPI.close_positions method.@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:26-26 (registration)Invocation of add_tools on the trading module, which defines and registers the close_positions tool via FastMCP decorators.trading.add_tools(mcp)
- mcp_okx/trading.py:8-14 (helper)Initialization of the TradeAPI instance (ACCOUNT) used by the close_positions handler to interact with the OKX API.ACCOUNT = TradeAPI( api_key=OKX_API_KEY, api_secret_key=OKX_API_SECRET, passphrase=OKX_PASSPHRASE, flag=OKX_TRADE_FLAG, domain=OKX_BASE_URL, )