candles
Retrieve OHLCV candlestick data for any cryptocurrency. Obtain open, high, low, and close prices for specified historical periods to analyze price action.
Instructions
Get OHLCV candlestick data for any crypto. Returns open, high, low, close for each period.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Crypto symbol | |
| days | No | Number of days of history (1, 7, 14, 30, 90, 180, 365). Default: 7 |
Implementation Reference
- index.js:80-99 (handler)The async function getCryptoCandles(symbol, interval, days) fetches OHLCV candlestick data from the CoinGecko API and maps the response to {time, open, high, low, close} objects.
async function getCryptoCandles(symbol, interval = '1h', days = 7) { const id = symbol.toLowerCase().replace('usdt', '').replace('usd', ''); const idMap = { btc: 'bitcoin', eth: 'ethereum', sol: 'solana', doge: 'dogecoin', xrp: 'ripple', bnb: 'binancecoin', ada: 'cardano', avax: 'avalanche-2', }; const coinId = idMap[id] || id; const data = await fetch( `https://api.coingecko.com/api/v3/coins/${coinId}/ohlc?vs_currency=usd&days=${days}` ); return data.map(c => ({ time: new Date(c[0]).toISOString(), open: c[1], high: c[2], low: c[3], close: c[4], })); } - index.js:249-259 (schema)Tool registration definition for 'candles' with inputSchema requiring 'symbol' (string) and optional 'days' (number).
{ name: 'candles', description: 'Get OHLCV candlestick data for any crypto. Returns open, high, low, close for each period.', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: 'Crypto symbol' }, days: { type: 'number', description: 'Number of days of history (1, 7, 14, 30, 90, 180, 365). Default: 7' } }, required: ['symbol'] } - index.js:236-316 (registration)The getToolDefinitions() method returns all tool definitions including 'candles'. The tools/list MCP method calls this to register tools.
getToolDefinitions() { return [ { name: 'price', description: 'Get current price, 24h change, volume, market cap for any cryptocurrency. Examples: BTC, ETH, SOL, DOGE.', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: 'Crypto symbol (BTC, ETH, SOL, DOGE, etc.)' } }, required: ['symbol'] } }, { name: 'candles', description: 'Get OHLCV candlestick data for any crypto. Returns open, high, low, close for each period.', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: 'Crypto symbol' }, days: { type: 'number', description: 'Number of days of history (1, 7, 14, 30, 90, 180, 365). Default: 7' } }, required: ['symbol'] } }, { name: 'order_book', description: 'Get live order book — top 20 bids and asks with spread. Shows market depth and liquidity.', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: 'Trading pair (BTC, ETHUSDT, etc.)' } }, required: ['symbol'] } }, { name: 'market_cap', description: 'Get top cryptocurrencies ranked by market cap with prices, volumes, and 24h changes.', inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Number of coins to return (default: 20, max: 100)' } } } }, { name: 'trending', description: 'Get trending cryptocurrencies right now — what people are searching for and trading.', inputSchema: { type: 'object', properties: {} } }, { name: 'analyze', description: 'Technical analysis for any crypto: RSI, SMA, volatility, z-score, trend direction. Actionable signals included.', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: 'Crypto symbol' }, days: { type: 'number', description: 'Lookback period in days (default: 30)' } }, required: ['symbol'] } }, { name: 'compare', description: 'Compare multiple assets side by side — prices, changes, market caps.', inputSchema: { type: 'object', properties: { symbols: { type: 'string', description: 'Comma-separated symbols (e.g., "BTC,ETH,SOL")' } }, required: ['symbols'] } }, { name: 'feargreed', description: 'Crypto Fear & Greed Index — market sentiment indicator. Shows last 7 days.', inputSchema: { type: 'object', properties: {} } } ]; } - index.js:318-324 (registration)The handleToolCall() method dispatches the 'candles' case to getCryptoCandles(args.symbol, '1h', args.days || 7). The interval is hardcoded to '1h'.
async handleToolCall(name, args) { switch (name) { case 'price': return await getCryptoPrice(args.symbol); case 'candles': return await getCryptoCandles(args.symbol, '1h', args.days || 7); - index.js:31-44 (helper)The fetch() helper function is used by getCryptoCandles to make HTTPS requests with JSON parsing and timeout handling.
function fetch(url) { return new Promise((resolve, reject) => { const req = https.get(url, { headers: { 'User-Agent': 'mcp-market-data/0.1' } }, (res) => { let data = ''; res.on('data', chunk => data += chunk); res.on('end', () => { try { resolve(JSON.parse(data)); } catch (e) { reject(new Error(`Parse error: ${data.slice(0, 200)}`)); } }); }); req.on('error', reject); req.setTimeout(15000, () => { req.destroy(); reject(new Error('Timeout')); }); }); }