Skip to main content
Glama

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

NameRequiredDescriptionDefault
exchangeYesExchange ID (e.g., binance, coinbase)
limitNoNumber of candles to fetch (max 1000)
symbolYesTrading pair symbol (e.g., BTC/USDT)
timeframeNoTimeframe (e.g., 1m, 5m, 1h, 1d)1d

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "exchange": { "description": "Exchange ID (e.g., binance, coinbase)", "type": "string" }, "limit": { "default": 100, "description": "Number of candles to fetch (max 1000)", "type": "number" }, "symbol": { "description": "Trading pair symbol (e.g., BTC/USDT)", "type": "string" }, "timeframe": { "default": "1d", "description": "Timeframe (e.g., 1m, 5m, 1h, 1d)", "type": "string" } }, "required": [ "exchange", "symbol" ], "type": "object" }

Implementation Reference

  • 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 }; } });
  • 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)")
  • 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 }; } });
  • Invocation of registerPublicTools which includes the registration of get-ohlcv among other public tools.
    registerPublicTools(server);

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/doggybee/mcp-server-ccxt'

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