Пример #1
0
        public async Task RunBots()
        {
            users = GetUsers(pathToUsers);

            SessionInfo sessionInfo = new SessionInfo(DateTime.Now);

            //Running bots
            using (HttpClient http = new HttpClient())
            {
                foreach (User user in users)
                {
                    LTCBot ltcBot = new LTCBot(user, http);
                    await ltcBot.ConnectAsync();

                    await CheckAuthorization(ltcBot);

                    //Check timeouts of bot
                    if (!IsTimeoutsGood(user))
                    {
                        continue;
                    }

                    BotStateInfo result = new BotStateInfo();

                    try
                    {
                        OnUserStarted?.Invoke(user);
                        SubscribeOnBotEvents(ltcBot);
                        result = await ltcBot.Start();
                        await TryToWithdraw(ltcBot, result);
                    }
                    catch (Exception e)
                    {
                        OnBotException?.Invoke(e);
                    }

                    SaveUsers();

                    OnUserCompleted?.Invoke(result);
                    UpdateSessionInfo(sessionInfo, result);

                    //Timeout before starting next bot
                    if (users.Last() != user)
                    {
                        await Task.Delay(60000);
                    }
                }
            }

            if (sessionInfo.CountOfUsers > 0)
            {
                sessionInfo.DurationInMinutes = (DateTime.Now - sessionInfo.Date).TotalMinutes;
                SaveSession(sessionInfo);
            }

            OnSessionCompleted?.Invoke(sessionInfo);
        }
Пример #2
0
        private async Task TryToWithdraw(LTCBot ltcBot, BotStateInfo result)
        {
            if (result.BalanceOfBot > 0.0004m)
            {
                try
                {
                    await ltcBot.Withdraw();

                    OnWithdrawed?.Invoke(result.BalanceOfBot);
                    withdrowedFromSession += result.BalanceOfBot;
                    result.BalanceOfBot    = 0;
                }
                catch (Exception e)
                {
                    OnBotException?.Invoke(e);
                }
            }
        }