Skip to main content
Glama

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
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

  • 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, )
  • Invocation of add_tools on the trading module, which defines and registers the close_positions tool via FastMCP decorators.
    trading.add_tools(mcp)
  • 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, )

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