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