diff --git a/widgets/extensions.yml b/widgets/extensions.yml index 7692e86c..8cc42d66 100644 --- a/widgets/extensions.yml +++ b/widgets/extensions.yml @@ -1,3 +1,8 @@ +- title: Fear & Greed Index + url: https://github.com/yroulin/fear-and-greed-index + description: A visually dynamic Glance widget that tracks real-time cryptocurrency market sentiment using the Crypto Fear & Greed Index API. + author: yroulin + - title: Glance F1 url: https://github.com/SkyAllinott/glance-F1 description: Adds user customization to widget by @abaza738 like local timezones, a track map, and more. diff --git a/widgets/fear-and-greed-index/README.md b/widgets/fear-and-greed-index/README.md new file mode 100644 index 00000000..aeca2b8b --- /dev/null +++ b/widgets/fear-and-greed-index/README.md @@ -0,0 +1,243 @@ +# Crypto Fear & Greed Index + +A [Glance](https://github.com/glanceapp/glance) widget that displays the current **Crypto Fear & Greed Index** โ€” a widely followed market sentiment indicator that measures whether crypto investors are driven by fear or greed at any given moment. The widget shows a live score from 0 to 100, a color-coded gradient bar with a moving indicator, a sentiment label, an emoji, and a trend arrow comparing today's value against yesterday's. + +No API key, no sign-up, no configuration beyond pasting the YAML. + +--- + +## Preview + +![Crypto Fear & Greed Index widget preview](preview.png) + +--- + +## What is the Fear & Greed Index? + +The Crypto Fear & Greed Index was originally inspired by CNN's Fear & Greed Index for traditional stock markets, adapted for the cryptocurrency ecosystem. It distills complex market signals into a single number between **0** (Extreme Fear) and **100** (Extreme Greed). + +The idea is simple: when the market is driven by **fear**, prices tend to be suppressed and may represent buying opportunities. When the market is driven by **greed**, prices may be overextended and due for a correction. + + +### Index scale + +| Range | Classification | Color | Emoji | What it means | +|---|---|---|---|---| +| 0 โ€“ 25 | **Extreme Fear** | ๐Ÿ”ด Red | ๐Ÿ˜ฑ | Investors are very worried. Historically a potential buying opportunity. | +| 26 โ€“ 45 | **Fear** | ๐ŸŸ  Orange | ๐Ÿ˜จ | Market sentiment is cautious and uncertain. | +| 46 โ€“ 54 | **Neutral** | ๐ŸŸก Yellow | ๐Ÿ˜ | Market is balanced between buyers and sellers. | +| 55 โ€“ 75 | **Greed** | ๐ŸŸข Green | ๐Ÿ˜ | Investors are increasingly confident, FOMO may be building. | +| 76 โ€“ 100 | **Extreme Greed** | ๐Ÿ’š Dark Green | ๐Ÿค‘ | Market may be overheated and due for a correction. | + +--- + +## Features + +- ๐Ÿ“Š **Live sentiment score** โ€” numeric value from 0 to 100 displayed prominently +- ๐ŸŽจ **Dynamic color coding** โ€” the score and label change color automatically based on the current classification +- ๐Ÿ“ **Gradient progress bar** โ€” a full spectrum bar (red โ†’ orange โ†’ yellow โ†’ green) with a white indicator dot that moves to the exact position of the current score +- ๐Ÿ˜ฑ โ†’ ๐Ÿค‘ **Emoji + sentiment label** โ€” human-readable classification shown alongside the score +- **โ–ฒ โ–ผ โ†’ Trend arrow** โ€” compares today's score against yesterday's so you can see at a glance whether sentiment is improving or deteriorating +- ๐Ÿ—“ **Yesterday's value** โ€” displayed as secondary text beneath the classification +- ๐Ÿ†“ **Completely free** โ€” uses the public [alternative.me](https://alternative.me/crypto/fear-and-greed-index/) API with no authentication required + +--- + +## API + +This widget relies on the **alternative.me Crypto Fear & Greed Index API**, a free and widely used public API that has been running since 2018. + +| Property | Value | +|---|---| +| **Endpoint** | `https://api.alternative.me/fng/?limit=2` | +| **Authentication** | None โ€” no API key required | +| **Rate limit** | None enforced for normal usage | +| **Update frequency** | Once per day (scores are published daily) | +| **Response format** | JSON | + +The `?limit=2` query parameter tells the API to return the **two most recent daily entries**: today's value (`data.0`) and yesterday's (`data.1`). This is what enables the trend arrow comparison. + +### Example API response + +```json +{ + "name": "Fear and Greed Index", + "data": [ + { + "value": "13", + "value_classification": "Extreme Fear", + "timestamp": "1708905600", + "time_until_update": "74093" + }, + { + "value": "18", + "value_classification": "Extreme Fear", + "timestamp": "1708819200", + "time_until_update": null + } + ], + "metadata": { + "error": null + } +} +``` + +### Fields used by this widget + +| JSON path | Type | Used for | +|---|---|---| +| `data.0.value` | `Int` | Current day's score (0โ€“100) | +| `data.1.value` | `Int` | Yesterday's score for trend comparison | +| `data.0.value_classification` | `String` | Sentiment label (e.g. `"Extreme Fear"`) | + +--- + +## Installation + +### 1. Open your Glance config file + +Typically located at `glance.yml` or wherever you have your Glance configuration set up (local install or Docker volume mount). + +### 2. Add the widget + +Paste the following block into the `widgets` list of any column on any page: + +```yaml +- type: custom-api + title: Crypto Fear & Greed Index + cache: 1h + url: https://api.alternative.me/fng/?limit=2 + template: | + {{ $value := .JSON.Int "data.0.value" }} + {{ $prev := .JSON.Int "data.1.value" }} + {{ $label := .JSON.String "data.0.value_classification" }} + + {{ $color := "#e74c3c" }} + {{ if ge $value 26 }}{{ $color = "#e67e22" }}{{ end }} + {{ if ge $value 46 }}{{ $color = "#f1c40f" }}{{ end }} + {{ if ge $value 55 }}{{ $color = "#2ecc71" }}{{ end }} + {{ if ge $value 76 }}{{ $color = "#27ae60" }}{{ end }} + + {{ $emoji := "๐Ÿ˜ฑ" }} + {{ if ge $value 26 }}{{ $emoji = "๐Ÿ˜จ" }}{{ end }} + {{ if ge $value 46 }}{{ $emoji = "๐Ÿ˜" }}{{ end }} + {{ if ge $value 76 }}{{ $emoji = "๐Ÿค‘" }}{{ end }} + + {{ $arrow := "โ†’" }} + {{ if gt $value $prev }}{{ $arrow = "โ–ฒ" }}{{ end }} + {{ if lt $value $prev }}{{ $arrow = "โ–ผ" }}{{ end }} + +
+ +
+ + {{ $value }} + +
+ + {{ $emoji }} {{ $label }} + + + Yesterday: {{ $prev }} {{ $arrow }} + +
+
+ +
+
+
+ +
+ ๐Ÿ˜ฑ Extreme Fear + Fear + Greed + ๐Ÿค‘ Extreme Greed +
+ +
+ Source: alternative.me ยท Updates daily +
+ +
+``` + +### 3. Restart or reload Glance + +```bash +# If running locally +./glance + +# If running with Docker +docker compose restart glance +``` + +The widget will appear immediately on your dashboard. + +--- + +## Configuration + +This widget has no required configuration โ€” it works out of the box. The only optional field you may want to adjust is `cache`. + +### Cache + +```yaml +cache: 1h +``` + +Since the index only updates **once per day**, a cache of `1h` is more than sufficient. Setting it lower (e.g. `5m`) will not give you fresher data and only creates unnecessary HTTP requests to the free API. You could even set it as high as `12h` if you prefer. + +--- + +## How the template works + +The widget uses Glance's `custom-api` widget type with a Go template. Here is a breakdown of what each section does: + +**Variable extraction** +``` +{{ $value := .JSON.Int "data.0.value" }} +{{ $prev := .JSON.Int "data.1.value" }} +{{ $label := .JSON.String "data.0.value_classification" }} +``` +Reads today's score, yesterday's score, and the text classification from the API JSON response. Note that the API returns `value` as a string in the JSON, but Glance's `.JSON.Int` helper automatically coerces it to an integer. + +**Dynamic color** +``` +{{ $color := "#e74c3c" }} +{{ if ge $value 26 }}{{ $color = "#e67e22" }}{{ end }} +{{ if ge $value 46 }}{{ $color = "#f1c40f" }}{{ end }} +{{ if ge $value 55 }}{{ $color = "#2ecc71" }}{{ end }} +{{ if ge $value 76 }}{{ $color = "#27ae60" }}{{ end }} +``` +Uses `ge` (greater than or equal) comparisons to progressively override the color variable as the score crosses each threshold. The comparisons are chained so only the highest matching band wins โ€” a value of `80` will pass all four checks, ending on dark green `#27ae60`. + +**Trend arrow** +``` +{{ $arrow := "โ†’" }} +{{ if gt $value $prev }}{{ $arrow = "โ–ฒ" }}{{ end }} +{{ if lt $value $prev }}{{ $arrow = "โ–ผ" }}{{ end }} +``` +Compares today vs yesterday. Arrow points up if sentiment improved, down if it worsened, and stays sideways if the value is identical. + +**Gradient bar indicator** +```css +left: calc({{ $value }}% - 6px); +``` +The indicator dot is positioned using the raw score as a CSS percentage. A value of `72` places the dot at `72%` along the bar, which naturally lands in the green "Greed" zone. The `-6px` offset re-centers the 13px dot on that exact position. + +--- + +## Credits +- Index data provided by [alternative.me](https://alternative.me/crypto/fear-and-greed-index/) +- Built for [Glance](https://github.com/glanceapp/glance) using the `custom-api` widget type with Go templates diff --git a/widgets/fear-and-greed-index/meta.yml b/widgets/fear-and-greed-index/meta.yml new file mode 100644 index 00000000..fe19f5f5 --- /dev/null +++ b/widgets/fear-and-greed-index/meta.yml @@ -0,0 +1,67 @@ +- type: custom-api + title: Crypto Fear & Greed Index + cache: 12h + url: https://api.alternative.me/fng/?limit=2 + template: | + {{ $value := .JSON.Int "data.0.value" }} + {{ $prev := .JSON.Int "data.1.value" }} + {{ $label := .JSON.String "data.0.value_classification" }} + + {{ $color := "#e74c3c" }} + {{ if ge $value 26 }}{{ $color = "#e67e22" }}{{ end }} + {{ if ge $value 46 }}{{ $color = "#f1c40f" }}{{ end }} + {{ if ge $value 55 }}{{ $color = "#2ecc71" }}{{ end }} + {{ if ge $value 76 }}{{ $color = "#27ae60" }}{{ end }} + + {{ $emoji := "๐Ÿ˜ฑ" }} + {{ if ge $value 26 }}{{ $emoji = "๐Ÿ˜จ" }}{{ end }} + {{ if ge $value 46 }}{{ $emoji = "๐Ÿ˜" }}{{ end }} + {{ if ge $value 76 }}{{ $emoji = "๐Ÿค‘" }}{{ end }} + + {{ $arrow := "โ†’" }} + {{ if gt $value $prev }}{{ $arrow = "โ–ฒ" }}{{ end }} + {{ if lt $value $prev }}{{ $arrow = "โ–ผ" }}{{ end }} + +
+ +
+ + {{ $value }} + +
+ + {{ $emoji }} {{ $label }} + + + Yesterday: {{ $prev }} {{ $arrow }} + +
+
+ +
+
+
+ +
+ ๐Ÿ˜ฑ Extreme Fear + Fear + Greed + ๐Ÿค‘ Extreme Greed +
+ +
+ Source: alternative.me ยท Updates daily +
+ +
\ No newline at end of file diff --git a/widgets/fear-and-greed-index/preview.png b/widgets/fear-and-greed-index/preview.png new file mode 100644 index 00000000..989ba604 Binary files /dev/null and b/widgets/fear-and-greed-index/preview.png differ