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
| Name | Required | Description | Default |
|---|---|---|---|
| exchange | Yes | Exchange ID (e.g., binance, bybit) | |
| marketType | No | Market type (default: swap) | swap |
| symbols | No | List of trading pair symbols (optional) |
Implementation Reference
- src/tools/public.ts:345-378 (handler)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 }; } });
- src/tools/public.ts:342-344 (schema)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)")
- src/tools/public.ts:341-378 (registration)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 }; } });