Skip to main content
Glama

get_sentiment_state

Analyze crypto market sentiment by retrieving the Fear & Greed Index, 7-day trend, contrarian signals, and extreme opportunity indicators.

Instructions

Get the current crypto sentiment state including Fear & Greed Index, 7-day trend, contrarian signals, and whether extreme fear/greed opportunities are active.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function for get_sentiment_state, which fetches fear/greed data, processes trends, and generates narrative/guidance.
    export async function getSentimentState(cache: CacheService): Promise<SentimentStateOutput | ErrorOutput> {
      const cached = cache.get<SentimentStateOutput>(CACHE_KEY);
      if (cached) return cached.data;
    
      try {
        const fgData = await getFearGreed(7);
        const entries = fgData.data;
    
        const current = parseInt(entries[0].value, 10);
        const sevenDayAgo = entries.length >= 7 ? parseInt(entries[6].value, 10) : parseInt(entries[entries.length - 1].value, 10);
    
        const diff = current - sevenDayAgo;
        const trend: 'improving' | 'stable' | 'deteriorating' =
          diff > 5 ? 'improving' : diff < -5 ? 'deteriorating' : 'stable';
    
        const extremeFearOpportunity = current < 20;
        const extremeGreedWarning = current > 80;
    
        const contrarianSignal = current < 20
          ? 'Historically strong accumulation signal. Extreme fear often precedes recovery. Prior instances (March 2020, June 2022, November 2022) preceded 50-300% rallies within 3-12 months.'
          : current > 80
            ? 'Historically strong distribution signal. Extreme greed often precedes correction. Prior instances (November 2021, March 2024) preceded 20-50% drawdowns within 1-3 months.'
            : `Sentiment at ${current} is in the neutral-to-${current > 50 ? 'greedy' : 'fearful'} range. No extreme contrarian signal active. Monitor for moves toward extremes.`;
    
        const narrative = generateSentimentNarrative(current, sevenDayAgo, trend);
        const guidance = generateSentimentGuidance(current, trend, extremeFearOpportunity, extremeGreedWarning);
    
        const result: SentimentStateOutput = {
          fear_greed_current: current,
          fear_greed_7d_ago: sevenDayAgo,
          fear_greed_trend: trend,
          fear_greed_label: getFearGreedLabel(current),
          sentiment_narrative: narrative,
          extreme_fear_opportunity: extremeFearOpportunity,
          extreme_greed_warning: extremeGreedWarning,
          contrarian_signal: contrarianSignal,
          agent_guidance: guidance,
        };
    
        cache.set(CACHE_KEY, result, getCacheTtl(BASE_TTL));
        return result;
      } catch (err) {
        return {
          error: true,
          error_source: 'get_sentiment_state',
          agent_guidance: 'Sentiment data unavailable. Without sentiment context, treat current conditions as uncertain. Reduce position sizes until sentiment data is restored.',
          last_known_data: cache.get<SentimentStateOutput>(CACHE_KEY)?.data ?? null,
          data_warnings: ['Sentiment data source temporarily unavailable. Retry shortly.'],
        };
      }
    }

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