Ejemplo n.º 1
0
 private string ActiveTime(PriceEntryBase priceEntry)
 {
     TimeSpan time = priceEntry.TimeMining;
     if (_engine.CurrentRunning == priceEntry.Id && _engine.StartMining.HasValue)
         time += (DateTime.Now - _engine.StartMining.Value);
     return time.FormatTime();
 }
Ejemplo n.º 2
0
 protected bool Equals(PriceEntryBase other)
 {
     return(Id == other.Id && Equals(ServiceEntry, other.ServiceEntry) && string.Equals(PriceId, other.PriceId) &&
            string.Equals(AlgoName, other.AlgoName) && string.Equals(Name, other.Name) &&
            UseWindow.Equals(other.UseWindow) && MinProfit == other.MinProfit && Hashrate == other.Hashrate &&
            Power == other.Power && string.Equals(Priority, other.Priority) && Affinity == other.Affinity &&
            string.Equals(Folder, other.Folder) && string.Equals(Command, other.Command) &&
            string.Equals(Arguments, other.Arguments) && string.Equals(DonationFolder, other.DonationFolder) &&
            string.Equals(DonationCommand, other.DonationCommand) &&
            string.Equals(DonationArguments, other.DonationArguments));
 }
 protected bool Equals(PriceEntryBase other)
 {
     return Id == other.Id && Equals(ServiceEntry, other.ServiceEntry) && string.Equals(PriceId, other.PriceId) &&
            string.Equals(AlgoName, other.AlgoName) && string.Equals(Name, other.Name) &&
            UseWindow.Equals(other.UseWindow) && MinProfit == other.MinProfit && Hashrate == other.Hashrate &&
            Power == other.Power && string.Equals(Priority, other.Priority) && Affinity == other.Affinity &&
            string.Equals(Folder, other.Folder) && string.Equals(Command, other.Command) &&
            string.Equals(Arguments, other.Arguments) && string.Equals(DonationFolder, other.DonationFolder) &&
            string.Equals(DonationCommand, other.DonationCommand) &&
            string.Equals(DonationArguments, other.DonationArguments);
 }
