public void Websocket()
        {
            using (var ws = new WebSocket(CommonConstants.CryptoCompareWebsocketUri + CommonConstants.CryptoCompareApiKey)
                   )
            {
                ws.OnMessage += (sender, e) =>
                {
                    CryptoCompareCoin cryptoCompareCoin = JsonConvert.DeserializeObject <CryptoCompareCoin>(e.Data);
                    if (!string.IsNullOrEmpty(cryptoCompareCoin.FROMSYMBOL))
                    {
                        CommonCoin commonCoin = new CommonCoin()
                        {
                            Symbol         = cryptoCompareCoin.FROMSYMBOL,
                            Price          = cryptoCompareCoin.PRICE,
                            HighPrice      = cryptoCompareCoin.HIGH24HOUR,
                            OpenPrice      = cryptoCompareCoin.OPEN24HOUR,
                            CurrencySymbol = cryptoCompareCoin.TOSYMBOL,
                            Timestamp      = cryptoCompareCoin.LASTUPDATE
                        };

                        _cloudFirestoreRepository.CreatOrUpdate(commonCoin, CommonConstants.CryptoCompareCollectionName);
                    }
                };

                ws.Connect();
                ws.Send(JsonConvert.SerializeObject(_commonConstants.CryptoCompareCoinRequestParams));

                Console.ReadKey(true);
            }
        }
