Example #1
0
 public CryptoIndexClientManager AddClient(string name, ICryptoIndexClient client)
 {
     _clients.Add(name, client);
     return(this);
 }
        private async Task LoadCryptoIndex(string name, ICryptoIndexClient client)
        {
            var dict             = new Dictionary <string, AssetInfo>();
            var indexValue       = 0m;
            var indexChangeToday = 0m;

            #region load data

            var data = await client.Public.GetLastAsync();

            var change = await client.Public.GetChangeAsync();

            indexValue       = data.Value;
            indexChangeToday = (change[1].Item2 - change[0].Item2) / change[0].Item2;

            foreach (var price in data.MiddlePrices)
            {
                if (!dict.TryGetValue(price.Key, out var item))
                {
                    item = new AssetInfo(price.Key);
                }

                item.Price       = price.Value;
                dict[item.Asset] = item;
            }

            foreach (var cup in data.MarketCaps)
            {
                if (!dict.TryGetValue(cup.Asset, out var item))
                {
                    item = new AssetInfo(cup.Asset);
                }

                item.MarketCap   = cup.MarketCap.Value;
                dict[item.Asset] = item;
            }

            foreach (var weight in data.Weights)
            {
                if (!dict.TryGetValue(weight.Key, out var item))
                {
                    item = new AssetInfo(weight.Key);
                }

                item.Weight      = weight.Value;
                dict[item.Asset] = item;
            }
            #endregion

            #region report data

            Console.WriteLine($"===== {name} =====");
            Console.WriteLine($"Index value: {indexValue}, change today: {indexChangeToday:P2}");
            foreach (var item in dict.Values.OrderByDescending(e => e.Weight))
            {
                Console.WriteLine($"  {item.Asset}: Price={item.Price}; \tWeight={item.Weight:P2}; \tMarketCup={item.MarketCap:N0}$");
            }
            Console.WriteLine();

            #endregion
        }