public void Complete(int skippedSignalSnapshots, int skippedTickerSnapshots)
        {
            loggingService.Info("Backtesting results:");

            double lagAmount = 0;

            foreach (KeyValuePair <string, ITimedTask> kvp in tasksService.GetAllTasks().OrderBy(t => t.Key))
            {
                string     taskName = kvp.Key;
                ITimedTask task     = kvp.Value;

                double averageWaitTime = Math.Round(task.TotalLagTime / task.RunCount, 3);
                if (averageWaitTime > 0)
                {
                    lagAmount += averageWaitTime;
                }
                loggingService.Info($" [+] {taskName} Run times: {task.RunCount}, average wait time: " + averageWaitTime);
            }

            loggingService.Info($"Lag value: {lagAmount}. Lower the ReplaySpeed if lag value is positive.");
            loggingService.Info($"Skipped signal snapshots: {skippedSignalSnapshots}");
            loggingService.Info($"Skipped ticker snapshots: {skippedTickerSnapshots}");

            tradingService.SuspendTrading(forced: true);
            signalsService.StopTrailing();
            signalsService.Stop();
        }
Beispiel #2
0
        public int CompareTo(ITimedTask other)
        {
            if (Time == other.Time)
            {
                return(Id - other.Id);
            }

            return(Time - other.Time);
        }
Beispiel #3
0
 public void Run()
 {
     while (m_TimedTasks.Any())
     {
         ITimedTask timedTask = m_TimedTasks.First();
         m_TimedTasks.Remove(timedTask);
         timedTask.Run();
     }
 }
Beispiel #4
0
        /// <summary>
        /// Executes the operations of the timed thread.
        /// </summary>
        private void Execute()
        {
            lock (sync) cancellation = new CancellationTokenSource();

            var process = new ITimedTask[0];
            var factory = new TaskFactory(cancellation.Token);

            while (!cancellation.IsCancellationRequested)
            {
                lock (sync)
                {
                    if (shutdown || !running)
                    {
                        break;
                    }

                    process = tasks.ToArray();
                }

                var now       = DateTime.Now;
                var estimated = -1L;

                foreach (var task in process)
                {
                    if (!task.IsEnabled || task.IsExecuting)
                    {
                        continue;
                    }

                    var interval = task.Interval;

                    if (interval.HasElapsed(task.LastExecutedAt, now))
                    {
                        factory.StartNew(() => task.Trigger());
                    }
                    else
                    {
                        estimated = Math.Min(estimated, interval.GetElapseTime(task.LastExecutedAt, now));
                    }
                }

                if (estimated <= 0)
                {
                    estimated = random.Next(10, 500);
                }

                lock (sync) Monitor.Wait(sync, (int)estimated);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Gets a timed task by name.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public virtual ITimedTask Get(string name)
        {
            ITimedTask t = _ApplicationTasks.FirstOrDefault(x => Internal.CrossPlatformHelpers.StringCompareIgnoreCase(x.Name, name));

            if (t is object)
            {
                return(t);
            }

            if (RequestSettingsProvider is null || !ProviderHasItems(RequestSettingsProvider))
            {
                return(null);
            }

            return(RequestSettingsProvider.Items[name] as TimedTask);
        }
Beispiel #6
0
        /// <summary>
        /// Execute timed task
        /// </summary>
        /// <param name="task"></param>
        public virtual void Execute(ITimedTask task)
        {
            if (task is null)
            {
                return;
            }

            // if requiring debug, and not in debug mode, execute with no tracking
            if (task.RequireDebugMode && RequestSettingsProvider?.IsDebugMode != true)
            {
                task.TimedAction();

                return;
            }

            Stopwatch s = new Stopwatch();

            s.Start();
            task.TimedAction();
            s.Stop();

            if (string.IsNullOrEmpty(task.Name))
            {
                task.Name = "TimedTask:" + Guid.NewGuid();
            }

            task.Timer = s;

            if (task.Scope == TimedActionScope.Application)
            {
                _ApplicationTasks.Add(task);
            }
            else
            {
                if (!ProviderHasItems(RequestSettingsProvider))
                {
                    throw new Exception($"Settings provider or its Items are null and TimerScope is set to {nameof(TimedActionScope.Request)}!");
                }

                RequestSettingsProvider.Items.Remove(task.Name);
                RequestSettingsProvider.Items.Add(task.Name, task);
            }
        }
 protected internal void Add(ITimedTask task)
 {
     _tasks.Add(task);
 }
Beispiel #8
0
 /// <summary>
 /// Adds a task to the timed thread for processing.
 /// </summary>
 /// <param name="task">The task.</param>
 public void Add(ITimedTask task)
 {
     lock (sync) tasks.AddIfMissing(task);
     StartIfRequired();
 }
    public void Add(ITimedTask TimedTask)
    {
        TimedTask.Completed += () =>
        {
            Tasks.Remove(TimedTask);
        };

        Tasks.Add(TimedTask);
    }