Beispiel #2
0
        /// <summary>CoinList
        /// <para>Get general info for all the coins available on the website.</para>
        /// <para>Required : none</para>
        /// <para>Optional : none</para>
        /// </summary>
        public static List <CryptoCompareCoin> getCoinList()
        {
            List <CryptoCompareCoin> list = new List <CryptoCompareCoin>();

            try
            {
                RestClient tclient = new RestClient("https://www.cryptocompare.com");
                var        request = new RestRequest("/api/data/coinlist/", Method.GET);
                //var request = new RestRequest("/data/coinlist/", Method.GET);
                var response = tclient.Execute(request);
                //LogManager.AddLogMessage(thisClassName, "getCoinList", "response.Content=" + response.Content, LogManager.LogMessageType.DEBUG);
                var jsonObject             = JObject.Parse(response.Content);
                CryptoCompareResult result = jsonObject.ToObject <CryptoCompareResult>();
                if (result.Response.ToLower() == "success")
                {
                    //LogManager.AddLogMessage(thisClassName, "getCoinList", "success : " + jsonObject["Data"].ToString(), LogManager.LogMessageType.DEBUG);
                    var data = JObject.Parse(jsonObject["Data"].ToString());

                    foreach (var item in data)
                    {
                        CryptoCompareCoin coin = data[item.Key].ToObject <CryptoCompareCoin>();
                        list.Add(coin);
                    }
                }
                else
                {
                    LogManager.AddLogMessage(Name, "getCoinList", "success IS FALSE : message=" + result.Message + " | Type=" + result.Type, LogManager.LogMessageType.DEBUG);
                }
            }
            catch (Exception ex)
            {
                LogManager.AddLogMessage(Name, "getCoinList", ex.Message, LogManager.LogMessageType.EXCEPTION);
            }
            return(list);
        }
        private void UpdateGroups()
        {
            if (view != BalanceViewType.balance)
            {
                //LogManager.AddLogMessage(Name, "UpdateGroups", "view=" + view + " | group.count=" + listView.OLVGroups.Count, LogManager.LogMessageType.OTHER);
                List <ExchangeBalance> balances = GetBalances();

                switch (view)
                {
                case BalanceViewType.symbol:
                    //LogManager.AddLogMessage(Name, "aboutToCreateGroups", "Group Count=" + e.Groups.Count + " | view=" + view + " | params=" + e.Parameters + " | " + e.Groups, LogManager.LogMessageType.OTHER);
                    listView.GroupImageList = ContentManager.SymbolIconList;

                    foreach (OLVGroup group in listView.OLVGroups)
                    {
                        //LogManager.AddLogMessage(Name, "aboutToCreateGroups", "GroupId=" + group.GroupId + " | Header=" + group.Header + " | id=" + group.Id + " | Key=" + group.Key + " | name=" + group.Name + " | " + group.Collapsed, LogManager.LogMessageType.OTHER);
                        List <ExchangeBalance> symbalances = balances.Where(item => item.Symbol == group.Key.ToString() && item.Balance > 0).ToList();
                        decimal usdTotal  = symbalances.Sum(b => b.TotalInUSD);
                        decimal btcTotal  = symbalances.Sum(b => b.TotalInBTC);
                        decimal coinTotal = symbalances.Sum(b => b.Balance);

                        CryptoCompareCoin coin = PreferenceManager.CryptoComparePreferences.CoinList.FirstOrDefault(item => item.Symbol == group.Key.ToString());
                        //LogManager.AddLogMessage(Name, "aboutToCreateGroups", "HEADER=" + group.Header + " | id=" + group.Id + " | Key=" + group.Key + " | name=" + group.Name + " | itemcount=" + group.Items.Count, LogManager.LogMessageType.OTHER);

                        if (coin != null)
                        {
                            group.Header = coin.FullName;
                        }
                        else
                        {
                            group.Header = group.Header.ToUpper();
                        }

                        group.TitleImage = group.Key;

                        if (balances.Count > 1)
                        {
                            group.Task = "[" + symbalances.Count + "] " + usdTotal.ToString("C");
                        }
                        else
                        {
                            group.Task = usdTotal.ToString("C");
                        }
                        group.Subtitle = "(" + coinTotal.ToString("N8") + ")";
                    }
                    //setGroupStates(true);
                    break;

                case BalanceViewType.exchange:
                    listView.GroupImageList = ContentManager.ExchangeIconList;

                    foreach (OLVGroup group in listView.OLVGroups)
                    {
                        //LogManager.AddLogMessage(Name, "aboutToCreateGroups", "GroupId=" + group.Items.Count + " | Header=" + group.Header + " | id=" + group.Id + " | Key=" + group.Key + " | name=" + group.Name + " | " + group.Collapsed);
                        decimal usdTotal = balances.Where(item => item.Exchange == group.Key.ToString() && item.Balance > 0).Sum(b => b.TotalInUSD);
                        decimal btcTotal = balances.Where(item => item.Exchange == group.Key.ToString() && item.Balance > 0).Sum(b => b.TotalInBTC);
                        group.Header     = group.Header.ToUpper();
                        group.TitleImage = group.Key;

                        if (group.Items.Count > 1)
                        {
                            group.Task = "[" + group.Items.Count + "] " + usdTotal.ToString("C");
                        }
                        else
                        {
                            group.Task = usdTotal.ToString("C");
                        }

                        group.Subtitle = "(" + btcTotal.ToString("N8") + ")";
                    }
                    //setGroupStates(true);
                    break;

                case BalanceViewType.balance:
                    // DO NOTHING
                    break;

                default:
                    // DO NOTHING
                    break;
                }
            }
        }
