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;
        }
        private void ProcessBalances(object jsonData)
        {
            var data = jsonData as Dictionary <string, object>;

            lock (MiningEngine)
            {
                foreach (var key in data.Keys)
                {
                    var algo    = key.ToLower();
                    var balance = data[key].ExtractDecimal();

                    var entry = GetEntry(algo);
                    if (entry == null)
                    {
                        continue;
                    }

                    entry.Balance = balance;
                }

                Balance = PriceEntries.Sum(o => o.Balance);

                MiningEngine.PricesUpdated = true;
                MiningEngine.HasPrices     = true;

                LastUpdated = DateTime.Now;
            }
        }
Example #3
0
 protected TEntry GetEntryTag(string tag)
 {
     return
         (PriceEntries.FirstOrDefault(
              o =>
              (o.Tag.ToString().ToLower() != null && o.Tag.ToString().ToLower() == tag.ToString().ToLower())));
 }
Example #4
0
 protected TEntry GetEntryCoin(string cname)
 {
     return
         (PriceEntries.FirstOrDefault(
              o =>
              (o.CoinName.ToString().ToLower() != null && o.CoinName.ToString().ToLower() == cname.ToString().ToLower())));
 }
Example #5
0
 protected TEntry GetEntryAlgo(string algo)
 {
     return
         (PriceEntries.FirstOrDefault(
              o =>
              (o.AlgoName.ToString().ToLower() != null && o.AlgoName.ToString().ToLower() == algo.ToString().ToLower())));
 }
Example #6
0
 protected TEntry GetEntry(string algo)
 {
     return
         (PriceEntries.FirstOrDefault(
              o =>
              (o.PriceId != null && o.PriceId == algo) ||
              (o.PriceId == null && o.AlgoName.ToString().ToLower() == GetAlgoName(algo.ToString().ToLower()))));
 }
Example #7
0
        public void Process()
        {
            foreach (var currName in _currencies)
            {
                _calculator.Currencies.Add(currName);
            }

            foreach (var sym in Symbols)
            {
                var         symbolValue = sym.Value;
                SymbolEntry symbolEntry = new SymbolEntry(_calculator, sym.Key, symbolValue.Currency, symbolValue.SettlementCurrency);
                symbolEntry.Hedging = symbolValue.MarginHedge;
                _calculator.Symbols.Add(symbolEntry);
            }


            PriceEntries priceEntries = _calculator.Prices;

            var feed   = FdkHelper.Wrapper.ConnectLogic.Feed;
            var server = feed.Server;

            server.SubscribeToQuotes(_symbolInfoDic.Select(sym => sym.Name), 1);
            var autoResetEvent = new AutoResetEvent(true);

            feed.Tick += (arg, ev) => autoResetEvent.Set();
            autoResetEvent.WaitOne();
            Thread.Sleep(100);

            _symbolInfoDic.Each(sym =>
            {
                var retries = 5;
                double price;
                while (!FdkHelper.Wrapper.ConnectLogic.Feed.Cache.TryGetBid(sym.Name, out price) && retries > 0)
                {
                    Thread.Sleep(100);
                    retries--;
                }

                try
                {
                    priceEntries.Update(sym.Name, price, price);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception on updating calculator for symbol: {0} exception: {1}", sym.Name, ex);
                }
            });
        }
Example #8
0
        private void ProcessBalances(object jsonData)
        {
            Dictionary <string, object> data = jsonData as Dictionary <string, object>;

            lock (MiningEngine)
            {
                foreach (WafflePoolPriceEntry entry in PriceEntries)
                {
                    entry.Balance     = 0;
                    entry.AcceptSpeed = 0;
                    entry.RejectSpeed = 0;
                }

                foreach (string key in data.Keys)
                {
                    object rawitem = data[key];
                    Dictionary <string, object> item = rawitem as Dictionary <string, object>;

                    WafflePoolPriceEntry entry = GetEntry(key.ToLower());
                    if (entry == null)
                    {
                        continue;
                    }

                    entry.AcceptSpeed = item["hashrate"].ExtractDecimal() / 1000000;
                    entry.RejectSpeed = item["stalerate"].ExtractDecimal() / 1000000;

                    Dictionary <string, object> balances = item["balances"] as Dictionary <string, object>;
                    entry.Balance = balances["confirmed"].ExtractDecimal() + balances["unconverted"].ExtractDecimal();
                }

                Balance = PriceEntries.Select(o => o.Balance).Sum();

                MiningEngine.PricesUpdated = true;
            }
        }
        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.ServiceEnum != _currentRunning.ServiceEntry.ServiceEnum
                        ? 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);
            }
        }
Example #10
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 == null || _process.HasExited)
                {
                    _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();
                }

                // Find the best, live entry
                var best = _donationMiningMode == MiningModeEnum.Donation
                    ? _priceEntries
                           .Where(o => !o.IsDead)
                           .Where(o => !string.IsNullOrWhiteSpace(o.DonationCommand))
                           .OrderByDescending(o => o.NetEarn)
                           .First()
                    : _priceEntries
                           .Where(o => !o.IsDead)
                           .Where(o => !string.IsNullOrWhiteSpace(o.Command))
                           .OrderByDescending(o => o.NetEarn)
                           .First();

                // 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;
                    }
                    if (NextRunTime.HasValue && NextRunTime > TimeSpan.Zero)
                    {
                        best = _priceEntries.First(o => o.Id == _currentRunning.Id);
                    }
                }

                // Update undead entries
                var entries = PriceEntries.Where(o => !o.IsDead && o.DeadTime != DateTime.MinValue);
                foreach (var entry in entries)
                {
                    entry.DeadTime = DateTime.MinValue;
                }

                // Just update time if we are already running the right entry
                if (_currentRunning != null && _currentRunning.Id == best.Id)
                {
                    _currentRunning.UpdateStatus();
                    return;
                }

                // Honor minimum time to run in auto mode
                if (MiningTime.HasValue && MiningTime.Value < _minTime)
                {
                    _currentRunning.UpdateStatus();
                    return;
                }

                StopMiner();
                StartMiner(best, isMinimizedToTray);
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
            }
        }