Skip to main content
Glama

get_trades

Retrieve recent trading activity for cryptocurrency pairs on supported exchanges like MEXC, Gate.io, Bitget, and Kraken to analyze market movements and execution data.

Instructions

Get recent trades for a trading pair on a supported exchange

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exchangeYesExchange to query. Supported: mexc, gateio, bitget, kraken
symbolYesTrading pair symbol (e.g., BTC/USDT, INDY/USDT)
limitNoNumber of results to return (default: 20, max: 100)

Implementation Reference

  • Main MCP tool registration and handler implementation for get_trades. Defines the tool with parameters (exchange, symbol, limit), validates inputs, retrieves trades from the exchange connector, and returns formatted trade data with summary statistics.
    server.tool(
      'get_trades',
      'Get recent trades for a trading pair on a supported exchange',
      {
        exchange: ExchangeParam,
        symbol: SymbolParam,
        limit: LimitParam(20, 100),
      },
      async ({ exchange, symbol, limit }) => {
        const validExchange = validateExchange(exchange);
        const validSymbol = validateSymbol(symbol);
    
        const connector = await getConnectorSafe(exchange);
        const trades = await connector.getRecentTrades(validSymbol);
    
        const limitedTrades = trades.slice(0, limit);
    
        const buyTrades = limitedTrades.filter((t) => t.side === 'buy');
        const sellTrades = limitedTrades.filter((t) => t.side === 'sell');
        const totalVolume = limitedTrades.reduce((sum, trade) => sum + trade.price * trade.amount, 0);
    
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(
                {
                  symbol: validSymbol,
                  trades: limitedTrades,
                  summary: {
                    totalTrades: limitedTrades.length,
                    buyTrades: buyTrades.length,
                    sellTrades: sellTrades.length,
                    totalVolume,
                  },
                  exchange: validExchange,
                },
                null,
                2
              ),
            },
          ],
        };
      }
    );
  • Schema definitions for the get_trades tool parameters: ExchangeParam (validates exchange string), SymbolParam (validates trading pair symbol), and LimitParam (numeric limit with min/max constraints and default value).
    export const ExchangeParam = z
      .string()
      .describe('Exchange to query. Supported: mexc, gateio, bitget, kraken');
    
    export const SymbolParam = z.string().describe('Trading pair symbol (e.g., BTC/USDT, INDY/USDT)');
    
    export const OptionalSymbolParam = z
      .string()
      .optional()
      .describe('Optional trading pair to filter by (e.g., BTC/USDT). Returns all if omitted.');
    
    export function LimitParam(defaultValue: number, max: number) {
      return z
        .number()
        .min(1)
        .max(max)
        .default(defaultValue)
        .describe(`Number of results to return (default: ${defaultValue}, max: ${max})`);
    }
  • Helper function validateSymbol that validates and normalizes trading pair symbols (converts to uppercase, checks format like BTC/USDT or BTCUSDT).
    export function validateSymbol(symbol: string): string {
      if (!symbol) {
        throw new Error('Symbol is required');
      }
      const upper = symbol.toUpperCase();
      if (!/^[A-Z]+\/[A-Z]+$/.test(upper) && !/^[A-Z]+[A-Z]+$/.test(upper)) {
        throw new Error(`Invalid symbol format: ${symbol}. Expected: BTC/USDT or BTCUSDT`);
      }
      return upper;
    }
  • Helper functions for exchange management: validateExchange (checks against supported exchanges list) and getConnectorSafe (retrieves the exchange connector with error handling).
    export function validateExchange(exchange: string): SupportedExchange {
      const lower = exchange.toLowerCase();
      if (!(SUPPORTED_EXCHANGES as readonly string[]).includes(lower)) {
        throw new Error(
          `Unsupported exchange: ${exchange}. Supported: ${SUPPORTED_EXCHANGES.join(', ')}`
        );
      }
      return lower as SupportedExchange;
    }
    
    export async function getConnectorSafe(exchange: string): Promise<BaseExchangeConnector> {
      const validExchange = validateExchange(exchange);
      const { ExchangeFactory } = await import('@3rd-eye-labs/openmm');
      try {
        return await ExchangeFactory.getExchange(validExchange as any);
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        throw new Error(`Failed to connect to ${validExchange}: ${message}`);
      }
    }
  • src/tools/index.ts:9-9 (registration)
    Registration call that registers all market data tools (including get_trades) with the MCP server.
    registerMarketDataTools(server);
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'recent trades' but doesn't specify what 'recent' means (e.g., time window, pagination), whether there are rate limits, authentication requirements, or what format the results will be in. This leaves significant gaps for an agent to understand the tool's behavior.

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 gets straight to the point with no wasted words. It's appropriately sized for a straightforward data retrieval tool and front-loads the essential information.

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?

For a data retrieval tool with no annotations and no output schema, the description is insufficient. It doesn't explain what 'recent' means, the structure of returned trade data, potential errors, or how it differs from sibling tools. Given the complexity of trading data and lack of structured output information, more context is needed.

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 already documents all three parameters thoroughly. The description doesn't add any meaningful parameter semantics 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.

Purpose4/5

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

The description clearly states the action ('Get recent trades') and resource ('for a trading pair on a supported exchange'), making the purpose immediately understandable. It doesn't explicitly differentiate from siblings like 'get_orderbook' or 'get_ticker', but the focus on trades is specific enough to avoid confusion with those alternatives.

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 like 'get_orderbook' or 'get_ticker', nor does it mention prerequisites or exclusions. It simply states what the tool does without contextual usage information.

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/QBT-Labs/openmm-mcp'

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