예제 #1
0
        private void LaunchLean()
        {
            Config.Set ("environment", "desktop");
            string algorithm = "EMATest";

            Config.Set("algorithm-type-name", algorithm);

            _jobQueue = new JobQueue ();
            _notify = new Messaging ();
            _api = new Api();
            _resultshandler = new DesktopResultHandler ();
            _dataFeed = new FileSystemDataFeed ();
            _setup = new ConsoleSetupHandler ();
            _realTime = new BacktestingRealTimeHandler ();
            _historyProvider = new SubscriptionDataReaderHistoryProvider ();
            _transactions = new BacktestingTransactionHandler ();

            var systemHandlers = new LeanEngineSystemHandlers (_jobQueue, _api, _notify);
            systemHandlers.Initialize ();

            var algorithmHandlers = new LeanEngineAlgorithmHandlers (_resultshandler, _setup, _dataFeed, _transactions, _realTime, _historyProvider);

            var _engine = new Engine (systemHandlers, algorithmHandlers, Config.GetBool ("live-mode"));
            string algorithmPath;
            var job = systemHandlers.JobQueue.NextJob(out algorithmPath);
            _engine.Run(job, algorithmPath);
        }
예제 #2
0
파일: Engine.cs 프로젝트: sopnic/Lean
        /// <summary>
        /// Get the setup handler for this algorithm, depending on its use case.
        /// </summary>
        /// <param name="setupMethod">Setup handler</param>
        /// <returns>Instance of a setup handler:</returns>
        private static ISetupHandler GetSetupHandler(SetupHandlerEndpoint setupMethod)
        {
            var sh = default(ISetupHandler);

            switch (setupMethod)
            {
                //Setup console handler:
                case SetupHandlerEndpoint.Console:
                    sh = new ConsoleSetupHandler();
                    Log.Trace("Engine.GetSetupHandler(): Selected Console Algorithm Setup Handler.");
                    break;
                //Default, backtesting result handler:
                case SetupHandlerEndpoint.Backtesting:
                    sh = new BacktestingSetupHandler();
                    Log.Trace("Engine.GetSetupHandler(): Selected Backtesting Algorithm Setup Handler.");
                    break;
                case SetupHandlerEndpoint.Brokerage:
                    sh = new BrokerageSetupHandler();
                    Log.Trace("Engine.GetSetupHandler(): Selected Brokerage Algorithm Setup Handler.");
                    break;
            }
            return sh;
        }
