Skip to main content
Glama
aahl

OKX MCP Server

by aahl

account_position_risk

Analyze overall holding risk for your OKX account across margin, futures, swaps, and options to monitor portfolio exposure.

Instructions

Obtain the overall holding risk of the OKX account

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instTypeNoInstrument type: `MARGIN`: 币币杠杆/`SWAP`: 永续合约/`FUTURES`: 交割合约/`OPTION`: 期权. Optional, all by default if not passed

Implementation Reference

  • The handler function for the 'account_position_risk' tool. It calls the OKX AccountAPI to get position risk data based on instrument type and attaches a detailed response schema.
    def account_position_risk(
        instType: str = Field("", description="Instrument type: "
                                              "`MARGIN`: 币币杠杆/"
                                              "`SWAP`: 永续合约/"
                                              "`FUTURES`: 交割合约/"
                                              "`OPTION`: 期权. "
                                              "Optional, all by default if not passed"),
    ):
        resp = ACCOUNT.get_position_risk(instType) or {}
        if int(resp.get("code", 0)):
            return resp
        resp["_response_schema"] = """
        adjEq: Adjusted / Effective equity in USD. Applicable to Multi-currency margin and Portfolio margin
        balData: Detailed asset information in all currencies
        balData.ccy: Currency
        balData.eq: Equity of currency
        balData.disEq: Discount equity of currency in USD
        posData: Detailed position information in all currencies
        posData.mgnMode: Margin mode: cross/isolated
        posData.instId: Instrument ID, e.g. BTC-USDT-SWAP
        posData.pos: Quantity of positions contract. In the isolated margin mode, when doing manual transfers,
            a position with pos of 0 will be generated after the deposit is transferred
        posData.posSide: Position side: long/short
            net (FUTURES/SWAP/OPTION: positive pos means long position and negative pos means short position. MARGIN: posCcy being base currency means long position, posCcy being quote currency means short position.)
        posData.posCcy: Position currency, only applicable to MARGIN positions
        posData.ccy: Currency used for margin
        posData.notionalCcy: Notional value of positions in coin
        posData.notionalUsd: Notional value of positions in USD
        """
        return resp
  • The @mcp.tool decorator registers the account_position_risk tool with FastMCP inside the add_tools function.
    @mcp.tool(
        title="Get account position risk",
        description="Obtain the overall holding risk of the OKX account",
    )
  • Top-level registration call that invokes add_tools from the account module to register all account-related tools, including account_position_risk.
    account.add_tools(mcp)
  • The response schema documentation string attached to the API response for the account_position_risk tool.
    resp["_response_schema"] = """
    adjEq: Adjusted / Effective equity in USD. Applicable to Multi-currency margin and Portfolio margin
    balData: Detailed asset information in all currencies
    balData.ccy: Currency
    balData.eq: Equity of currency
    balData.disEq: Discount equity of currency in USD
    posData: Detailed position information in all currencies
    posData.mgnMode: Margin mode: cross/isolated
    posData.instId: Instrument ID, e.g. BTC-USDT-SWAP
    posData.pos: Quantity of positions contract. In the isolated margin mode, when doing manual transfers,
        a position with pos of 0 will be generated after the deposit is transferred
    posData.posSide: Position side: long/short
        net (FUTURES/SWAP/OPTION: positive pos means long position and negative pos means short position. MARGIN: posCcy being base currency means long position, posCcy being quote currency means short position.)
    posData.posCcy: Position currency, only applicable to MARGIN positions
    posData.ccy: Currency used for margin
    posData.notionalCcy: Notional value of positions in coin
    posData.notionalUsd: Notional value of positions in USD
    """

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