Ejemplo n.º 4
0
        private void StartMiner(PriceEntryBase entry, bool isMinimizedToTray = false)
        {
            _nextRun = null;
            _nextRunFromTime = null;
            _currentRunning = entry;
            _startMining = DateTime.Now;
            _stoppedMining = null;

            _process = new Process();
            if (_donationMiningMode == MiningModeEnum.Donation)
            {
                if (!string.IsNullOrWhiteSpace(entry.DonationFolder))
                    _process.StartInfo.WorkingDirectory = entry.DonationFolder;
                _process.StartInfo.FileName = string.IsNullOrWhiteSpace(entry.DonationFolder)
                    ? entry.DonationCommand
                    : string.Format(@"{0}\{1}", entry.DonationFolder, entry.DonationCommand);
                _process.StartInfo.Arguments = DetectNiceHashStratum(entry) + entry.DonationArguments;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(entry.Folder))
                    _process.StartInfo.WorkingDirectory = entry.Folder;
                _process.StartInfo.FileName = string.IsNullOrWhiteSpace(entry.Folder)
                    ? entry.Command
                    : string.Format(@"{0}\{1}", entry.Folder, entry.Command);
                _process.StartInfo.Arguments = DetectNiceHashStratum(entry) + entry.Arguments;
            }

            WriteConsole(
                string.Format("Starting {0} {1} with {2} {3}", _currentRunning.ServicePrint, _currentRunning.Name,
                    _process.StartInfo.FileName, _process.StartInfo.Arguments), true);

            if (!string.IsNullOrWhiteSpace(_process.StartInfo.WorkingDirectory) &&
                !Directory.Exists(_process.StartInfo.WorkingDirectory))
            {
                entry.DeadTime = DateTime.Now;
                string message = string.Format("Path '{0}' does not exist.", _process.StartInfo.WorkingDirectory);
                _process = null;
                WriteConsole(message, true);
                throw new ArgumentException(message);
            }
            if (!string.IsNullOrWhiteSpace(_process.StartInfo.FileName) && !File.Exists(_process.StartInfo.FileName))
            {
                entry.DeadTime = DateTime.Now;
                string message = string.Format("File '{0}' does not exist.", _process.StartInfo.FileName);
                _process = null;
                WriteConsole(message, true);
                throw new ArgumentException(message);
            }

            if (entry.UseWindow)
            {
                _process.StartInfo.WindowStyle = (isMinimizedToTray && TrayMode == 2)
                    ? ProcessWindowStyle.Hidden
                    : ProcessWindowStyle.Minimized;
                _process.Start();

                Thread.Sleep(100);
                try
                {
                    ProcessUtil.SetWindowTitle(_process, string.Format("{0} {1} Miner", entry.ServicePrint, entry.Name));
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex);
                }

                if (isMinimizedToTray && TrayMode == 1)
                    HideMinerWindow();
            }
            else
            {
                _process.StartInfo.RedirectStandardOutput = true;
                _process.StartInfo.RedirectStandardError = true;
                _process.EnableRaisingEvents = true;
                _process.StartInfo.CreateNoWindow = true;
                _process.StartInfo.UseShellExecute = false;

                _process.ErrorDataReceived += ProcessConsoleOutput;
                _process.OutputDataReceived += ProcessConsoleOutput;

                _process.Start();

                _process.BeginOutputReadLine();
                _process.BeginErrorReadLine();
            }

            ProcessPriorityClass processPriority;
            if (entry.Priority != "Normal" && entry.Priority != string.Empty
                && Enum.TryParse(entry.Priority, out processPriority))
            {
                // Defaults to Normal, other possible values are Idle, BelowNormal,
                // AboveNormal, High & RealTime. ccminer <3 RealTime
                // Note 1: Realtime by minercontrol is only possible when given administrator privileges to minercontrol
                // Note 2: --cpu-priority by ccminer overrides minercontrols priority
                // Note 3: When giving administrator privileges to minercontrol and setting the priority by minercontrol to
                // something DIFFERENT than what's used by --cpu-priority by ccminer, then your whole system locks up
                _process.PriorityClass = processPriority;
            }

            if (entry.Affinity > 0)
            {
                // Just like with start /affinity, you can use 1 for first core, 2 for second core, 4 for third core, etc
                _process.ProcessorAffinity = (IntPtr) entry.Affinity;
            }

            _startMining = DateTime.Now;
            _donationMiningMode = MiningMode;

            entry.UpdateStatus();

            LogActivity(_donationMiningMode == MiningModeEnum.Donation ? "DonationStart" : "Start");
        }
Ejemplo n.º 5
0
        private string DetectNiceHashStratum(PriceEntryBase entry)
        {
            if (entry.ServiceEntry.ServiceName != "NiceHash" && entry.ServiceEntry.ServiceName != "WestHash") return string.Empty;
            NiceHashService niceHash = entry.ServiceEntry as NiceHashService;
            if (niceHash == null || niceHash.DetectStratum == false) return string.Empty;

            return "-o stratum+tcp://" + niceHash.GetBestStratum(entry.AlgoName) + " ";
        }
Ejemplo n.º 6
0
        public void StopMiner()
        {
            if (!_process.IsRunning())
            {
                _process = null;
                return;
            }

            LogActivity(_donationMiningMode == MiningModeEnum.Donation ? "DonationStop" : "Stop");
            WriteConsole(string.Format("Stopping {0} {1}", _currentRunning.ServicePrint, _currentRunning.AlgoName), true);
            RecordMiningTime();
            if (MinerKillMode == 0)
                ProcessUtil.KillProcess(_process);
            else
                ProcessUtil.KillProcessAndChildren(_process.Id);

            _process = null;
            _donationMiningMode = MiningModeEnum.Stopped;

            if (_currentRunning != null)
            {
                PriceEntryBase entry = PriceEntries.Single(o => o.Id == _currentRunning.Id);
                entry.UpdateStatus();
            }

            if(_stoppedMining == null) _stoppedMining = DateTime.Now;
            _currentRunning = null;
        }
