Skip to main content
Glama
aahl

OKX MCP Server

by aahl

market_tickers

Retrieve real-time cryptocurrency market data including prices, bid/ask spreads, and 24-hour trading volumes. Sort and rank coins by price changes or trading activity to identify market trends.

Instructions

Retrieve the latest price snapshot, best bid/ask price, and trading volume in the last 24 hours.Get the ranking of coins with the highest increase or the largest trading volume.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instTypeNoInstrument type: [SPOT/SWAP/FUTURES/OPTION]SPOT
instFamilyNoInstrument family。 Applicable to FUTURES/SWAP/OPTION
sortByNoSorting method: [change24h/changeMax/last/vol24h/...]change24h
limitNoNumber of results. Default: 30

Implementation Reference

  • The core handler function for the 'market_tickers' tool. It calls the OKX MarketAPI.get_tickers, processes the data by calculating change24h and changeMax, sorts by the specified field, limits the results, and includes a response schema.
    def market_tickers(
        instType: str = Field("SPOT", description="Instrument type: [SPOT/SWAP/FUTURES/OPTION]"),
        instFamily: str = Field("", description="Instrument family。 Applicable to FUTURES/SWAP/OPTION"),
        sortBy: str = Field("change24h", description="Sorting method: [change24h/changeMax/last/vol24h/...]"),
        limit: int | str = Field(30, description="Number of results. Default: 30"),
    ):
        resp = ACCOUNT.get_tickers(instType=instType, instFamily=instFamily) or {}
        if int(resp.get("code", 0)):
            return resp
        data = resp.get("data", [])
        for item in data:
            try:
                item["change24h"] = round((float(item["last"]) - float(item["open24h"])) / float(item["open24h"]) * 100, 2)
                item["changeMax"] = round((float(item["high24h"]) - float(item["low24h"])) / float(item["low24h"]) * 100, 2)
            except Exception:
                continue
        data.sort(key=lambda x: float(x.get(sortBy) or 0), reverse=True)
        resp["data"] = data[:int(limit)]
        resp["_response_schema"] = """
        instType	String	Instrument type
        instId	String	Instrument ID
        last	String	Last traded price
        lastSz	String	Last traded size. 0 represents there is no trading volume
        askPx	String	Best ask price
        askSz	String	Best ask size
        bidPx	String	Best bid price
        bidSz	String	Best bid size
        open24h	String	Open price in the past 24 hours
        high24h	String	Highest price in the past 24 hours
        low24h	String	Lowest price in the past 24 hours
        volCcy24h	String	24h trading volume, with a unit of currency.
            If it is a derivatives contract, the value is the number of base currency. e.g. the unit is BTC for BTC-USD-SWAP and BTC-USDT-SWAP
            If it is SPOT/MARGIN, the value is the quantity in quote currency.
        vol24h	String	24h trading volume, with a unit of contract.
            If it is a derivatives contract, the value is the number of contracts.
            If it is SPOT/MARGIN, the value is the quantity in base currency.
        sodUtc0	String	Open price in the UTC 0
        sodUtc8	String	Open price in the UTC 8
        change24h   float   Percentage change over 24 hours
        changeMax   float   24-hour high and low percentage range
        """
        return resp
  • Tool schema definition including title, description, and input parameters with Pydantic Field validations for the market_tickers tool.
    @mcp.tool(
        title="Get market tickers",
        description="Retrieve the latest price snapshot, best bid/ask price, and trading volume in the last 24 hours."
                    "Get the ranking of coins with the highest increase or the largest trading volume.",
    )
    def market_tickers(
        instType: str = Field("SPOT", description="Instrument type: [SPOT/SWAP/FUTURES/OPTION]"),
        instFamily: str = Field("", description="Instrument family。 Applicable to FUTURES/SWAP/OPTION"),
        sortBy: str = Field("change24h", description="Sorting method: [change24h/changeMax/last/vol24h/...]"),
        limit: int | str = Field(30, description="Number of results. Default: 30"),
    ):
  • Registration of the market tools (including market_tickers) by calling add_tools on the FastMCP instance.
    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