get-ohlcv
Fetch OHLCV candlestick data for trading pairs from cryptocurrency exchanges using exchange ID, symbol, timeframe, and limit parameters.
Instructions
Get OHLCV candlestick data for a trading pair
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| exchange | Yes | Exchange ID (e.g., binance, coinbase) | |
| limit | No | Number of candles to fetch (max 1000) | |
| symbol | Yes | Trading pair symbol (e.g., BTC/USDT) | |
| timeframe | No | Timeframe (e.g., 1m, 5m, 1h, 1d) | 1d |
Implementation Reference
- src/tools/public.ts:148-176 (handler)The handler function for the 'get-ohlcv' tool. It uses rate limiting and caching to fetch OHLCV candlestick data from the specified exchange using the exchange instance's fetchOHLCV method and returns the data as JSON.}, async ({ exchange, symbol, timeframe, limit }) => { try { return await rateLimiter.execute(exchange, async () => { const ex = getExchange(exchange); const cacheKey = `ohlcv:${exchange}:${symbol}:${timeframe}:${limit}`; const ohlcv = await getCachedData(cacheKey, async () => { log(LogLevel.INFO, `Fetching OHLCV for ${symbol} on ${exchange}, timeframe: ${timeframe}, limit: ${limit}`); return await ex.fetchOHLCV(symbol, timeframe, undefined, limit); }); return { content: [{ type: "text", text: JSON.stringify(ohlcv, null, 2) }] }; }); } catch (error) { log(LogLevel.ERROR, `Error fetching OHLCV data: ${error instanceof Error ? error.message : String(error)}`); return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } });
- src/tools/public.ts:144-147 (schema)Zod input schema for the 'get-ohlcv' tool defining parameters: exchange, symbol, timeframe (optional, default '1d'), and limit (optional, default 100).exchange: z.string().describe("Exchange ID (e.g., binance, coinbase)"), symbol: z.string().describe("Trading pair symbol (e.g., BTC/USDT)"), timeframe: z.string().optional().default("1d").describe("Timeframe (e.g., 1m, 5m, 1h, 1d)"), limit: z.number().optional().default(100).describe("Number of candles to fetch (max 1000)")
- src/tools/public.ts:143-176 (registration)Registration of the 'get-ohlcv' tool using server.tool(), including description, input schema, and inline handler function.server.tool("get-ohlcv", "Get OHLCV candlestick data for a trading pair", { exchange: z.string().describe("Exchange ID (e.g., binance, coinbase)"), symbol: z.string().describe("Trading pair symbol (e.g., BTC/USDT)"), timeframe: z.string().optional().default("1d").describe("Timeframe (e.g., 1m, 5m, 1h, 1d)"), limit: z.number().optional().default(100).describe("Number of candles to fetch (max 1000)") }, async ({ exchange, symbol, timeframe, limit }) => { try { return await rateLimiter.execute(exchange, async () => { const ex = getExchange(exchange); const cacheKey = `ohlcv:${exchange}:${symbol}:${timeframe}:${limit}`; const ohlcv = await getCachedData(cacheKey, async () => { log(LogLevel.INFO, `Fetching OHLCV for ${symbol} on ${exchange}, timeframe: ${timeframe}, limit: ${limit}`); return await ex.fetchOHLCV(symbol, timeframe, undefined, limit); }); return { content: [{ type: "text", text: JSON.stringify(ohlcv, null, 2) }] }; }); } catch (error) { log(LogLevel.ERROR, `Error fetching OHLCV data: ${error instanceof Error ? error.message : String(error)}`); return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } });
- src/tools/index.ts:24-24 (registration)Invocation of registerPublicTools which includes the registration of get-ohlcv among other public tools.registerPublicTools(server);