Skip to main content
Glama

dexPairsOhlcvHistorical

Retrieve historical OHLCV and market cap data for cryptocurrency spot pairs using customizable time intervals. Analyze trends and performance metrics for specific tokens on decentralized exchanges.

Instructions

Returns historical OHLCV data along with market cap for any spot pairs using time interval parameters.

Input Schema

NameRequiredDescriptionDefault
auxNo
contract_addressNo
convert_idNo
countNo
intervalNo
network_idNo
network_slugNo
reverse_orderNo
skip_invalidNo
time_endNo
time_periodNo
time_startNo

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "aux": { "type": "string" }, "contract_address": { "type": "string" }, "convert_id": { "type": "string" }, "count": { "type": "string" }, "interval": { "enum": [ "1m", "5m", "15m", "30m", "1h", "4h", "8h", "12h", "daily", "weekly", "monthly" ], "type": "string" }, "network_id": { "type": "string" }, "network_slug": { "type": "string" }, "reverse_order": { "type": "string" }, "skip_invalid": { "type": "string" }, "time_end": { "type": "string" }, "time_period": { "enum": [ "daily", "hourly", "1m", "5m", "15m", "30m", "4h", "8h", "12h", "weekly", "monthly" ], "type": "string" }, "time_start": { "type": "string" } }, "type": "object" }

Implementation Reference

  • The main handler function that executes the tool logic by making an API request to the CoinMarketCap '/v4/dex/pairs/ohlcv/historical' endpoint using helper functions handleEndpoint, makeApiRequest, and formatResponse.
    async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v4/dex/pairs/ohlcv/historical', params) return formatResponse(data) }) }
  • Zod input schema for the tool parameters including contract_address, network details, time periods, and other optional filters.
    { contract_address: z.string().optional(), network_id: z.string().optional(), network_slug: z.string().optional(), time_period: z.enum(['daily', 'hourly', '1m', '5m', '15m', '30m', '4h', '8h', '12h', 'weekly', 'monthly']).optional(), time_start: z.string().optional(), time_end: z.string().optional(), count: z.string().optional(), interval: z.enum(['1m', '5m', '15m', '30m', '1h', '4h', '8h', '12h', 'daily', 'weekly', 'monthly']).optional(), aux: z.string().optional(), convert_id: z.string().optional(), skip_invalid: z.string().optional(), reverse_order: z.string().optional() },
  • index.js:394-416 (registration)
    The server.tool registration call that defines and registers the dexPairsOhlcvHistorical tool with its description, input schema, and handler function.
    server.tool("dexPairsOhlcvHistorical", "Returns historical OHLCV data along with market cap for any spot pairs using time interval parameters.", { contract_address: z.string().optional(), network_id: z.string().optional(), network_slug: z.string().optional(), time_period: z.enum(['daily', 'hourly', '1m', '5m', '15m', '30m', '4h', '8h', '12h', 'weekly', 'monthly']).optional(), time_start: z.string().optional(), time_end: z.string().optional(), count: z.string().optional(), interval: z.enum(['1m', '5m', '15m', '30m', '1h', '4h', '8h', '12h', 'daily', 'weekly', 'monthly']).optional(), aux: z.string().optional(), convert_id: z.string().optional(), skip_invalid: z.string().optional(), reverse_order: z.string().optional() }, async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v4/dex/pairs/ohlcv/historical', params) return formatResponse(data) }) } )
  • Helper function used by the handler to wrap API calls with try-catch error handling.
    async function handleEndpoint(apiCall) { try { return await apiCall() } catch (error) { return formatErrorResponse(error.message, error.status || 403) } }
  • Core helper function that makes the actual HTTP GET request to the CoinMarketCap API with API key and query parameters.
    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() }

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/shinzo-labs/coinmarketcap-mcp'

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