Ejemplo n.º 1
0
        private void Start(StrategyContainer strategy, DateTime?startDate, DateTime?stopDate, TimeSpan?candlesTimeFrame, bool onlyInitialize)
        {
            if (Connector == null)
            {
                throw new InvalidOperationException("Connector=null");
            }

            strategy.CheckCanStart();

            var from = startDate ?? DateTime.Today.AddDays(-strategy.HistoryDaysCount);
            var to   = stopDate ?? DateTime.Now;

            var strategyConnector = new StrategyConnector(strategy, from, to, candlesTimeFrame ?? TimeSpan.FromMinutes(5), onlyInitialize);

            ConfigManager.GetService <LogManager>().Sources.Add(strategyConnector);

            strategy.Connector = strategyConnector;
            strategy.SetCandleManager(CreateCandleManager(strategyConnector, TimeSpan.FromDays((strategy.HistoryDaysCount + 1) * 2)));
            strategy.SetIsEmulation(false);

            strategyConnector.Connected += strategyConnector.StartExport;

            strategy.Start();
            strategyConnector.Connect();
        }
Ejemplo n.º 2
0
        private IEnumerable <Strategy> GetStrategies()
        {
            EmulationConnector.AddInfoLog(LocalizedStrings.Str3592);

            var enumerator = Strategies.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var strategy = (StrategyContainer)enumerator.Current;

                strategy.CheckCanStart();

                var container = new StrategyContainer
                {
                    Id                 = strategy.Id,
                    StrategyInfo       = _infoClone,
                    MarketDataSettings = strategy.MarketDataSettings,
                    Connector          = EmulationConnector,
                    //SessionType = SessionType.Optimization,
                };

                container.Environment.AddRange(strategy.Environment);

                container.SetCandleManager(CreateCandleManager());
                container.SetIsEmulation(true);
                container.SetIsInitialization(false);

                container.NameGenerator.Pattern = strategy.NameGenerator.Pattern;
                container.Portfolio             = strategy.Portfolio;
                container.Security = strategy.Security;
                container.Strategy = strategy;

                container.UnrealizedPnLInterval = EmulationSettings.UnrealizedPnLInterval ?? ((EmulationSettings.StopTime - EmulationSettings.StartTime).Ticks / 1000).To <TimeSpan>();

                _infoClone.Strategies.Add(container);

                yield return(container);
            }

            EmulationConnector.AddInfoLog(LocalizedStrings.Str3593);
        }