Skip to main content
Glama
aahl

OKX MCP Server

by aahl

Get account balance

account_balance

Check available cryptocurrency balances and asset holdings in your OKX trading account to monitor portfolio status and prepare for transactions.

Instructions

Retrieve a list of assets (with non-zero balance), remaining balance, and available amount in the OKX trading account

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ccyNoSingle currency or multiple currencies (no more than 20) separated with comma, e.g. BTC or BTC,ETH.Optional, all by default if not passed

Implementation Reference

  • The main handler function for the 'account_balance' tool. It is decorated with @mcp.tool(), takes an optional 'ccy' parameter, calls the OKX AccountAPI.get_account_balance(), handles errors, adds response schema docs, and returns the result.
    @mcp.tool(
        title="Get account balance",
        description="Retrieve a list of assets (with non-zero balance), remaining balance, and available amount in the OKX trading account",
    )
    def account_balance(
        ccy: str = Field("", description="Single currency or multiple currencies (no more than 20) separated with comma, e.g. BTC or BTC,ETH."
                                         "Optional, all by default if not passed"),
    ):
        resp = ACCOUNT.get_account_balance(ccy) or {}
        if int(resp.get("code", 0)):
            return resp
        resp["_response_schema"] = """
        totalEq: The total amount of equity in USD
        isoEq: Isolated margin equity in USD. Applicable to Futures mode/Multi-currency margin/Portfolio margin
        adjEq: Adjusted / Effective equity in USD.
            The net fiat value of the assets in the account that can provide margins for spot, expiry futures, perpetual futures and options under the cross-margin mode.
            In multi-ccy or PM mode, the asset and margin requirement will all be converted to USD value to process the order check or liquidation.
            Due to the volatility of each currency market, our platform calculates the actual USD value of each currency based on discount rates to balance market risks.
            Applicable to Spot mode/Multi-currency margin and Portfolio margin
        availEq: Account level available equity, excluding currencies that are restricted due to the collateralized borrowing limit.
            Applicable to Multi-currency margin/Portfolio margin
        ordFroz: Cross margin frozen for pending orders in USD. Only applicable to Spot mode/Multi-currency margin/Portfolio margin
        imr: Initial margin requirement in USD.
            The sum of initial margins of all open positions and pending orders under cross-margin mode in USD.
            Applicable to Spot mode/Multi-currency margin/Portfolio margin
        mmr: Maintenance margin requirement in USD.
            The sum of maintenance margins of all open positions and pending orders under cross-margin mode in USD.
            Applicable to Spot mode/Multi-currency margin/Portfolio margin
        borrowFroz: Potential borrowing IMR of the account in USD.
            Only applicable to Spot mode/Multi-currency margin/Portfolio margin. It is "" for other margin modes.
        mgnRatio: Maintenance margin ratio in USD. Applicable to Spot mode/Multi-currency margin/Portfolio margin
        notionalUsd: Notional value of positions in USD. Applicable to Spot mode/Multi-currency margin/Portfolio margin
        notionalUsdForBorrow: Notional value for Borrow in USD. Applicable to Spot mode/Multi-currency margin/Portfolio margin
        notionalUsdForSwap: Notional value of positions for Perpetual Futures in USD. Applicable to Multi-currency margin/Portfolio margin
        notionalUsdForFutures: Notional value of positions for Expiry Futures in USD. Applicable to Multi-currency margin/Portfolio margin
        notionalUsdForOption: Notional value of positions for Option in USD. Applicable to Spot mode/Multi-currency margin/Portfolio margin
        upl: Cross-margin info of unrealized profit and loss at the account level in USD. Applicable to Multi-currency margin/Portfolio margin
        details: Detailed asset information in all currencies
        details.ccy: Currency
        details.eq: Equity of currency
        details.cashBal: Cash balance
        details.disEq: Discount equity of currency in USD. Applicable to Spot mode(enabled spot borrow)/Multi-currency margin/Portfolio margin
        details.fixedBal: Frozen balance for Dip Sniper and Peak Sniper
        details.availBal: Available balance of currency
        details.frozenBal: Frozen balance of currency
        details.ordFrozen: Margin frozen for open orders. Applicable to Spot mode/Futures mode/Multi-currency margin
        details.liab: Liabilities of currency. It is a positive value, e.g. 21625.64; Applicable to Spot mode/Multi-currency margin/Portfolio margin
        details.uplLiab: Liabilities due to Unrealized loss of currency. Applicable to Multi-currency margin/Portfolio margin
        details.crossLiab: Cross liabilities of currency. Applicable to Spot mode/Multi-currency margin/Portfolio margin
        details.rewardBal: Trial fund balance
        details.isoLiab: Isolated liabilities of currency. Applicable to Multi-currency margin/Portfolio margin
        details.interest: Accrued interest of currency. It is a positive value, e.g. 9.01; Applicable to Spot mode/Multi-currency margin/Portfolio margin
        details.twap: Risk indicator of forced repayment. Divided into multiple levels from 0 to 5, the larger the number, 
            the more likely the forced repayment will be triggered. Applicable to Spot mode/Multi-currency margin/Portfolio margin
        details.frpType: Forced repayment (FRP) type. 0: no FRP; 1: user based FRP; 2: platform based FRP; 
            Return 1/2 when twap is >= 1, applicable to Spot mode/Multi-currency margin/Portfolio margin
        details.maxLoan: Max loan of currency. Applicable to cross of Spot mode/Multi-currency margin/Portfolio margin
        details.eqUsd: Equity in USD of currency
        details.borrowFroz: Potential borrowing IMR of currency in USD. Applicable to Multi-currency margin/Portfolio margin. It is "" for other margin modes.
        details.notionalLever: Leverage of currency. Applicable to Futures mode
        details.stgyEq: Strategy equity
        details.isoUpl: Isolated unrealized profit and loss of currency. Applicable to Futures mode/Multi-currency margin/Portfolio margin
        details.spotInUseAmt: Spot in use amount. Applicable to Portfolio margin
        details.clSpotInUseAmt: User-defined spot risk offset amount. Applicable to Portfolio margin
        details.maxSpotInUse: Max possible spot risk offset amount. Applicable to Portfolio margin
        details.spotIsoBal: Spot isolated balance. Applicable to copy trading. Applicable to Spot mode/Futures mode.
        details.smtSyncEq: Smart sync equity. The default is "0", only applicable to copy trader
        details.spotCopyTradingEq: Spot smart sync equity. The default is "0", only applicable to copy trader.
        details.spotBal: Spot balance. The unit is currency, e.g. BTC
        details.openAvgPx: Spot average cost price. The unit is USD
        details.accAvgPx: Spot accumulated cost price. The unit is USD
        details.spotUpl: Spot unrealized profit and loss. The unit is USD
        details.spotUplRatio: Spot unrealized profit and loss ratio
        details.totalPnl: Spot accumulated profit and loss. The unit is USD
        details.totalPnlRatio: Spot accumulated profit and loss ratio
        details.colRes: Platform level collateral restriction status.
            0: The restriction is not enabled.
            1: The restriction is not enabled. But the crypto is close to the platform's collateral limit.
            2: The restriction is enabled. This crypto can't be used as margin for your new orders. This may result in failed orders.
            But it will still be included in the account's adjusted equity and doesn't impact margin ratio.
        details.colBorrAutoConversion: Risk indicator of auto conversion. Divided into multiple levels from 1-5, the larger the number, the more likely the repayment will be triggered. The default will be 0, indicating there is no risk currently. 5 means this user is undergoing auto conversion now, 4 means this user will undergo auto conversion soon whereas 1/2/3 indicates there is a risk for auto conversion.
            Applicable to Spot mode/Futures mode/Multi-currency margin/Portfolio margin.
            When the total liability for each crypto set as collateral exceeds a certain percentage of the platform's total limit, the auto-conversion mechanism may be triggered.
            This may result in the automatic sale of excess collateral crypto if you've set this crypto as collateral and have large borrowings.
            To lower this risk, consider reducing your use of the crypto as collateral or reducing your liabilities.
        details.collateralEnabled: true: Collateral enabled; false: Collateral disabled. Applicable to Multi-currency margin
        details.autoLendStatus: Auto lend status
            unsupported: auto lend is not supported by this currency
            off: auto lend is supported but turned off
            pending: auto lend is turned on but pending matching
            active: auto lend is turned on and matched
        details.autoLendMtAmt: Auto lend currency matched amount.
            Return "0" when autoLendStatus is unsupported/off/pending. Return matched amount when autoLendStatus is active
        """
        return resp
  • Registration of tools by creating FastMCP instance and calling add_tools from account, trading, and market modules, which includes registering the 'account_balance' tool via its @mcp.tool decorator.
    mcp = FastMCP(name="mcp-okx", version="0.1.0", auth=verifier)
    account.add_tools(mcp)
    trading.add_tools(mcp)
    market.add_tools(mcp)
  • Initialization of the OKX AccountAPI client instance used by the account_balance handler to fetch balance data.
    ACCOUNT = AccountAPI(
        api_key=OKX_API_KEY,
        api_secret_key=OKX_API_SECRET,
        passphrase=OKX_PASSPHRASE,
        flag=OKX_TRADE_FLAG,
        domain=OKX_BASE_URL,
    )
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses that the tool retrieves non-zero balance assets and includes remaining/available amounts, which is useful behavioral context. However, it doesn't mention rate limits, authentication requirements, error conditions, or response format details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, well-structured sentence that efficiently conveys the tool's purpose without unnecessary words. It's appropriately sized and front-loaded with the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a read-only tool with one well-documented parameter but no output schema, the description provides adequate context about what data is retrieved. However, it lacks details about response structure, pagination, or error handling that would be helpful for an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents the single parameter. The description doesn't add any parameter-specific information beyond what's in the schema, maintaining the baseline score for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Retrieve'), resource ('assets', 'balance', 'available amount'), and scope ('in the OKX trading account'). It distinguishes from siblings by focusing on balance retrieval rather than positions, orders, or configuration.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for checking account balances but doesn't explicitly state when to use this tool versus alternatives like account_positions or account_position_risk. No guidance is provided about prerequisites, timing, or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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