예제 #3
0
        /// <summary>
        /// Launches a Lean Engine using a parameter
        /// </summary>
        /// <param name="val">The paramater to use when launching lean. </param>
        private void LaunchLean(string val)
        {
            Config.Set("environment", "backtesting");
            string algorithm = val;

            // Set the algorithm in Config.  Here is where you can customize Config settings
            Config.Set("algorithm-type-name", algorithm);

            _jobQueue = new JobQueue();
            _notify = new Messaging();
            _api = new Api();

            /************  Comment one of the two following lines to select which ResultHandler to use ***********/
            _resultshandler = new OptimizationResultHandler();
            //_resultshandler = new ConsoleResultHandler();

            _dataFeed = new FileSystemDataFeed();
            _setup = new ConsoleSetupHandler();
            _realTime = new BacktestingRealTimeHandler();
            _historyProvider = new SubscriptionDataReaderHistoryProvider();
            _transactions = new BacktestingTransactionHandler();

            // Set the Log.LogHandler to only write to the log.txt file.
            //  This setting avoids writing Log messages to the console.
            Log.LogHandler = (ILogHandler)new FileLogHandler();
            Log.DebuggingEnabled = false;                           // Set this property to true for lots of messages
            Log.DebuggingLevel = 1;                                 // A reminder that the default level for Log.Debug message is 1

            var systemHandlers = new LeanEngineSystemHandlers(_jobQueue, _api, _notify);
            systemHandlers.Initialize();

            var algorithmHandlers = new LeanEngineAlgorithmHandlers(_resultshandler, _setup, _dataFeed, _transactions, _realTime, _historyProvider);
            string algorithmPath;

            AlgorithmNodePacket job = systemHandlers.JobQueue.NextJob(out algorithmPath);
            try
            {
                var _engine = new Engine(systemHandlers, algorithmHandlers, Config.GetBool("live-mode"));
                _engine.Run(job, algorithmPath);
            }
            finally
            {
                /* The JobQueue.AcknowledgeJob only asks for any key to close the window.
                 * We do not want that behavior, so we comment out this line so that multiple Leans will run
                 *
                 * The alternative is to comment out Console.Read(); the line in JobQueue class.
                 */
                //systemHandlers.JobQueue.AcknowledgeJob(job);
                Log.Trace("Engine.Main(): Packet removed from queue: " + job.AlgorithmId);

                // clean up resources
                systemHandlers.Dispose();
                algorithmHandlers.Dispose();
                Log.LogHandler.Dispose();
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: bizcad/LeanOpto
        private void LaunchLean()
        {
            Config.Set("environment", "backtesting");
            string algorithm = "EMATest";

            Config.Set("algorithm-type-name", algorithm);
            //string datapath = Config.Get("data-folder");
            _jobQueue = new JobQueue();
            _notify = new Messaging();
            _api = new Api();
            _resultshandler = new OptimizationResultHandler();
            //_resultshandler = new ConsoleResultHandler();
            _dataFeed = new FileSystemDataFeed();
            _setup = new ConsoleSetupHandler();
            _realTime = new BacktestingRealTimeHandler();
            _historyProvider = new SubscriptionDataReaderHistoryProvider();
            _transactions = new BacktestingTransactionHandler();
            Log.LogHandler = (ILogHandler)new FileLogHandler();
            Log.DebuggingEnabled = false;
            Log.DebuggingLevel = 1;

            var systemHandlers = new LeanEngineSystemHandlers(_jobQueue, _api, _notify);
            systemHandlers.Initialize();

            var algorithmHandlers = new LeanEngineAlgorithmHandlers(_resultshandler, _setup, _dataFeed, _transactions, _realTime, _historyProvider);
            string algorithmPath;

            AlgorithmNodePacket job = systemHandlers.JobQueue.NextJob(out algorithmPath);
            try
            {
                var _engine = new Engine(systemHandlers, algorithmHandlers, Config.GetBool("live-mode"));
                _engine.Run(job, algorithmPath);
            }
            finally
            {
                //Delete the message from the job queue:
                //systemHandlers.JobQueue.AcknowledgeJob(job);
                Log.Trace("Engine.Main(): Packet removed from queue: " + job.AlgorithmId);

                // clean up resources
                systemHandlers.Dispose();
                algorithmHandlers.Dispose();
                Log.LogHandler.Dispose();
            }
        }
예제 #5
0
        private void LaunchLean()
        {
            Config.Set ("environment", "backtesting");
            string algorithm = "EMATest";

            Config.Set("algorithm-type-name", algorithm);

            _jobQueue = new JobQueue ();
            _notify = new Messaging ();
            _api = new Api();
            _resultshandler = new DesktopResultHandler ();
            _dataFeed = new FileSystemDataFeed ();
            _setup = new ConsoleSetupHandler ();
            _realTime = new BacktestingRealTimeHandler ();
            _historyProvider = new SubscriptionDataReaderHistoryProvider ();
            _transactions = new BacktestingTransactionHandler ();
            var systemHandlers = new LeanEngineSystemHandlers (_jobQueue, _api, _notify);
            systemHandlers.Initialize ();

            //			var algorithmHandlers = new LeanEngineAlgorithmHandlers (_resultshandler, _setup, _dataFeed, _transactions, _realTime, _historyProvider);
            Log.LogHandler = Composer.Instance.GetExportedValueByTypeName<ILogHandler>(Config.Get("log-handler", "CompositeLogHandler"));

            LeanEngineAlgorithmHandlers leanEngineAlgorithmHandlers;
            try
            {
                leanEngineAlgorithmHandlers = LeanEngineAlgorithmHandlers.FromConfiguration(Composer.Instance);
                _resultshandler = leanEngineAlgorithmHandlers.Results;
            }
            catch (CompositionException compositionException)
            {
                Log.Error("Engine.Main(): Failed to load library: " + compositionException);
                throw;
            }
            string algorithmPath;
            AlgorithmNodePacket job = systemHandlers.JobQueue.NextJob(out algorithmPath);
            try
            {
                var _engine = new Engine(systemHandlers, leanEngineAlgorithmHandlers, Config.GetBool("live-mode"));
                _engine.Run(job, algorithmPath);
            }
            finally
            {
                //Delete the message from the job queue:
                //systemHandlers.JobQueue.AcknowledgeJob(job);
                Log.Trace("Engine.Main(): Packet removed from queue: " + job.AlgorithmId);

                // clean up resources
                systemHandlers.Dispose();
                leanEngineAlgorithmHandlers.Dispose();
                Log.LogHandler.Dispose();
            }
        }