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 }; } });

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