Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
auxNo
contract_addressNo
convert_idNo
network_idNo
network_slugNo
reverse_orderNo
skip_invalidNo

Implementation Reference

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

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