Beispiel #4
0
        private void aboutToCreateGroups(object sender, CreateGroupsEventArgs e)
        {
            //LogManager.AddLogMessage(Name, "aboutToCreateGroups", "view=" + view + " | group.count=" + e.Groups.Count, LogManager.LogMessageType.OTHER);
            try
            {
                List <ExchangeBalance> balances = GetBalances();

                switch (view)
                {
                case BalanceViewType.symbol:
                    //LogManager.AddLogMessage(Name, "aboutToCreateGroups", "Group Count=" + e.Groups.Count + " | view=" + view + " | params=" + e.Parameters + " | " + e.Groups, LogManager.LogMessageType.OTHER);

                    listView.GroupImageList = ContentManager.SymbolIconList;
                    foreach (OLVGroup group in e.Groups)
                    {
                        string key = group.Key.ToString();

                        if (!groupStates.ContainsKey(key))
                        {
                            groupStates.Add(key, false);
                        }

                        //LogManager.AddLogMessage(Name, "aboutToCreateGroups", "GroupId=" + group.GroupId + " | Header=" + group.Header + " | id=" + group.Id + " | Key=" + group.Key + " | name=" + group.Name + " | " + group.Collapsed, LogManager.LogMessageType.OTHER);
                        List <ExchangeBalance> symbalances = balances.Where(item => item.Symbol == key.ToString() && item.Balance > 0).ToList();
                        decimal usdTotal  = symbalances.Sum(b => b.TotalInUSD);
                        decimal btcTotal  = symbalances.Sum(b => b.TotalInBTC);
                        decimal coinTotal = symbalances.Sum(b => b.Balance);

                        CryptoCompareCoin   coin      = PreferenceManager.CryptoComparePreferences.CoinList.FirstOrDefault(item => item.Symbol == group.Key.ToString());
                        CoinMarketCapTicker priceItem = PreferenceManager.CoinMarketCapPreferences.Tickers.FirstOrDefault(item => item.symbol == key);
                        //LogManager.AddLogMessage(Name, "aboutToCreateGroups", "HEADER=" + group.Header + " | id=" + group.Id + " | Key=" + group.Key + " | name=" + group.Name + " | itemcount=" + group.Items.Count, LogManager.LogMessageType.OTHER);
                        string price = "";
                        if (priceItem != null)
                        {
                            price = " " + priceItem.price_usd.ToString("C");
                        }

                        if (coin != null)
                        {
                            group.Header = coin.FullName + price;
                        }
                        else
                        {
                            group.Header = key + price;
                        }

                        group.TitleImage = key;

                        if (balances.Count > 1)
                        {
                            group.Task = "[" + symbalances.Count + "] " + usdTotal.ToString("C");
                        }
                        else
                        {
                            group.Task = usdTotal.ToString("C");
                        }
                        group.Subtitle  = "(" + coinTotal.ToString("N8") + ")";
                        group.Collapsed = groupStates[key];
                    }
                    break;

                case BalanceViewType.exchange:
                    listView.GroupImageList = ContentManager.ExchangeIconList;

                    foreach (OLVGroup group in e.Groups)
                    {
                        string key = group.Key.ToString();

                        if (!groupStates.ContainsKey(key))
                        {
                            groupStates.Add(key, false);
                        }
                        //LogManager.AddLogMessage(Name, "aboutToCreateGroups", "GroupId=" + group.Items.Count + " | Header=" + group.Header + " | id=" + group.Id + " | Key=" + group.Key + " | name=" + group.Name + " | " + group.Collapsed);
                        decimal usdTotal = balances.Where(item => item.Exchange == group.Key.ToString() && item.Balance > 0).Sum(b => b.TotalInUSD);
                        decimal btcTotal = balances.Where(item => item.Exchange == group.Key.ToString() && item.Balance > 0).Sum(b => b.TotalInBTC);
                        group.Header     = group.Header.ToUpper();
                        group.TitleImage = group.Key;

                        if (group.Items.Count > 1)
                        {
                            group.Task = "[" + group.Items.Count + "] " + usdTotal.ToString("C");
                        }
                        else
                        {
                            group.Task = usdTotal.ToString("C");
                        }

                        group.Subtitle  = "(" + btcTotal.ToString("N8") + ")";
                        group.Collapsed = groupStates[key];
                    }

                    break;

                case BalanceViewType.balance:
                    // DO NOTHING
                    break;

                default:
                    // DO NOTHING
                    break;
                }
            }
            catch (Exception ex)
            {
                LogManager.AddLogMessage(Name, "aboutToCreateGroups", ex.Message, LogManager.LogMessageType.EXCEPTION);
            }
        }