crypto_price_history
Retrieve historical cryptocurrency price data for analysis by specifying a coin and time period.
Instructions
Get price history for a coin over a number of days
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coin | Yes | Coin ID (e.g. bitcoin) | |
| days | No | Number of days (1, 7, 30, 90, 365) |
Implementation Reference
- src/modules/crypto.ts:42-54 (handler)The `crypto_price_history` tool is implemented here, defining the input schema (coin, days) and executing the handler by fetching market data from CoinGecko and formatting the result.
server.tool("crypto_price_history", "Get price history for a coin over a number of days", { coin: z.string().describe("Coin ID (e.g. bitcoin)"), days: z.number().default(7).describe("Number of days (1, 7, 30, 90, 365)") }, async ({ coin, days }) => { const data = await safeFetch(`https://api.coingecko.com/api/v3/coins/${coin}/market_chart?vs_currency=usd&days=${days}`); const prices = data.prices; const first = prices[0][1]; const last = prices[prices.length - 1][1]; const change = ((last - first) / first) * 100; const high = Math.max(...prices.map((p: any) => p[1])); const low = Math.min(...prices.map((p: any) => p[1])); return { content: [{ type: "text", text: `**${coin.toUpperCase()} — ${days}d History**\nStart: ${formatCurrency(first)}\nEnd: ${formatCurrency(last)}\nChange: ${formatPercent(change)}\nHigh: ${formatCurrency(high)}\nLow: ${formatCurrency(low)}\nData Points: ${prices.length}` }] }; });