private IDataFeed RunDataFeed(IAlgorithm algorithm, out FuncDataQueueHandler dataQueueHandler, ITimeProvider timeProvider = null, Func <FuncDataQueueHandler, IEnumerable <BaseData> > getNextTicksFunction = null) { getNextTicksFunction = getNextTicksFunction ?? (fdqh => fdqh.Subscriptions.Select(symbol => new Tick(DateTime.Now, symbol, 1, 2) { Quantity = 1 })); // job is used to send into DataQueueHandler var job = new LiveNodePacket(); // result handler is used due to dependency in SubscriptionDataReader var resultHandler = new ConsoleResultHandler(); // new ResultHandlerStub(); dataQueueHandler = new FuncDataQueueHandler(getNextTicksFunction); var feed = new TestableLiveTradingDataFeed(dataQueueHandler, timeProvider); feed.Initialize(algorithm, job, resultHandler, new LocalDiskMapFileProvider()); var feedThreadStarted = new ManualResetEvent(false); Task.Factory.StartNew(() => { feedThreadStarted.Set(); feed.Run(); }); // wait for feed.Run to actually begin feedThreadStarted.WaitOne(); return(feed); }
/// <summary> /// Get an instance of the data feed handler we're requesting for this work. /// </summary> /// <param name="job">Algorithm Node Packet</param> /// <returns>Class Matching IResultHandler Inteface</returns> private static IResultHandler GetResultHandler(AlgorithmNodePacket job) { var rh = default(IResultHandler); if (IsLocal) { return(new ConsoleResultHandler(job)); } switch (job.ResultEndpoint) { //Local backtesting and live trading result handler route messages to the local console. case ResultHandlerEndpoint.Console: Log.Trace("Engine.GetResultHandler(): Selected Console Output."); rh = new ConsoleResultHandler((BacktestNodePacket)job); break; // Backtesting route messages to user browser. case ResultHandlerEndpoint.Backtesting: Log.Trace("Engine.GetResultHandler(): Selected Backtesting API Result Endpoint."); rh = new BacktestingResultHandler((BacktestNodePacket)job); break; // Live trading route messages to user's browser. case ResultHandlerEndpoint.LiveTrading: Log.Trace("Engine.GetResultHandler(): Selected Live Trading API Result Endpoint."); rh = new LiveTradingResultHandler((LiveNodePacket)job); break; } return(rh); }
private void CreateAndAddConsoleResultHandlerToEventAggregator(ILogger logger) { if (_consoleResultHandler == null) { _consoleResultHandler = new ConsoleResultHandler(logger); _eventSubscriptionManager.AddListener(_consoleResultHandler); } }
private static BenchmarkResultHandler CreateResultHandler(BenchmarkOptions options) { BenchmarkResultHandler handler = new ConsoleResultHandler(options.DisplayRawData); if (options.XmlFile != null) { var xmlHandler = new XmlResultHandler(options.XmlFile); handler = new CompositeResultHandler(new[] { handler, xmlHandler }); } return(handler); }
public void EmitsData() { var algorithm = new AlgorithmStub(forex: new List <string> { "EURUSD" }); // job is used to send into DataQueueHandler var job = new LiveNodePacket(); // result handler is used due to dependency in SubscriptionDataReader var resultHandler = new ConsoleResultHandler(); var lastTime = DateTime.MinValue; var timeProvider = new RealTimeProvider(); var dataQueueHandler = new FuncDataQueueHandler(fdqh => { var time = timeProvider.GetUtcNow().ConvertFromUtc(TimeZones.EasternStandard); if (time == lastTime) { return(Enumerable.Empty <BaseData>()); } lastTime = time; return(Enumerable.Range(0, 9).Select(x => new Tick(time.AddMilliseconds(x * 100), Symbols.EURUSD, 1.3m, 1.2m, 1.3m))); }); var feed = new TestableLiveTradingDataFeed(dataQueueHandler, timeProvider); var mapFileProvider = new LocalDiskMapFileProvider(); feed.Initialize(algorithm, job, resultHandler, mapFileProvider, new LocalDiskFactorFileProvider(mapFileProvider)); var feedThreadStarted = new ManualResetEvent(false); Task.Factory.StartNew(() => { feedThreadStarted.Set(); feed.Run(); }); // wait for feed.Run to actually begin feedThreadStarted.WaitOne(); var emittedData = false; ConsumeBridge(feed, TimeSpan.FromSeconds(10), true, ts => { if (ts.Slice.Count != 0) { emittedData = true; Console.WriteLine("HasData: " + ts.Slice.Bars[Symbols.EURUSD].EndTime); Console.WriteLine(); } }); Assert.IsTrue(emittedData); }
public decimal Run(ConfigVars vars) { foreach (KeyValuePair <string, object> kvp in vars.vars) { Config.Set(kvp.Key, kvp.Value.ToString()); } LaunchLean(); ConsoleResultHandler resultshandler = (ConsoleResultHandler)_resultshandler; var sharpe_ratio = 0.0m; var ratio = resultshandler.FinalStatistics ["Sharpe Ratio"]; Decimal.TryParse(ratio, out sharpe_ratio); return(sharpe_ratio); }
private static void Main() { var container = new Container(x => { x.Scan(s => { s.Assembly("StackWarden.Core"); s.Assembly("StackWarden.Monitoring"); s.LookForRegistries(); }); }); var monitorFactory = container.GetInstance <CompositeMonitorFactory>(); var monitors = monitorFactory.Build().ToArray(); #if DEBUG Console.WriteLine($"Configured {monitors.Count()} monitors."); Console.WriteLine(string.Join(Environment.NewLine, monitors.Select(x => x.Name))); var consoleResultHandler = new ConsoleResultHandler(); foreach (var currentMonitor in monitors) { currentMonitor.Updated += consoleResultHandler.Handle; currentMonitor.Start(); } Console.ReadKey(); foreach (var currentMonitor in monitors) { currentMonitor.Stop(); } #else var services = new ServiceBase[] { new StackWardenServerService(LogManager.GetLogger(typeof(StackWardenServerService)), monitors.ToArray()) }; ServiceBase.Run(services); #endif }
public ConsoleResultHandlerTests() { _loggerMock = new Mock <ILogger <ConsoleResultHandler> >(); _resultHandler = new ConsoleResultHandler(_loggerMock.Object); }