Skip to main content
Glama
mbarinov

OKX MCP Server

by mbarinov

get_order_history

Read-onlyIdempotent

Retrieve filled order history for specific instruments within defined time periods to analyze trading activity and performance.

Instructions

Get a list of filled orders for a given date range and optional symbol filter

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
beginNothe beginning of the time range in timestamp format
endNothe end of the time range in timestamp format
instIdYesInstrument ID (symbol), e.g. BTC-USDT

Implementation Reference

  • The main execution handler for the get_order_history tool. It invokes the OKX API client to retrieve order history and formats the response as text content.
    export default async function get_order_history({
      instId,
      begin,
      end,
    }: InferSchema<typeof schema>) {
      try {
        const orderHistory = await okxApiClient.getOrderHistory(instId, begin, end);
        return {
          content: [{ type: "text", text: JSON.stringify(orderHistory, null, 2) }],
        };
      } catch (error) {
        const message =
          error instanceof Error ? error.message : "An unknown error occurred";
        return {
          content: [
            { type: "text", text: JSON.stringify({ error: message }, null, 2) },
          ],
        };
      }
    }
  • Zod-based input schema defining parameters: instId (required string), begin and end (optional numbers for timestamp range).
    export const schema = {
      instId: z.string().describe("Instrument ID (symbol), e.g. BTC-USDT"),
      begin: z
        .number()
        .optional()
        .describe("the beginning of the time range in timestamp format"),
      end: z
        .number()
        .optional()
        .describe("the end of the time range in timestamp format"),
    };
  • Tool metadata registration, specifying the name 'get_order_history', description, and annotations for MCP tool protocol.
    export const metadata = {
      name: "get_order_history",
      description:
        "Get a list of filled orders for a given date range and optional symbol filter",
      annotations: {
        title: "Get Order History",
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
      },
    };
  • Supporting helper method in OkxApiClient class that interfaces with the OKX REST API to fetch order history for SPOT instruments, processes the response, and handles errors.
    async getOrderHistory(instId: string, begin?: number, end?: number) {
      try {
        const response = await client.getOrderHistory({
          instType: "SPOT",
          instId,
          begin: begin?.toString(),
          end: end?.toString(),
        });
        return response.map((order) => ({
          orderId: order.ordId,
          symbol: order.instId,
          price: parseFloat(order.avgPx),
          amount: parseFloat(order.sz),
          side: order.side,
          realizedPnl: parseFloat(order.pnl),
        }));
      } catch (error) {
        console.error("Error fetching order history:", error);
        throw error;
      }
    }
Behavior3/5

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

Annotations already declare readOnlyHint=true, idempotentHint=true, and destructiveHint=false, so the agent knows this is a safe, repeatable read operation. The description adds minimal behavioral context beyond this—it specifies that it retrieves 'filled orders' (implying historical data) and mentions filtering, but doesn't cover aspects like pagination, rate limits, or authentication needs. With annotations covering core safety, a baseline 3 is appropriate as the description adds some value but not rich behavioral 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, efficient sentence that directly states the tool's function and key parameters. It's front-loaded with the core purpose ('Get a list of filled orders') and includes essential filtering details without unnecessary elaboration. Every word earns its place, making it highly concise and well-structured.

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?

Given the tool's moderate complexity (3 parameters, no output schema), the description is adequate but has gaps. It covers the basic purpose and filtering, but lacks details on output format, error handling, or integration with sibling tools. Annotations provide safety context, but without an output schema, the description could better prepare the agent for what to expect from the response. It's minimally viable but not fully comprehensive.

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%, with clear documentation for each parameter (begin, end, instId). The description adds marginal semantic value by framing 'instId' as an 'optional symbol filter' (though the schema marks it as required) and specifying 'date range', but doesn't provide additional syntax, format details, or constraints beyond what the schema already states. Baseline 3 is correct when the schema does the heavy lifting.

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: 'Get a list of filled orders' with filtering by 'date range and optional symbol filter'. It specifies the verb ('Get') and resource ('filled orders'), making the intent unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'get_open_orders' (which likely shows unfilled orders), leaving some room for improvement.

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 mentions filtering capabilities but doesn't clarify scenarios where it's preferred over other tools like 'get_open_orders' or 'get_account_summary'. There's no mention of prerequisites, exclusions, or comparative use cases, leaving the agent to infer usage context.

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/mbarinov/okx-mcp'

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