/// <summary>
        /// Checks profits and updates normalization based on ticks
        /// </summary>
        internal void SmaCheckTimerOnElapsed(object sender, ElapsedEventArgs e)
        {
            Randomize();

            // Will be null if manually called (in tests)
            if (_smaCheckTimer != null)
            {
                _smaCheckTimer.Interval = _smaCheckTime * 1000;
            }

            var sb = new StringBuilder();

            if (_hasStarted)
            {
                sb.AppendLine("Normalizing profits");
            }

            var stableUpdated   = UpdateProfits(_stableHistory, _ticksForStable, sb);
            var unstableUpdated = UpdateProfits(_unstableHistory, _ticksForUnstable, sb);

            if (!stableUpdated && !unstableUpdated && _hasStarted)
            {
                sb.AppendLine("No algos affected (either no SMA update or no algos higher");
            }

            if (_hasStarted)
            {
                Logger.Info(Tag, sb.ToString());
            }
            else
            {
                _hasStarted = true;
            }

            var args = new SmaUpdateEventArgs(_lastLegitPaying);

            SmaCheck?.Invoke(this, args);
        }
        public void ForceUpdate()
        {
            var isAllZeroPaying = _lastLegitPaying.Values.Any(paying => paying == 0);

            if (isAllZeroPaying)
            {
                foreach (var kvp in NHSmaData.FilteredCurrentProfits(true))
                {
                    _stableHistory[kvp.Key]   = new AlgorithmHistory(MaxHistory);
                    _lastLegitPaying[kvp.Key] = kvp.Value;
                }
                foreach (var kvp in NHSmaData.FilteredCurrentProfits(false))
                {
                    _unstableHistory[kvp.Key] = new AlgorithmHistory(MaxHistory);
                    _lastLegitPaying[kvp.Key] = kvp.Value;
                }
            }
            var args = new SmaUpdateEventArgs(_lastLegitPaying);

            Stop();
            SmaCheck?.Invoke(this, args);
            Start();
        }
Beispiel #3
0
        /// <summary>
        /// Checks profits and updates normalization based on ticks
        /// </summary>
        internal void SmaCheckTimerOnElapsed(object sender, ElapsedEventArgs e)
        {
            Randomize();

            var sb = new StringBuilder();

            sb.AppendLine("Normalizing profits");

            UpdateProfits(_stableHistory, _ticksForStable, sb);
            UpdateProfits(_unstableHistory, _ticksForUnstable, sb);

            Helpers.ConsolePrint(Tag, sb.ToString());

            var args = new SmaUpdateEventArgs(_lastLegitPaying);

            SmaCheck?.Invoke(this, args);

            // Will be null if manually called (in tests)
            if (_smaCheckTimer != null)
            {
                _smaCheckTimer.Interval = _smaCheckTime * 1000;
            }
        }