Beispiel #1
0
        public TrackModel Run(TrackModel model, AccountModel account, SettingService settings, HostDomainLogger logger)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            Log.LogHandler = logger;
            if (!SetConfig(model, account, settings))
            {
                return(model);
            }

            // Register all data providers
            ProviderFactory.RegisterProviders();

            Log.Trace("LeanLanucher: Memory " + OS.ApplicationMemoryUsed + "Mb-App " + OS.TotalPhysicalMemoryUsed + "Mb-Used");
            try
            {
                var liveMode = Config.GetBool("live-mode");
                using (var algorithmHandlers = LeanEngineAlgorithmHandlers.FromConfiguration(Composer.Instance))
                    using (var systemHandlers = LeanEngineSystemHandlers.FromConfiguration(Composer.Instance))
                    {
                        string assemblyPath;
                        systemHandlers.Initialize();
                        var engine              = new Engine(systemHandlers, algorithmHandlers, liveMode);
                        var algorithmManager    = new AlgorithmManager(liveMode);
                        AlgorithmNodePacket job = systemHandlers.JobQueue.NextJob(out assemblyPath);
                        job.UserPlan = UserPlan.Professional;
                        systemHandlers.LeanManager.Initialize(systemHandlers, algorithmHandlers, job, algorithmManager);
                        engine.Run(job, algorithmManager, assemblyPath);
                        systemHandlers.JobQueue.AcknowledgeJob(job);
                        BacktestResultHandler resultHandler = algorithmHandlers.Results as BacktestResultHandler;
                        model.Result = resultHandler?.JsonResult ?? string.Empty;
                        model.Logs   = resultHandler?.Logs ?? string.Empty;
                    }
            }
            catch (Exception ex)
            {
                Log.Error("{0}: {1}", ex.GetType(), ex.Message);
            }

            NetMQConfig.Cleanup(false);
            Log.LogHandler.Dispose();
            return(model);
        }
Beispiel #2
0
        public TrackModel Run(TrackModel model, AccountModel account, SettingModel settings, HostDomainLogger logger)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            Log.LogHandler = logger;
            if (!SetConfig(model, account, settings))
            {
                return(model);
            }

            // Register all data providers
            ProviderFactory.RegisterProviders(settings);

            Log.Trace("LeanLanucher: Memory " + OS.ApplicationMemoryUsed + "Mb-App " + OS.TotalPhysicalMemoryUsed + "Mb-Used");
            try
            {
                var liveMode = Config.GetBool("live-mode");
                using var algorithmHandlers = LeanEngineAlgorithmHandlers.FromConfiguration(Composer.Instance);
                using var systemHandlers    = LeanEngineSystemHandlers.FromConfiguration(Composer.Instance);
                systemHandlers.Initialize();
                var engine              = new Engine(systemHandlers, algorithmHandlers, liveMode);
                var algorithmManager    = new AlgorithmManager(liveMode);
                AlgorithmNodePacket job = systemHandlers.JobQueue.NextJob(out string assemblyPath);
                job.UserPlan = UserPlan.Professional;
                job.Language = model.AlgorithmLanguage;
                if (job is BacktestNodePacket backtest)
                {
                    backtest.PeriodStart  = model.StartDate;
                    backtest.PeriodFinish = model.EndDate;
                    backtest.CashAmount   = new CashAmount(model.InitialCapital, Currencies.USD);
                }
                systemHandlers.LeanManager.Initialize(systemHandlers, algorithmHandlers, job, algorithmManager);
                engine.Run(job, algorithmManager, assemblyPath, WorkerThread.Instance);
                BacktestResultHandler resultHandler = algorithmHandlers.Results as BacktestResultHandler;
                model.Result = resultHandler?.JsonResult ?? string.Empty;
                model.Logs   = resultHandler?.Logs ?? string.Empty;
            }
            catch (Exception ex)
            {
                Log.Error("{0}: {1}", ex.GetType(), ex.Message);
            }

            NetMQConfig.Cleanup(false);
            Log.LogHandler.Dispose();
            return(model);
        }