Skip to main content
Glama
al-one

MCP Server for stock and crypto

获取加密货币历史价格

okx_prices

Retrieve historical cryptocurrency price data from OKX exchange for analysis, including candlestick charts, trading volume, and technical indicators.

Instructions

获取OKX加密货币的历史K线数据,包括价格、交易量和技术指标

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instIdNo产品ID,格式: BTC-USDTBTC-USDT
barNoK线时间粒度,仅支持: [1m/3m/5m/15m/30m/1H/2H/4H/6H/12H/1D/2D/3D/1W/1M/3M] 除分钟为小写m外,其余均为大写1H
limitNo返回数量(int),最大300,最小建议30

Implementation Reference

  • The core handler function for the 'okx_prices' tool. It fetches historical candlestick data from OKX API, processes it into a DataFrame, adds technical indicators (MACD, KDJ, RSI, Bollinger Bands), and returns a formatted CSV snippet.
    def okx_prices(
        instId: str = Field("BTC-USDT", description="产品ID,格式: BTC-USDT"),
        bar: str = Field("1H", description="K线时间粒度,仅支持: [1m/3m/5m/15m/30m/1H/2H/4H/6H/12H/1D/2D/3D/1W/1M/3M] 除分钟为小写m外,其余均为大写"),
        limit: int = Field(100, description="返回数量(int),最大300,最小建议30", strict=False),
    ):
        if not bar.endswith("m"):
            bar = bar.upper()
        res = requests.get(
            f"{OKX_BASE_URL}/api/v5/market/candles",
            params={
                "instId": instId,
                "bar": bar,
                "limit": max(300, limit + 62),
            },
            timeout=20,
        )
        data = res.json() or {}
        dfs = pd.DataFrame(data.get("data", []))
        if dfs.empty:
            return pd.DataFrame()
        dfs.columns = ["时间", "开盘", "最高", "最低", "收盘", "成交量", "成交额", "成交额USDT", "K线已完结"]
        dfs.sort_values("时间", inplace=True)
        dfs["时间"] = pd.to_datetime(dfs["时间"], errors="coerce", unit="ms")
        dfs["开盘"] = pd.to_numeric(dfs["开盘"], errors="coerce")
        dfs["最高"] = pd.to_numeric(dfs["最高"], errors="coerce")
        dfs["最低"] = pd.to_numeric(dfs["最低"], errors="coerce")
        dfs["收盘"] = pd.to_numeric(dfs["收盘"], errors="coerce")
        dfs["成交量"] = pd.to_numeric(dfs["成交量"], errors="coerce")
        dfs["成交额"] = pd.to_numeric(dfs["成交额"], errors="coerce")
        add_technical_indicators(dfs, dfs["收盘"], dfs["最低"], dfs["最高"])
        columns = [
            "时间", "开盘", "收盘", "最高", "最低", "成交量", "成交额",
            "MACD", "DIF", "DEA", "KDJ.K", "KDJ.D", "KDJ.J", "RSI", "BOLL.U", "BOLL.M", "BOLL.L",
        ]
        all = dfs.to_csv(columns=columns, index=False, float_format="%.2f").strip().split("\n")
        return "\n".join([all[0], *all[-limit:]])
  • The @mcp.tool decorator that registers the 'okx_prices' function as an MCP tool with its title and description.
    @mcp.tool(
        title="获取加密货币历史价格",
        description="获取OKX加密货币的历史K线数据,包括价格、交易量和技术指标",
    )
  • Pydantic Field definitions for the input parameters: instId (product ID), bar (time granularity), limit (number of records). These define the tool's input schema.
    def okx_prices(
        instId: str = Field("BTC-USDT", description="产品ID,格式: BTC-USDT"),
        bar: str = Field("1H", description="K线时间粒度,仅支持: [1m/3m/5m/15m/30m/1H/2H/4H/6H/12H/1D/2D/3D/1W/1M/3M] 除分钟为小写m外,其余均为大写"),
        limit: int = Field(100, description="返回数量(int),最大300,最小建议30", strict=False),
    ):
  • Helper function that adds technical indicators (MACD, DIF, DEA, KDJ.K/D/J, RSI, BOLL.U/M/L) to the price DataFrame, used by okx_prices.
    def add_technical_indicators(df, clos, lows, high):
        # 计算MACD指标
        ema12 = clos.ewm(span=12, adjust=False).mean()
        ema26 = clos.ewm(span=26, adjust=False).mean()
        df["DIF"] = ema12 - ema26
        df["DEA"] = df["DIF"].ewm(span=9, adjust=False).mean()
        df["MACD"] = (df["DIF"] - df["DEA"]) * 2
    
        # 计算KDJ指标
        low_min  = lows.rolling(window=9, min_periods=1).min()
        high_max = high.rolling(window=9, min_periods=1).max()
        rsv = (clos - low_min) / (high_max - low_min) * 100
        df["KDJ.K"] = rsv.ewm(com=2, adjust=False).mean()
        df["KDJ.D"] = df["KDJ.K"].ewm(com=2, adjust=False).mean()
        df["KDJ.J"] = 3 * df["KDJ.K"] - 2 * df["KDJ.D"]
    
        # 计算RSI指标
        delta = clos.diff()
        gain = delta.where(delta > 0, 0)
        loss = -delta.where(delta < 0, 0)
        avg_gain = gain.rolling(window=14).mean()
        avg_loss = loss.rolling(window=14).mean()
        rs = avg_gain / avg_loss
        df["RSI"] = 100 - (100 / (1 + rs))
    
        # 计算布林带指标
        df["BOLL.M"] = clos.rolling(window=20).mean()
        std = clos.rolling(window=20).std()
        df["BOLL.U"] = df["BOLL.M"] + 2 * std
        df["BOLL.L"] = df["BOLL.M"] - 2 * std
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the data includes '价格、交易量和技术指标' (price, trading volume, and technical indicators), which adds some context about return content. However, it doesn't cover critical aspects like rate limits, authentication needs, data freshness, error handling, or whether this is a read-only operation. For a data retrieval tool with no annotations, this leaves significant gaps.

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

Conciseness4/5

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

The description is a single, efficient sentence that front-loads the core purpose. It avoids redundancy and wastes no words. However, it could be slightly more structured by separating key points, but it's appropriately concise for the tool's complexity.

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

Completeness2/5

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

Given no annotations and no output schema, the description is incomplete. It mentions return data includes price, volume, and technical indicators, but doesn't specify format, structure, or examples. For a data retrieval tool with 3 parameters, more context on behavior and output is needed to be fully helpful to an AI 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?

The input schema has 100% description coverage, providing details for all parameters (instId, bar, limit). The description adds minimal value beyond the schema, only implying that parameters relate to fetching '历史K线数据' (historical K-line data). No additional semantics, constraints, or examples are provided in the description. Baseline 3 is appropriate given high schema coverage.

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

Purpose4/5

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

The description clearly states the tool's purpose: '获取OKX加密货币的历史K线数据' (get OKX cryptocurrency historical K-line data). It specifies the resource (OKX cryptocurrency data) and verb (get/retrieve). However, it doesn't distinguish this tool from potential siblings like 'stock_prices' or 'okx_taker_volume' beyond mentioning '历史K线数据' (historical K-line data).

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'okx_taker_volume' or 'stock_prices', nor does it specify prerequisites, constraints, or scenarios where this tool is preferred. Usage is implied by the purpose but not explicitly stated.

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/al-one/mcp-aktools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server