get_market_sentiment
Analyze Bitcoin market sentiment by retrieving the Fear & Greed Index value, classification, and 7-day history to inform trading decisions alongside price data.
Instructions
Get Bitcoin Fear & Greed Index: current value (0-100), classification (Extreme Fear/Fear/Neutral/Greed/Extreme Greed), and 7-day history. Use this to gauge market sentiment alongside price data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/bitcoin_mcp/server.py:1041-1066 (handler)The `get_market_sentiment` tool fetches the current Bitcoin Fear & Greed Index and its 7-day history from the `api.alternative.me` service. It uses `urllib` to request data and returns a JSON-formatted summary containing the current sentiment, classification, and historical data points.
def get_market_sentiment() -> str: """Get Bitcoin Fear & Greed Index: current value (0-100), classification (Extreme Fear/Fear/Neutral/Greed/Extreme Greed), and 7-day history. Use this to gauge market sentiment alongside price data.""" try: url = "https://api.alternative.me/fng/?limit=7" req = urllib.request.Request(url, headers={"User-Agent": "bitcoin-mcp"}) with urllib.request.urlopen(req, timeout=10) as resp: data = json.loads(resp.read(1_000_000)) entries = data.get("data", []) if not entries: return json.dumps({"error": "No data returned from Fear & Greed API"}) current = entries[0] history = [] for e in entries: history.append({ "value": int(e["value"]), "classification": e["value_classification"], "timestamp": e["timestamp"], }) return json.dumps({ "current_value": int(current["value"]), "classification": current["value_classification"], "history_7d": history, "source": "alternative.me", }) except Exception as e: return json.dumps({"error": f"Fear & Greed fetch failed: {e}", "hint": "api.alternative.me may be down. Try again shortly."})