cmc100IndexHistorical
Retrieve historical CoinMarketCap 100 Index values by specifying interval, start/end times, and number of data points.
Instructions
Returns an interval of historic CoinMarketCap 100 Index values based on the interval parameter.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| time_start | No | ||
| time_end | No | ||
| count | No | ||
| interval | No |
Implementation Reference
- index.js:511-516 (handler)The async handler function for the cmc100IndexHistorical tool that makes an API request to /v3/index/cmc100-historical and formats the response.
async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v3/index/cmc100-historical', params) return formatResponse(data) }) } - index.js:505-510 (schema)Zod schema defining the optional input parameters: time_start, time_end, count (all strings), and interval (enum of '5m', '15m', 'daily').
{ time_start: z.string().optional(), time_end: z.string().optional(), count: z.string().optional(), interval: z.enum(['5m', '15m', 'daily']).optional() }, - index.js:503-517 (registration)Registration of the cmc100IndexHistorical tool via server.tool() with its description, schema, and handler function.
server.tool("cmc100IndexHistorical", "Returns an interval of historic CoinMarketCap 100 Index values based on the interval parameter.", { time_start: z.string().optional(), time_end: z.string().optional(), count: z.string().optional(), interval: z.enum(['5m', '15m', 'daily']).optional() }, async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v3/index/cmc100-historical', params) return formatResponse(data) }) } ) - index.js:82-88 (helper)The handleEndpoint wrapper function used by the tool handler to catch and format errors.
async function handleEndpoint(apiCall) { try { return await apiCall() } catch (error) { return formatErrorResponse(error.message, error.status || 403) } } - index.js:50-73 (helper)The makeApiRequest helper function that builds the URL, makes the fetch call with the API key, and returns JSON data.
async function makeApiRequest(apiKey, endpoint, params = {}) { const queryParams = new URLSearchParams() Object.entries(params).forEach(([key, value]) => { if (value !== undefined) { queryParams.append(key, value.toString()) } }) const url = `https://pro-api.coinmarketcap.com${endpoint}${queryParams.toString() ? `?${queryParams.toString()}` : ''}` const response = await fetch(url, { method: 'GET', headers: { 'Accept': 'application/json', 'X-CMC_PRO_API_KEY': apiKey, } }) if (!response.ok) { throw new Error(`Error fetching data from CoinMarketCap: ${response.statusText}`) } return await response.json() }