Skip to main content
Glama

fetchOHLCV

Retrieve OHLCV candlestick data for cryptocurrency trading pairs from exchanges to analyze market trends and price movements.

Instructions

Fetch OHLCV candlestick data for a symbol on an exchange

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exchangeIdYesExchange ID (e.g., 'binance', 'coinbase')
symbolYesTrading symbol (e.g., 'BTC/USDT')
timeframeNoTimeframe (e.g., '1m', '5m', '1h', '1d')1h
sinceNoTimestamp in ms to fetch data since (optional)
limitNoLimit the number of candles returned (optional)

Implementation Reference

  • Registers the 'fetchOHLCV' tool on the MCP server, including description, input schema, and inline handler function.
      server.tool(
        "fetchOHLCV",
        "Fetch OHLCV candlestick data for a symbol on an exchange",
        {
          exchangeId: z.string().describe("Exchange ID (e.g., 'binance', 'coinbase')"),
          symbol: z.string().describe("Trading symbol (e.g., 'BTC/USDT')"),
          timeframe: z.string().default("1h").describe("Timeframe (e.g., '1m', '5m', '1h', '1d')"),
          since: z.number().optional().describe("Timestamp in ms to fetch data since (optional)"),
          limit: z.number().optional().describe("Limit the number of candles returned (optional)")
        },
        async ({ exchangeId, symbol, timeframe, since, limit }) => {
          try {
            // 공개 인스턴스 사용
            const exchange = ccxtServer.getPublicExchangeInstance(exchangeId);
    
            // 거래소가 OHLCV 데이터를 지원하는지 확인
            if (!exchange.has['fetchOHLCV']) {
              return {
                content: [
                  {
                    type: "text",
                    text: `Exchange ${exchangeId} does not support OHLCV data fetching`
                  }
                ],
                isError: true
              };
            }
            
            const ohlcv = await exchange.fetchOHLCV(symbol, timeframe, since, limit);
            
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify(ohlcv, null, 2)
                }
              ]
            };
          } catch (error) {
            return {
              content: [
                {
                  type: "text",
                  text: `Error fetching OHLCV data: ${(error as Error).message}`
                }
              ],
              isError: true
            };
          }
        }
      );
    }
  • The handler function that implements the core logic: retrieves public CCXT exchange instance, checks support for fetchOHLCV, fetches the data, and returns JSON stringified OHLCV array or error.
      async ({ exchangeId, symbol, timeframe, since, limit }) => {
        try {
          // 공개 인스턴스 사용
          const exchange = ccxtServer.getPublicExchangeInstance(exchangeId);
    
          // 거래소가 OHLCV 데이터를 지원하는지 확인
          if (!exchange.has['fetchOHLCV']) {
            return {
              content: [
                {
                  type: "text",
                  text: `Exchange ${exchangeId} does not support OHLCV data fetching`
                }
              ],
              isError: true
            };
          }
          
          const ohlcv = await exchange.fetchOHLCV(symbol, timeframe, since, limit);
          
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(ohlcv, null, 2)
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error fetching OHLCV data: ${(error as Error).message}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Zod schema for input validation: exchangeId (string), symbol (string), timeframe (string, default '1h'), since (number optional), limit (number optional).
    {
      exchangeId: z.string().describe("Exchange ID (e.g., 'binance', 'coinbase')"),
      symbol: z.string().describe("Trading symbol (e.g., 'BTC/USDT')"),
      timeframe: z.string().default("1h").describe("Timeframe (e.g., '1m', '5m', '1h', '1d')"),
      since: z.number().optional().describe("Timestamp in ms to fetch data since (optional)"),
      limit: z.number().optional().describe("Limit the number of candles returned (optional)")
    },
  • src/server.ts:372-372 (registration)
    Top-level call to registerMarketTools in CcxtMcpServer's registerTools method, which includes registration of fetchOHLCV.
    registerMarketTools(this.server, this);
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't cover important traits like rate limits, authentication requirements, error handling, or the format/scope of returned data (e.g., whether it's historical or real-time). This leaves significant gaps for an agent to understand operational constraints.

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 front-loads the core purpose without any unnecessary words. Every part of the sentence directly contributes to understanding what the tool does, making it highly concise and well-structured for quick comprehension.

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 the complexity of fetching financial data with 5 parameters and no output schema or annotations, the description is incomplete. It doesn't address the return format (e.g., array of candles with OHLCV fields), data recency, or common use cases, which are critical for an agent to use this tool effectively in a trading context.

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%, providing clear documentation for all 5 parameters. The description adds no additional parameter semantics beyond what's in the schema, so it meets the baseline of 3 without compensating for any gaps. It doesn't explain parameter interactions or provide examples beyond the schema's descriptions.

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 ('fetch') and resource ('OHLCV candlestick data for a symbol on an exchange'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like fetchTicker or fetchTrades, which also retrieve market data but for different types of information.

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 fetchTicker (for current price) or fetchTrades (for recent trades). It also doesn't mention prerequisites such as needing a valid exchange ID or symbol format, leaving usage context implied rather than explicit.

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/lazy-dinosaur/ccxt-mcp'

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