dexPairsTradeLatest
Retrieve the latest 100 trades for a specific decentralized exchange (DEX) spot pair, providing insights into market activity, liquidity, and transaction trends on supported networks.
Instructions
Returns up to the latest 100 trades for 1 spot pair.
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:430-435 (handler)The handler function for dexPairsTradeLatest tool that invokes handleEndpoint to make an API request to CoinMarketCap's '/v4/dex/pairs/trade/latest' endpoint with the provided parameters and formats the response.async (params) => { return handleEndpoint(async () => { const data = await makeApiRequest(apiKey, '/v4/dex/pairs/trade/latest', params) return formatResponse(data) }) }
- index.js:421-429 (schema)Zod input schema defining optional parameters for specifying the spot pair: contract_address, network_id or slug, aux, convert_id, etc.{ 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:419-436 (registration)Registers the dexPairsTradeLatest tool on the MCP server with description, input schema, and inline handler function.server.tool("dexPairsTradeLatest", "Returns up to the latest 100 trades for 1 spot pair.", { 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/trade/latest', params) return formatResponse(data) }) } )
- index.js:82-88 (helper)Helper function used by the handler to wrap API calls with try-catch error handling and response formatting.async function handleEndpoint(apiCall) { try { return await apiCall() } catch (error) { return formatErrorResponse(error.message, error.status || 403) } }
- index.js:50-73 (helper)Core helper function that constructs the API request URL, performs the fetch to CoinMarketCap Pro API, and returns the JSON response.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() }