private void UpdateStatisticAccount(long accountId) { var mt4AccountData = accountService.GetMt4AccountInfo(accountId); if (!mt4AccountData.IsSuccess) { throw new Exception(mt4AccountData.Error); } var statistic = statisticRepository.GetLastStatistic(accountId); if (statistic == null && mt4AccountData.Result.Role == AccountRole.Trading) { return; } var clientData = clientService.GetClient(mt4AccountData.Result.ClientId); if (!clientData.IsSuccess) { throw new Exception(clientData.Error); } var traders = new List <Trader>(); var providers = new List <SignalProvider>(); var s = new List <Manager>(); var clientAccountsNumberData = accountService.GetClientAccountsNumber(clientData.Result.Id, false); if (!clientAccountsNumberData.IsSuccess) { throw new Exception(clientAccountsNumberData.Error); } var ratingAccount = new RatingAccount { AccountId = mt4AccountData.Result.AccountId, Age = mt4AccountData.Result.Age, Avatar = mt4AccountData.Result.Avatar, Country = clientData.Result.Country, Currency = mt4AccountData.Result.Currency, Login = mt4AccountData.Result.Login, Name = string.IsNullOrEmpty(mt4AccountData.Result.Nickname) ? mt4AccountData.Result.Login.ToString() : mt4AccountData.Result.Nickname, Nickname = mt4AccountData.Result.Nickname, Rating = mt4AccountData.Result.RatingValue, AccountsNumber = clientAccountsNumberData.Result, ClientNickname = clientData.Result.Nickname }; AddStatisticAccount(ratingAccount, new AccountDayStatistic(statistic), mt4AccountData.Result.Role, traders, providers, s); lock (topAccountsLock) { switch (mt4AccountData.Result.Role) { case AccountRole.Trading: if (traders.Any()) { topTraders[traders.First().AccountId] = traders.First(); } break; case AccountRole.SignalProvider: if (providers.Any()) { topSignalProviders[providers.First().AccountId] = providers.First(); } break; case AccountRole.Master: if (s.Any()) { topManagers[s.First().AccountId] = s.First(); } break; } } }
private void AddStatisticAccount(RatingAccount ratingAccount, AccountDayStatistic statistic, AccountRole accType, List <Trader> traders, List <SignalProvider> providers, List <Manager> s) { if (statistic.MaxOpenOrders <= 0) { return; } switch (accType) { case AccountRole.Trading: traders.Add(new Trader { AccountId = ratingAccount.AccountId, Age = ratingAccount.Age, Country = ratingAccount.Country, AccountNickname = ratingAccount.Nickname, Login = ratingAccount.Login, LoseOrders = statistic.ClosedLoseTradesTotal, MaxDailyDrowdown = (float)statistic.MaxDailyDrowdown, Profit = (float)statistic.ClosedProfitInPointsTotal, ProfitLastDay = (float)statistic.ClosedProfitInPointsPerDay, ProfitOrders = statistic.ClosedProfitTradesTotal, Volatility = (float)statistic.VolatilityPerDay, Avatar = ratingAccount.Avatar, Rating = ratingAccount.Rating, ClientNickname = ratingAccount.ClientNickname, Currency = ratingAccount.Currency, Chart = statisticRepository.GetDecimatedChart(ratingAccount.AccountId, Constants.PointsCountInSmallChart, StatisticRepository.StatisticType.ProfitInPointsTotal), AccountsNumber = ratingAccount.AccountsNumber, }); break; case AccountRole.SignalProvider: var subscribers = signalService.GetProviderSubscribers(ratingAccount.AccountId); if (!subscribers.IsSuccess) { throw new Exception(subscribers.Error); } providers.Add(new SignalProvider { AccountId = ratingAccount.AccountId, Age = ratingAccount.Age, Country = ratingAccount.Country, AccountNickname = ratingAccount.Nickname, Login = ratingAccount.Login, Profit = (float)statistic.ClosedProfitInPointsTotal, ProfitLastDay = (float)statistic.ClosedProfitInPointsPerDay, Subscribers = subscribers.Result.Length, LoseOrders = statistic.ClosedLoseTradesTotal, MaxDailyDrowdown = (float)statistic.MaxDailyDrowdown, ProfitOrders = statistic.ClosedProfitTradesTotal, Volatility = (float)statistic.VolatilityPerDay, Avatar = ratingAccount.Avatar, Rating = ratingAccount.Rating, ClientNickname = ratingAccount.ClientNickname, Currency = ratingAccount.Currency, Chart = statisticRepository.GetDecimatedChart(ratingAccount.AccountId, Constants.PointsCountInSmallChart, StatisticRepository.StatisticType.ProfitInPointsTotal), AccountsNumber = ratingAccount.AccountsNumber, }); break; case AccountRole.Master: var investorsCount = Service.GetIvestorsCount(ratingAccount.AccountId); if (!investorsCount.IsSuccess) { throw new Exception(investorsCount.Error); } s.Add(new Manager { AccountId = ratingAccount.AccountId, Age = ratingAccount.Age, Country = ratingAccount.Country, AccountNickname = ratingAccount.Nickname, Login = ratingAccount.Login, Profit = (float)statistic.ClosedProfitInPercentsTotal, ProfitLastDay = (float)statistic.ClosedProfitInPercentsPerDay, Investors = investorsCount.Result, LoseOrders = statistic.ClosedLoseTradesTotal, MaxDailyDrowdown = (float)statistic.MaxDailyDrowdown, ProfitOrders = statistic.ClosedProfitTradesTotal, Volatility = (float)statistic.VolatilityPerDay, Avatar = ratingAccount.Avatar, Rating = ratingAccount.Rating, ClientNickname = ratingAccount.ClientNickname, Currency = ratingAccount.Currency, Chart = statisticRepository.GetDecimatedChart(ratingAccount.AccountId, Constants.PointsCountInSmallChart, StatisticRepository.StatisticType.ProfitInPercentTotal), AccountsNumber = ratingAccount.AccountsNumber, }); break; } }