C#: Get XRP Distribution



Get information on the total amount of XRP in existence and in circulation, by weekly intervals.

Read more: https://developers.ripple.com/data-api.html#get-xrp-distribution

Requirement

1
2
3
4
using System.Windows.Forms;
using System.Net;
using Newtonsoft.Json;
using System.IO;

Generate C# class from JSON:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public partial class Xrpdistribution
        {
            [JsonProperty("result")]
            public string Result { get; set; }

            [JsonProperty("count")]
            public long Count { get; set; }

            [JsonProperty("marker")]
            public string Marker { get; set; }

            [JsonProperty("rows")]
            public Row[] Rows { get; set; }
        }

        public partial class Row
        {
            [JsonProperty("date")]
            public DateTime Date { get; set; }

            [JsonProperty("total")]
            public string Total { get; set; }

            [JsonProperty("distributed")]
            public string Distributed { get; set; }

            [JsonProperty("undistributed")]
            public string Undistributed { get; set; }

            [JsonProperty("escrowed")]
            public string Escrowed { get; set; }
        }

Create request and get JSON data:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
string url = "https://data.ripple.com/v2/network/xrp_distribution?limit=2&descending=true";
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            string json = "";
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                json = reader.ReadToEnd();
            }

            Xrpdistribution dobj = JsonConvert.DeserializeObject<Xrpdistribution>(json);
            fromdate.Text = dobj.Rows[1].Date.ToShortDateString();
            todate.Text = dobj.Rows[0].Date.ToShortDateString();
            heldbyripple.Text = String.Format("{0:#,#.##}", Double.Parse(dobj.Rows[0].Undistributed));
            heldbyothers.Text = String.Format("{0:#,#.##}", Double.Parse(dobj.Rows[0].Distributed));
            inescrow.Text = String.Format("{0:#,#.##}", Double.Parse(dobj.Rows[0].Escrowed));
            totalxrp.Text = String.Format("{0:#,#.##}", Double.Parse(dobj.Rows[0].Total));
            long changex = Convert.ToInt64(dobj.Rows[0].Distributed) - Convert.ToInt64(dobj.Rows[1].Distributed);
            change.Text = String.Format("{0:#,#.##}", Double.Parse(changex.ToString()));

Gets or sets the security protocol used by the ServicePoint objects managed by the ServicePointManager object.
Read more about: ServicePointManager.SecurityProtocol Property