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
| Name | Required | Description | Default |
|---|---|---|---|
| exchangeId | Yes | Exchange ID (e.g., 'binance', 'coinbase') | |
| limit | No | Limit the number of candles returned (optional) | |
| since | No | Timestamp in ms to fetch data since (optional) | |
| symbol | Yes | Trading symbol (e.g., 'BTC/USDT') | |
| timeframe | No | Timeframe (e.g., '1m', '5m', '1h', '1d') | 1h |
Implementation Reference
- src/tools/market-tools.ts:206-245 (handler)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 }; } }
- src/tools/market-tools.ts:199-205 (schema)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)") },
- src/tools/market-tools.ts:196-247 (registration)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);