Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
auxNo
contract_addressNo
convert_idNo
network_idNo
network_slugNo
reverse_orderNo
skip_invalidNo

Implementation Reference

  • 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)
      })
    }
  • 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)
        })
      }
    )
  • 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)
      }
    }
  • 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()
    }

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