Skip to main content
Glama

fetchOHLCV

Retrieve OHLCV candlestick data for any cryptocurrency symbol across multiple exchanges. Specify exchange, symbol, timeframe, and optional parameters to fetch historical market data for analysis.

Instructions

Fetch OHLCV candlestick data for a symbol on an exchange

Input Schema

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

Implementation Reference

  • The main execution logic for the fetchOHLCV tool. It uses a public CCXT exchange instance to check support for fetchOHLCV, fetches the OHLCV candlestick data, and returns it as JSON or an error response.
    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 input schema defining parameters for the fetchOHLCV tool: exchangeId (required), symbol (required), timeframe (default '1h'), since (optional), limit (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)") },
  • Registers the fetchOHLCV tool on the MCP server using server.tool(), including name, description, input schema, and handler function within the registerMarketTools 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 }; } } ); }
  • src/server.ts:372-372 (registration)
    Top-level call to registerMarketTools in CcxtMcpServer's registerTools method, which registers the fetchOHLCV tool among market tools.
    registerMarketTools(this.server, this);

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