Skip to main content
Glama
aahl

OKX MCP Server

by aahl

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)

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