Skip to main content
Glama

get_derivatives_context

Access derivatives intelligence including perpetual funding rates, options data, and leverage positioning to understand market positioning and liquidation risk.

Instructions

Derivatives intelligence: perpetual funding rates (BTC/ETH/SOL), options data (put/call ratio, open interest, implied volatility, max pain price), and leverage positioning. Critical for understanding market positioning and liquidation risk. Data from Deribit.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler for 'get_derivatives_context' which fetches derivative data, calculates metrics, and generates guidance.
    export async function getDerivativesContext(cache: CacheService): Promise<DerivativesContextOutput | ErrorOutput> {
      const cached = cache.get<DerivativesContextOutput>(CACHE_KEY);
      if (cached) return cached.data;
    
      try {
        const data = await getDerivativesData();
    
        const fundingRates = data.funding_rates.map(f => {
          // Determine trajectory from annualized rate magnitude
          const rate = f.annualized_rate;
          const trajectory: 'rising' | 'stable' | 'falling' =
            rate > 30 ? 'rising' : rate < -10 ? 'falling' : 'stable';
          // Project next funding direction
          const projected = rate > 20 ? 'Likely to remain elevated or increase — longs paying heavy premium'
            : rate < -10 ? 'Likely to go more negative — shorts paying premium, potential short squeeze setup'
            : 'Likely stable — no strong directional pressure from funding';
          return {
            asset: f.asset,
            rate_8h: f.current_rate_8h,
            annualized_pct: f.annualized_rate,
            annualized_rate: f.annualized_rate,
            sentiment: f.sentiment,
            trajectory,
            projected_next: projected,
          };
        });
    
        const btcOpts = data.options_btc;
        const ethOpts = data.options_eth;
    
        // Determine leverage signal from funding + put/call
        const leverageSignal = determineLeverageSignal(data);
        const summary = generateSummary(data);
        const guidance = generateGuidance(data, leverageSignal);
    
        const result: DerivativesContextOutput = {
          funding_rates: fundingRates,
          options: {
            btc_put_call_ratio: btcOpts.put_call_ratio,
            btc_open_interest_usd: btcOpts.total_open_interest_usd,
            btc_volume_24h_usd: btcOpts.total_volume_24h_usd,
            btc_implied_volatility: btcOpts.avg_implied_volatility,
            btc_max_pain: btcOpts.max_pain_price,
            btc_options_sentiment: btcOpts.sentiment,
            eth_put_call_ratio: ethOpts?.put_call_ratio ?? null,
            eth_open_interest_usd: ethOpts?.total_open_interest_usd ?? null,
            eth_options_sentiment: ethOpts?.sentiment ?? null,
            nearest_expiry: btcOpts.nearest_expiry,
          },
          leverage_signal: leverageSignal,
          derivatives_summary: summary,
          agent_guidance: guidance,
        };
    
        cache.set(CACHE_KEY, result, getCacheTtl(BASE_TTL));
        return result;
      } catch (err) {
        return {
          error: true,
          error_source: 'get_derivatives_context',
          agent_guidance: 'Derivatives data unavailable (Deribit API). Cannot assess funding rates, options flow, or leverage positioning. Proceed with caution — you are missing leverage and positioning signals.',
          last_known_data: cache.get<DerivativesContextOutput>(CACHE_KEY)?.data ?? null,
          data_warnings: ['Derivatives data source temporarily unavailable.'],
        };
      }
    }
  • Data schema for the derivatives context output.
    export interface DerivativesContextOutput {
      funding_rates: Array<{
        asset: string;
        rate_8h: number;
        annualized_pct: number;
        annualized_rate: number;
        sentiment: string;
        trajectory: 'rising' | 'stable' | 'falling';
        projected_next: string;
      }>;
      options: {
        btc_put_call_ratio: number;
        btc_open_interest_usd: number;
        btc_volume_24h_usd: number;
        btc_implied_volatility: number;
        btc_max_pain: number;
        btc_options_sentiment: string;
        eth_put_call_ratio: number | null;
        eth_open_interest_usd: number | null;
        eth_options_sentiment: string | null;
        nearest_expiry: string;
      };
      leverage_signal: 'overleveraged_long' | 'leveraged_long' | 'neutral' | 'leveraged_short' | 'overleveraged_short';
      derivatives_summary: string;
      agent_guidance: string;
    }
  • Helper functions to process the derivatives data, including leverage signal determination, summary generation, and agent guidance.
    function determineLeverageSignal(data: DerivativesData): DerivativesContextOutput['leverage_signal'] {
      const btcFunding = data.funding_rates.find(f => f.asset === 'BTC');
      const pcr = data.options_btc.put_call_ratio;
    
      let score = 0; // positive = overleveraged long, negative = overleveraged short
    
      if (btcFunding) {
        if (btcFunding.annualized_rate > 50) score += 3;
        else if (btcFunding.annualized_rate > 15) score += 1;
        else if (btcFunding.annualized_rate < -50) score -= 3;
        else if (btcFunding.annualized_rate < -15) score -= 1;
      }
    
      // Low put/call = bullish positioning (potential overleveraged long)
      if (pcr < 0.5) score += 1;
      else if (pcr > 1.2) score -= 1;
    
      if (score >= 3) return 'overleveraged_long';
      if (score >= 1) return 'leveraged_long';
      if (score <= -3) return 'overleveraged_short';
      if (score <= -1) return 'leveraged_short';
      return 'neutral';
    }
    
    function generateSummary(data: DerivativesData): string {
      const btcFunding = data.funding_rates.find(f => f.asset === 'BTC');
      const pcr = data.options_btc.put_call_ratio;
      const oi = data.options_btc.total_open_interest_usd;
      const iv = data.options_btc.avg_implied_volatility;
      const maxPain = data.options_btc.max_pain_price;
    
      const parts: string[] = [];
    
      if (btcFunding) {
        parts.push(`BTC perpetual funding: ${btcFunding.annualized_rate > 0 ? '+' : ''}${btcFunding.annualized_rate.toFixed(1)}% annualized (${btcFunding.sentiment.replace(/_/g, ' ')})`);
      }
    
      parts.push(`Options: P/C ratio ${pcr.toFixed(2)}, OI $${(oi / 1e9).toFixed(1)}B, IV ${iv.toFixed(0)}%, max pain $${maxPain.toLocaleString()}`);
    
      if (data.options_btc.nearest_expiry) {
        parts.push(`Nearest expiry: ${data.options_btc.nearest_expiry}`);
      }
    
      return parts.join('. ') + '.';
    }
    
    function generateGuidance(data: DerivativesData, leverage: string): string {
      const pcr = data.options_btc.put_call_ratio;
      const btcFunding = data.funding_rates.find(f => f.asset === 'BTC');
      const maxPain = data.options_btc.max_pain_price;
    
      const parts: string[] = [];
    
      if (leverage === 'overleveraged_long') {
        parts.push('Market is overleveraged long. High funding rates and low put/call ratio suggest a crowded long trade. Elevated risk of a long squeeze. Reduce long exposure or tighten stops.');
      } else if (leverage === 'overleveraged_short') {
        parts.push('Market is overleveraged short. Negative funding and high put/call ratio suggest excessive bearishness. Short squeeze potential. Contrarian long setups may offer favorable risk/reward.');
      } else if (leverage === 'leveraged_long') {
        parts.push('Moderate long bias in derivatives. Funding positive but not extreme. Monitor for acceleration.');
      } else if (leverage === 'leveraged_short') {
        parts.push('Moderate short bias in derivatives. Market hedging downside. Watch for capitulation or reversal signals.');
      } else {
        parts.push('Derivatives positioning is neutral. No clear leverage imbalance. Trade based on other signals.');
      }
    
      if (maxPain > 0) {
        parts.push(`Max pain at $${maxPain.toLocaleString()} — price tends to gravitate toward max pain near options expiry.`);
      }
    
      if (pcr > 1.0) {
        parts.push('Elevated put/call ratio indicates hedging or bearish positioning. Historically this can be a contrarian bullish signal when extreme.');
      }
    
      return parts.join(' ');
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It successfully identifies the data source (Deribit) and enumerates specific data categories returned, but omits critical behavioral details such as data freshness (real-time vs cached), rate limits, or whether historical data is available.

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

Conciseness4/5

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

The description efficiently packs specific data types, use case justification, and source attribution into two sentences. While 'Derivatives intelligence' is slightly abstract, the colon-delimited list immediately clarifies the concrete data points, minimizing cognitive load.

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

Completeness4/5

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

Given the absence of parameters and output schema, the description adequately compensates by enumerating the specific metrics returned (funding rates, Greeks, open interest). For a simple data-retrieval tool, this provides sufficient context for invocation, though mentioning return structure format would further improve completeness.

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

Parameters4/5

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

Per the evaluation rules, tools with zero parameters receive a baseline score of 4. The input schema contains no properties requiring semantic elaboration, so no additional descriptive compensation is needed beyond the baseline.

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

Purpose5/5

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

The description precisely identifies the resource (derivatives data) and specific sub-types (perpetual funding rates for BTC/ETH/SOL, options data including put/call ratios and max pain price, and leverage positioning). It clearly distinguishes from siblings like get_asset_context or get_macro_context by focusing exclusively on derivatives market data from Deribit.

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

Usage Guidelines3/5

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

The description provides implicit usage context by stating it is 'Critical for understanding market positioning and liquidation risk,' which hints at when to invoke the tool. However, it lacks explicit guidance on when to choose this over similar context-gathering siblings (e.g., get_asset_context vs get_derivatives_context) and does not mention prerequisites or filtering.

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

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/0xHashy/fathom-fyi'

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