Ejemplo n.º 7
0
        public void RunBestAlgo(bool isMinimizedToTray)
        {
            try
            {
                // Check for dead process
                if (!_process.IsRunning() && _currentRunning != null)
                {
                    lock (this)
                    {
                        _currentRunning.DeadTime = DateTime.Now;
                        LogActivity(_donationMiningMode == MiningModeEnum.Donation ? "DonationDead" : "Dead");
                        WriteConsole(string.Format("Dead {0} {1}", _currentRunning.ServicePrint, _currentRunning.Name),
                            true);
                        RecordMiningTime();
                    }
                }

                // Clear information if process not running
                if (!_process.IsRunning())
                {
                    _currentRunning = null;
                    _startMining = null;
                    _nextRun = null;
                    _nextRunFromTime = null;
                }

                // Donation mining
                if (DoDonationMinging)
                {
                    if (_donationMiningMode == MiningModeEnum.Automatic && TimeUntilDonation == TimeSpan.Zero)
                    {
                        StopMiner();
                        _donationMiningMode = MiningModeEnum.Donation;
                        MiningMode = _donationMiningMode;
                        _autoMiningTime = TimeSpan.Zero;
                    }
                    else if (_donationMiningMode == MiningModeEnum.Donation && TimeDuringDonation == TimeSpan.Zero)
                    {
                        StopMiner();
                        _donationMiningMode = MiningModeEnum.Automatic;
                        MiningMode = _donationMiningMode;
                        _donationMiningTime = TimeSpan.Zero;
                    }
                }

                // Restart miner if max time reached
                if (RestartTime.HasValue && RestartTime.Value <= TimeSpan.Zero)
                    StopMiner();

                foreach (PriceEntryBase entry in _priceEntries)
                {
                    entry.BelowMinPrice = entry.NetEarn < _minPrice;
                }

                // Find the best, live entry
                PriceEntryBase best =
                    _priceEntries
                        .Where(o => !IsBadEntry(o))
                        .Where(o =>
                                !string.IsNullOrWhiteSpace(_donationMiningMode == MiningModeEnum.Donation
                                    ? o.DonationCommand
                                    : o.Command))
                                    .OrderByDescending(o => _mineByAverage? o.NetAverage: o.NetEarn)
                        .FirstOrDefault();

                // If none is found, because they're all banned, dead, below minprice
                // All should quit
                if (best == null && _currentRunning != null)
                {
                    StopMiner();
                    return;
                }

                // If the current pool is banned, it should directly start the best one
                if (_currentRunning != null && _currentRunning.Banned
                    && best.Id != _currentRunning.Id)
                {
                    StopMiner();
                    StartMiner(best, isMinimizedToTray);
                    return;
                }

                decimal highestMinProfit = 1M;

                // Handle minimum time for better algorithm before switching
                if (_switchTime > TimeSpan.Zero && _currentRunning != null)
                {
                    if (!_nextRun.HasValue && _currentRunning.Id != best.Id)
                    {
                        _nextRun = best.Id;
                        _nextRunFromTime = DateTime.Now;
                    }
                    else if (_nextRun.HasValue && _currentRunning.Id == best.Id)
                    {
                        _nextRun = null;
                        _nextRunFromTime = null;
                    }

                    _profitBestOverRunning = _mineByAverage? best.NetAverage/_currentRunning.NetAverage : best.NetEarn/_currentRunning.NetEarn;
                    highestMinProfit = best.ServiceEntry.ServiceName != _currentRunning.ServiceEntry.ServiceName
                        ? Math.Max(best.MinProfit, _minProfit)
                        : _minProfit;

                    if (NextRunTime.HasValue && NextRunTime > TimeSpan.Zero)
                        best = _priceEntries.First(o => o.Id == _currentRunning.Id);
                }

                // Update undead entries
                IEnumerable<PriceEntryBase> entries =
                    PriceEntries.Where(o => !o.IsDead && o.DeadTime != DateTime.MinValue);
                foreach (PriceEntryBase entry in entries)
                    entry.DeadTime = DateTime.MinValue;

                if (_currentRunning != null
                    // Guarantees a minimum profit before switching
                    && (_profitBestOverRunning < highestMinProfit
                    // Keeps outliers pending/ignores them if requested and not mining by average
                    || (!_mineByAverage && _ignoreOutliers && best.Outlier)
                    // Just update time if we are already running the right entry
                    || _currentRunning.Id == best.Id
                    // Honor minimum time to run in auto mode
                    || (MiningTime.HasValue && MiningTime.Value < _minTime)))
                {
                    _currentRunning.UpdateStatus();
                    return;
                }

                StopMiner();
                if (_stoppedMining == null || _stoppedMining + _delay <= DateTime.Now) StartMiner(best, isMinimizedToTray);
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
            }
        }
