dexPairsQuotesLatest
Retrieve real-time market quotes for one or more decentralized exchange (DEX) spot pairs. Supports contract addresses, network IDs, and currency conversions.
Instructions
Returns the latest market quote for 1 or more spot pairs.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| aux | No | ||
| contract_address | No | ||
| convert_id | No | ||
| network_id | No | ||
| network_slug | No | ||
| reverse_order | No | ||
| skip_invalid | No |
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"
},
"network_id": {
"type": "string"
},
"network_slug": {
"type": "string"
},
"reverse_order": {
"type": "string"
},
"skip_invalid": {
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- index.js:365-370 (handler)The main handler function for the dexPairsQuotesLatest tool. It calls handleEndpoint which invokes makeApiRequest to the specific CoinMarketCap endpoint '/v4/dex/pairs/quotes/latest' with the provided params and formats the response.async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v4/dex/pairs/quotes/latest', params) return formatResponse(data) }) }
- index.js:356-364 (schema)Input schema defined using Zod (z) for validating optional parameters passed to the tool.{ contract_address: z.string().optional(), network_id: z.string().optional(), network_slug: z.string().optional(), aux: z.string().optional(), convert_id: z.string().optional(), skip_invalid: z.string().optional(), reverse_order: z.string().optional() },
- index.js:353-371 (registration)The registration call to server.tool() that defines the tool name, description, input schema, and handler function.// /v4/dex/pairs/quotes/latest server.tool("dexPairsQuotesLatest", "Returns the latest market quote for 1 or more spot pairs.", { contract_address: z.string().optional(), network_id: z.string().optional(), network_slug: z.string().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/quotes/latest', params) return formatResponse(data) }) } )
- index.js:50-73 (helper)Shared helper function that makes the HTTP request to the CoinMarketCap API, builds query params from input, and returns parsed JSON.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() }
- index.js:82-88 (helper)Shared wrapper function used in the handler to execute the API call and catch errors, returning formatted error response if failed.async function handleEndpoint(apiCall) { try { return await apiCall() } catch (error) { return formatErrorResponse(error.message, error.status || 403) } }