[C#] 使用 Alternative.me 快速取得加密貨幣恐懼貪婪指數

  • 41
  • 0

如果你正在開發加密貨幣相關的應用,可能常常會想了解市場的恐懼貪婪指數..

在眾多資料來源中,Alternative.me 的 Crypto Fear & Greed Index 算是最容易取得,也最容易串接的一個

重點是免費...

1. 如果你只是想放在系統或是 Blog 上面,你只要插入這網址就可以了
https://alternative.me/crypto/fear-and-greed-index.png

但是避免快取,你可以透過後面的 seed 幫助可以取到最新的圖片

<script>
    const img = document.getElementById("imgCryptoFG");
  img.src = "https://alternative.me/crypto/fear-and-greed-index.png?seed=" + Date.now();

</script>

2. 接下來就是如何取得今天的加密貨幣恐懼貪婪指數

資料模型

		
		
        public class FearGreedResponse
        {
            public string Name { get; set; }

            public List Data { get; set; }
        
        }

        public class FearGreedData
        {
            public string Value { get; set; }
            public string Value_Classification { get; set; }
            public string Timestamp { get; set; }
            public string Time_Until_Update { get; set; }
        }
        

取得今天的資料:

        
        var url = "https://api.alternative.me/fng/?limit=1&format=json";

        using var client = new HttpClient();
        var json = await client.GetStringAsync(url);

        var options = new JsonSerializerOptions
        {
        	PropertyNameCaseInsensitive = true
        };

        var result = JsonSerializer.Deserialize(json, options);

        Console.WriteLine(result.Data[0].Value + "-" + result.Data[0].Value_Classification);
        
            
        //Result:
        //11-Extreme Fear
    

3. 取得七天的資料

   var url = "https://api.alternative.me/fng/?limit="+"7"+"&format=json";

    using var client = new HttpClient();
    var json = await client.GetStringAsync(url);

    var options = new JsonSerializerOptions
    {
    PropertyNameCaseInsensitive = true
    };

    var result = JsonSerializer.Deserialize(json, options);

        foreach (var d in result.Data) {
        Console.WriteLine(DateTimeOffset.FromUnixTimeSeconds(long.Parse(d.Timestamp)).ToLocalTime().DateTime + " : "
        +d.Value+" ,"
        +d.Value_Classification);

        }

        //2025/11/18 上午 08:00:00 : 11 ,Extreme Fear
        //2025/11/17 上午 08:00:00 : 14 ,Extreme Fear
        //2025/11/16 上午 08:00:00 : 10 ,Extreme Fear
        //2025/11/15 上午 08:00:00 : 10 ,Extreme Fear
        //2025/11/14 上午 08:00:00 : 16 ,Extreme Fear
        //2025/11/13 上午 08:00:00 : 15 ,Extreme Fear
        //2025/11/12 上午 08:00:00 : 24 ,Extreme Fear
        
        

結論 - 

如果你需要快速加入市場情緒這種資訊

Alternative.me 的 Fear & Greed Index 真的是非常理想的資料來源

它沒有 API Key、不需要驗證、資料格式乾淨

還另外提供每日更新的圖形版 index,只要記得加上一個 query string,就能避免快取問題,永遠看到最新的內容。

不論你是在做 Dashboard、Bot、網站,或只是想玩玩數據,這個 API 幾乎是零成本就能使用的工具

--

本文原文首發於我的個人部落格:使用 Alternative.me 快速取得加密貨幣恐懼貪婪指數

 

---

Yesterday I wrote down the code. I bet I could be your hero. I am a mighty little programmer.