Esempio n. 1
0
        private void DoFinal()
        {
            lock (_lock)
            {
                _items.RemoveAll(x => x.IsTotalLine);
                var qa = _quoteAsset;


                SubscribePriceConversion(qa);

                if (_items.Any())
                {
                    _items.Add(new PortfolioTotalLineItem()
                    {
                        Items = _items
                    });
                }

                _groupedAsset.Clear();

                foreach (var i in _items.GroupBy(x => x.Asset))
                {
                    _groupedAsset.Add(PortfolioGroupedItem.Create(qa, i.Key, i.ToList()));
                }

                foreach (var n in _infoItems)
                {
                    n.ConvertedTotal = _items.Where(x => !x.IsTotalLine && Equals(x.Network, n.Network)).Select(x => x.Converted).Sum(_quoteAsset);
                }

                if (_infoItems.All(x => x.ConvertedTotal != null))
                {
                    var t = _infoItems.Select(x => x.ConvertedTotal).Sum();
                    var r = t == 0 ? 0 : 100 / t;

                    foreach (var n in _infoItems)
                    {
                        n.Percentage = Math.Round(n.ConvertedTotal.Value.ToDecimalValue() * r, 2);
                    }
                }
            }
        }
Esempio n. 2
0
        public void SendChangedMessage()
        {
            lock (_lock)
            {
                var msg = new PortfolioResultsMessage
                {
                    UtcLastUpdated       = UtcLastUpdated,
                    Items                = _items.ToList(),
                    NetworkItems         = _infoItems.ToList(),
                    GroupedAsset         = _groupedAsset.ToList(),
                    WorkingProviders     = _workingProviders.ToList(),
                    QueryingProviders    = _queryingProviders.ToList(),
                    FailingProviders     = _failingProviders.ToList(),
                    IsCollectionComplete = _scanners.All(x => _hasCollected.Contains(x.Provider)),
                    IsConversionComplete = _items.All(x => x.Converted != null),
                    TotalConverted       = _items.Where(x => x != null && !x.IsTotalLine).Select(x => x.Converted).Sum(_quoteAsset)
                };

                M.Send(msg, Context.Token);
            }
        }