get-historical-analysis
Analyze historical cryptocurrency prices by specifying the symbol, time interval, and duration. Customize the analysis to identify trends and patterns over a selected timeframe.
Instructions
Get historical price analysis with customizable timeframe
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No | Number of days to analyze (1-30) | |
| interval | No | Time interval (m5, m15, m30, h1, h2, h6, h12, d1) | h1 |
| symbol | Yes | Cryptocurrency symbol (e.g., BTC, ETH) |
Implementation Reference
- src/tools/historical.ts:11-45 (handler)The handler function that executes the get-historical-analysis tool. It validates input using Zod schema, fetches asset data and historical prices from CoinCap API, handles errors, and formats the response.export async function handleGetHistoricalAnalysis(args: unknown) { const { symbol, interval, days } = GetHistoricalAnalysisSchema.parse(args); const upperSymbol = symbol.toUpperCase(); const assetsData = await getAssets(); if (!assetsData) { return { content: [{ type: "text", text: "Failed to retrieve cryptocurrency data" }], }; } const asset = assetsData.data.find( (a: { symbol: string; }) => a.symbol.toUpperCase() === upperSymbol ); if (!asset) { return { content: [{ type: "text", text: `Could not find cryptocurrency with symbol ${upperSymbol}` }], }; } const end = Date.now(); const start = end - (days * 24 * 60 * 60 * 1000); const historyData = await getHistoricalData(asset.id, interval, start, end); if (!historyData || !historyData.data.length) { return { content: [{ type: "text", text: "Failed to retrieve historical data" }], }; } return { content: [{ type: "text", text: formatHistoricalAnalysis(asset, historyData.data) }], }; }
- src/tools/historical.ts:5-9 (schema)Zod schema used for input validation within the handler function.export const GetHistoricalAnalysisSchema = z.object({ symbol: z.string().min(1), interval: z.enum(['m5', 'm15', 'm30', 'h1', 'h2', 'h6', 'h12', 'd1']).default('h1'), days: z.number().min(1).max(30).default(7), });
- src/index.ts:60-82 (registration)Tool registration in the ListTools handler, including name, description, and input schema.name: "get-historical-analysis", description: "Get historical price analysis with customizable timeframe", inputSchema: { type: "object", properties: { symbol: { type: "string", description: "Cryptocurrency symbol (e.g., BTC, ETH)", }, interval: { type: "string", description: "Time interval (m5, m15, m30, h1, h2, h6, h12, d1)", default: "h1", }, days: { type: "number", description: "Number of days to analyze (1-30)", default: 7, }, }, required: ["symbol"], }, },
- src/index.ts:97-98 (registration)Switch case in CallTool handler that routes to the get-historical-analysis handler function.case "get-historical-analysis": return await handleGetHistoricalAnalysis(args);
- src/index.ts:15-15 (registration)Import of the handler function from tools/index.js for use in server setup.} from './tools/index.js';