Ejemplo n.º 8
0
 public bool IsBadEntry(PriceEntryBase priceEntry)
 {
     return (priceEntry.BelowMinPrice || priceEntry.Banned || priceEntry.IsDead);
 }
        public void UpdatePrice(PriceEntryBase priceEntryBase)
        {
            DateTime now = DateTime.Now;
            decimal price = priceEntryBase.NetEarn;

            decimal totalPrice = price;
            int totalCount = PriceList.Count;

            List<decimal> window = new List<decimal> {price};
            decimal windowedPrice = price;
            int windowedCount = 0;
            bool outlier = false;

            if (!PriceList.ContainsKey(priceEntryBase))
                PriceList.Add(priceEntryBase, new List<PriceStat>());

            foreach (PriceStat stat in PriceList[priceEntryBase])
            {
                decimal historicPrice = stat.CurrentPrice;
                totalPrice += historicPrice;

                if (stat.Time == now) return;
                if (stat.Time >= now - _statWindow)
                {
                    window.Add(historicPrice);
                    windowedPrice += historicPrice;
                    windowedCount++;
                }
            }

            decimal totalAveragePrice = totalPrice/(totalCount+1);
            decimal windowedAveragePrice = windowedPrice/(windowedCount+1);

            if (windowedCount >= 10) // Makes sure at least ten entries are in there
            {
                window.Sort();
                if (_iqrMultiplier > 0)
                {
                    double sumOfSquareOfDifferences =
                        (double) PriceList[priceEntryBase].Where(stat => stat.Time >= now - _statWindow)
                            .Sum(stat =>
                                (stat.CurrentPrice - windowedAveragePrice) *
                                (stat.CurrentPrice - windowedAveragePrice));
                    decimal standardDeviation = (decimal) Math.Sqrt(sumOfSquareOfDifferences/windowedCount);
                    decimal top = windowedAveragePrice + standardDeviation;
                    decimal bottom = windowedAveragePrice - standardDeviation;
                    decimal iqr = top - bottom;
                    decimal max = windowedAveragePrice + (iqr * _iqrMultiplier);
                    outlier = price > max;
                }
                else
                {
                    // If the IQR multiplier is negative or zero,
                    // it'll try to use percentiles for outlierdetection
                    // Not advised! Will kill off trending profits, iqr-multiplying is preferable
                    int outlierIndex = (int) Math.Truncate(window.Count*_percentile);
                    decimal[] outliers = {window[outlierIndex], window[window.Count - outlierIndex]};
                    outlier = price > outliers.Max();
                }
            }

            PriceStat priceStat = new PriceStat
            {
                Time = now,
                CurrentPrice = price,
                TotalAveragePrice = totalAveragePrice,
                WindowedAveragePrice = windowedAveragePrice,
                Outlier = outlier
            };

            priceEntryBase.Outlier = outlier;
            priceEntryBase.NetAverage = windowedAveragePrice;

            PriceList[priceEntryBase].Add(priceStat);
        }