private void ClientOnNewSpotPortfoliosEvent(Wallets wallets) { try { Portfolio myPortfolio = _portfolios.Find(p => p.Number == "BitMaxSpot"); if (myPortfolio == null) { Portfolio newPortf = new Portfolio(); newPortf.Number = "BitMaxSpot"; newPortf.ValueBegin = 1; newPortf.ValueCurrent = 1; _portfolios.Add(newPortf); myPortfolio = newPortf; } if (wallets.Data == null) { return; } UpdatePortfolio(myPortfolio, wallets); } catch (Exception error) { SendLogMessage(error.ToString(), LogMessageType.Error); } }
private void UpdatePortfolio(Portfolio myPortfolio, Wallets wallets) { myPortfolio.ClearPositionOnBoard(); foreach (var wallet in wallets.Data) { PositionOnBoard newPortf = new PositionOnBoard(); var valueCurrent = wallet.AvailableBalance.ToDecimal(); newPortf.SecurityNameCode = wallet.Asset; newPortf.ValueBegin = wallet.TotalBalance.ToDecimal(); newPortf.ValueCurrent = wallet.AvailableBalance.ToDecimal(); newPortf.ValueBlocked = wallet.TotalBalance.ToDecimal() - valueCurrent; myPortfolio.SetNewPosition(newPortf); } PortfolioEvent?.Invoke(_portfolios); }