Skip to main content
Glama

get-funding-rates

Retrieve current funding rates for perpetual contracts on cryptocurrency exchanges. Specify exchange ID, trading pairs, and market type to get precise data for informed trading decisions.

Instructions

Get current funding rates for perpetual contracts

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exchangeYesExchange ID (e.g., binance, bybit)
marketTypeNoMarket type (default: swap)swap
symbolsNoList of trading pair symbols (optional)

Implementation Reference

  • The handler function that implements the core logic for the 'get-funding-rates' tool. It fetches funding rates from the exchange using ccxt's fetchFundingRates method (for specified symbols or all), applies rate limiting via rateLimiter, caching via getCachedData (5 min TTL), logging, and error handling with structured MCP response.
    }, async ({ exchange, symbols, marketType }) => {
      try {
        return await rateLimiter.execute(exchange, async () => {
          // Get futures exchange
          const ex = getExchangeWithMarketType(exchange, marketType);
          const cacheKey = `funding_rates:${exchange}:${marketType}:${symbols ? symbols.join(',') : 'all'}`;
          
          const rates = await getCachedData(cacheKey, async () => {
            log(LogLevel.INFO, `Fetching funding rates for ${symbols ? symbols.length : 'all'} symbols on ${exchange} (${marketType})`);
            if (symbols) {
              return await ex.fetchFundingRates(symbols);
            } else {
              return await ex.fetchFundingRates();
            }
          }, 300000); // Cache for 5 minutes
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify(rates, null, 2)
            }]
          };
        });
      } catch (error) {
        log(LogLevel.ERROR, `Error fetching funding rates: ${error instanceof Error ? error.message : String(error)}`);
        return {
          content: [{
            type: "text",
            text: `Error: ${error instanceof Error ? error.message : String(error)}`
          }],
          isError: true
        };
      }
    });
  • Zod input schema for the 'get-funding-rates' tool, validating exchange, optional symbols array, and marketType (future/swap, defaults to swap).
    exchange: z.string().describe("Exchange ID (e.g., binance, bybit)"),
    symbols: z.array(z.string()).optional().describe("List of trading pair symbols (optional)"),
    marketType: z.enum(["future", "swap"]).default("swap").describe("Market type (default: swap)")
  • Registration of the 'get-funding-rates' tool via server.tool() within registerPublicTools function, including name, description, input schema, and inline handler.
    server.tool("get-funding-rates", "Get current funding rates for perpetual contracts", {
      exchange: z.string().describe("Exchange ID (e.g., binance, bybit)"),
      symbols: z.array(z.string()).optional().describe("List of trading pair symbols (optional)"),
      marketType: z.enum(["future", "swap"]).default("swap").describe("Market type (default: swap)")
    }, async ({ exchange, symbols, marketType }) => {
      try {
        return await rateLimiter.execute(exchange, async () => {
          // Get futures exchange
          const ex = getExchangeWithMarketType(exchange, marketType);
          const cacheKey = `funding_rates:${exchange}:${marketType}:${symbols ? symbols.join(',') : 'all'}`;
          
          const rates = await getCachedData(cacheKey, async () => {
            log(LogLevel.INFO, `Fetching funding rates for ${symbols ? symbols.length : 'all'} symbols on ${exchange} (${marketType})`);
            if (symbols) {
              return await ex.fetchFundingRates(symbols);
            } else {
              return await ex.fetchFundingRates();
            }
          }, 300000); // Cache for 5 minutes
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify(rates, null, 2)
            }]
          };
        });
      } catch (error) {
        log(LogLevel.ERROR, `Error fetching funding rates: ${error instanceof Error ? error.message : String(error)}`);
        return {
          content: [{
            type: "text",
            text: `Error: ${error instanceof Error ? error.message : String(error)}`
          }],
          isError: true
        };
      }
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral context. It doesn't disclose whether this is a read-only operation, latency expectations, rate limits, authentication requirements, or what format the funding rates are returned in. The description is functional but lacks operational transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that communicates the core purpose without unnecessary words. It's appropriately sized for a straightforward data retrieval tool and front-loads the essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 3 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what funding rates are, how they're calculated, typical use cases, or what the return data looks like. The agent would need to guess about the output format and operational characteristics.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so all parameters are documented in the schema itself. The description doesn't add any parameter-specific context beyond what's in the schema, such as explaining why 'exchange' is required or how 'symbols' filtering works. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get') and target resource ('current funding rates for perpetual contracts'), making the tool's purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'get-ticker' or 'get-ohlcv' that also retrieve market data but for different metrics.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites, context for funding rates in trading, or when other tools like 'get-ticker' might be more appropriate for different market data needs.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/doggybee/mcp-server-ccxt'

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