Ejemplo n.º 1
0
 protected void Start(StrategyMode mode)
 {
     if (this.StartRequested != null)
     {
         this.StartRequested(mode, EventArgs.Empty);
     }
 }
Ejemplo n.º 2
0
		protected void Start(StrategyMode mode)
		{
			if (this.StartRequested != null)
			{
				this.StartRequested(mode, EventArgs.Empty);
			}
		}
Ejemplo n.º 3
0
        protected void AddOrUpdateValueRules(IEnumerable <CorrectValueRule> rules, StrategyMode mode)
        {
            lock (_valueRuleLockObj)
            {
                if (mode == StrategyMode.OverallOverwrite)
                {
                    _correctValueRules.Clear();
                }

                foreach (var rule in rules)
                {
                    var target = _correctValueRules.FirstOrDefault(r => r.Name == rule.Name);

                    if (target is null)
                    {
                        // If the value of StrategyMode is OverallOverwrite,
                        // this branch must be entered.
                        _correctValueRules.Add(rule);
                    }

                    else if (mode == StrategyMode.ItemOverwrite)
                    {
                        _correctValueRules.Remove(target);
                        _correctValueRules.Add(rule);
                    }

                    else if (mode == StrategyMode.Append)
                    {
                        target.Merge(rule);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public LoggerFactory(StrategyMode strategyMode, string logConfigFileName, RollingInterval rollingInterval)
        {
            var config = ReadConfig(GetConfigPath(), logConfigFileName);

            this._logConfig       = JsonConvert.DeserializeObject <LogConfiguration>(config);
            this._logPath         = GetLogPath(strategyMode, this._logConfig);
            this._rollingInterval = rollingInterval;
        }
Ejemplo n.º 5
0
        public ILeoValidationContext SetStrategy <TStrategy>(StrategyMode mode = StrategyMode.OverallOverwrite)
            where TStrategy : class, ILeoValidationStrategy, new()
        {
            var rel = (ICorrectStrategy) new TStrategy();

            AddOrUpdateValueRules(rel.GetValueRuleBuilders().Select(builder => builder.Build()), mode);
            return(this);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Starts the solution associated with the scenario in the specific mode
 /// </summary>
 /// <param name="mode">Mode.</param>
 protected void Start(StrategyMode mode)
 {
     if (this.StartRequested == null)
     {
         return;
     }
     this.StartRequested((object)mode, EventArgs.Empty);
 }
Ejemplo n.º 7
0
        public IFluentValidationRegistrar AndForStrategy <TStrategy, T>(string name, StrategyMode mode = StrategyMode.OverallOverwrite)
            where TStrategy : class, IValidationStrategy <T>, new()
        {
            //step 1: build this register
            BuildMySelf();

            //step 2: create a new register
            return(_parentRegistrar.AndForStrategy <TStrategy, T>(name, mode));
        }
 public IValidationEntry SetStrategy <TStrategy>(TStrategy strategy, StrategyMode mode = StrategyMode.OverallOverwrite) where TStrategy : class, IValidationStrategy, new()
 {
     if (strategy is null)
     {
         throw new ArgumentNullException(nameof(strategy));
     }
     CorrectRuleChain.RegisterStrategy(strategy, mode);
     _needToBuild = true;
     return(this);
 }
Ejemplo n.º 9
0
 public void StartStrategy(StrategyMode mode)
 {
     Console.WriteLine(DateTime.Now + " Scenario::StartStrategy " + mode);
     this.framework.strategyManager.StartStrategy(this.strategy, mode);
     while (this.strategy.Status != StrategyStatus.Stopped)
     {
         Thread.Sleep(10);
     }
     Console.WriteLine(DateTime.Now + " Scenario::StartStrategy Done");
 }
Ejemplo n.º 10
0
 public void Start(Strategy strategy, StrategyMode mode)
 {
     Console.WriteLine($"{DateTime.Now} Scenario::StartStrategy {strategy.Name} in {mode}");
     this.framework.ExperimentalStrategyManager.Start(strategy, mode);
     while (this.framework.ExperimentalStrategyManager.Status != StrategyStatus.Stopped)
     {
         Thread.Sleep(10);
     }
     Console.WriteLine($"{DateTime.Now} Scenario::StartStrategy Done");
 }
Ejemplo n.º 11
0
        public LoggerFactory(StrategyMode strategyMode, LogConfiguration logConfig, RollingInterval rollingInterval, string identifierPlaceHolder, string searchStringTemplate, List <string> indentifierValues)
        {
            this._logConfig       = logConfig;
            this._logPath         = GetLogPath(strategyMode, logConfig);
            this._rollingInterval = rollingInterval;

            this._identifierPlaceHolder = identifierPlaceHolder;
            this._searchStringTemplate  = searchStringTemplate;
            this._indentifierValues     = indentifierValues;
        }
        public IFluentValidationRegistrar AndForStrategy <TStrategy>(StrategyMode mode = StrategyMode.OverallOverwrite)
            where TStrategy : class, IValidationStrategy, new()
        {
            //step 1: build this register
            BuildMySelf();

            //step 2: create a new register
            _parentRegistrar.ForStrategy <TStrategy>(mode);
            return(this);
        }
Ejemplo n.º 13
0
        public LoggerFactory(StrategyMode strategyMode, string logConfigFileName, RollingInterval rollingInterval, string identifierPlaceHolder, string searchStringTemplate, List <string> indentifierValues)
        {
            var config = ReadConfig(GetConfigPath(), logConfigFileName);

            this._logConfig       = JsonConvert.DeserializeObject <LogConfiguration>(config);
            this._logPath         = GetLogPath(strategyMode, this._logConfig);
            this._rollingInterval = rollingInterval;

            this._identifierPlaceHolder = identifierPlaceHolder;
            this._searchStringTemplate  = searchStringTemplate;
            this._indentifierValues     = indentifierValues;
        }
Ejemplo n.º 14
0
        public ILeoValidationContext SetStrategy <TStrategy>(TStrategy strategy, StrategyMode mode = StrategyMode.OverallOverwrite)
            where TStrategy : class, ILeoValidationStrategy, new()
        {
            if (strategy is null)
            {
                throw new ArgumentNullException(nameof(strategy));
            }
            var rel = (ICorrectStrategy)strategy;

            AddOrUpdateValueRules(rel.GetValueRuleBuilders().Select(builder => builder.Build()), mode);
            return(this);
        }
Ejemplo n.º 15
0
        private void StartStrategy(Strategy strategy, StrategyMode mode)
        {
            Console.WriteLine($"{DateTime.Now} Scenario::StartStrategy {mode}");
            this.framework.StrategyManager.StartStrategy(strategy, mode);

            // Wait for completion
            while (strategy.Status != StrategyStatus.Stopped)
            {
                Thread.Sleep(10);
            }

            Console.WriteLine($"{DateTime.Now} Scenario::StartStrategy Done");
        }
Ejemplo n.º 16
0
        private void OnStrategyModeChanged(object sender, EventArgs e)
        {
            var      combo = sender as ComboBox;
            TreeIter iter;

            if (!combo.GetActiveIter(out iter))
            {
                return;
            }

            string       val  = (string)combo.Model.GetValue(iter, 0);
            StrategyMode mode = StrategyMode.Backtest;

            if (val == "Paper")
            {
                mode = StrategyMode.Paper;
            }
            else if (val == "Live")
            {
                mode = StrategyMode.Live;
            }

            var f = Framework.Current;

            if (f.StrategyManager.Mode == mode)
            {
                return;
            }
            if (f.Mode == FrameworkMode.Simulation)
            {
                if (mode != StrategyMode.Backtest)
                {
                    Console.WriteLine(string.Format("{0} Framework::Clear Mode changed", DateTime.Now));
                    f.Clear();
                }
            }
            else if (mode == StrategyMode.Backtest)
            {
                Console.WriteLine(string.Format("{0} Framework::Clear Mode changed", DateTime.Now));
                f.Clear();
            }
            f.StrategyManager.Mode = mode;
        }
Ejemplo n.º 17
0
        public void Start(Strategy strategy, StrategyMode mode)
        {
            if (this.Status != StrategyStatus.Running)
            {
                this.strategy__0 = strategy;
                this.Mode        = mode;
                this.method_39(StrategyStatusType.Started);
                this.method_40();
                if (this.Persistence != StrategyPersistence.Full)
                {
                    if (this.Persistence != StrategyPersistence.Save)
                    {
                        this.framework.orderManager_0.bool_0 = false;
                        goto IL_74;
                    }
                }
                this.framework.orderServer_0.SeriesName = strategy.Name;
                this.framework.orderManager_0.bool_0    = true;
IL_74:
                if (this.Persistence == StrategyPersistence.Full || this.Persistence == StrategyPersistence.Load)
                {
                    this.framework.portfolioManager_0.Load(strategy.Name);
                    this.framework.orderManager_0.Load(strategy.Name, -1);
                }
                this.Status = StrategyStatus.Running;
                if (mode == StrategyMode.Backtest && !this.framework.bool_6)
                {
                    this.framework.providerManager_0.idataSimulator_0.RunOnSubscribe = false;
                }
                strategy.icojrGfcqNm();
                if ((this.Persistence == StrategyPersistence.Full || this.Persistence == StrategyPersistence.Save) && !strategy.Portfolio.iEcAijqtwI)
                {
                    this.framework.portfolioManager_0.Save(strategy.Portfolio);
                }
                strategy.vmethod_0(mode);
                if (mode == StrategyMode.Backtest && !this.framework.bool_6)
                {
                    this.framework.providerManager_0.idataSimulator_0.Run();
                    this.framework.providerManager_0.idataSimulator_0.RunOnSubscribe = true;
                }
            }
        }
Ejemplo n.º 18
0
        public override void Run()
        {
            StrategyMode sm = StrategyMode.Backtest;


            bool isTest = false;

            if (isTest)
            {
                Instrument instrument1 = InstrumentManager.Instruments["AAPL"];
                Instrument instrument2 = InstrumentManager.Instruments["MSFT"];
                strategy = new Strategy_BB(framework, "BollingerBands");
                sm       = StrategyMode.Backtest;
                strategy.AddInstrument(instrument1);
                strategy.AddInstrument(instrument2);
                DataSimulator.DateTime1 = new DateTime(2013, 01, 01);
                DataSimulator.DateTime2 = new DateTime(2013, 12, 31);
                BarFactory.Add(instrument1, BarType.Time, barSize);
                BarFactory.Add(instrument2, BarType.Time, barSize);
            }
            else
            {
                IDataProvider      dataProvider      = null;
                IExecutionProvider executionProvider = null;
                OQFunc.UserInputProviderId(out dataProvider, out executionProvider, this.ProviderManager);

                Instrument instrument3 = OQFunc.UserInputInstrument(this.InstrumentManager);

                strategy = new Strategy_BB(framework, "BollingerBands");
                sm       = StrategyMode.Live;
                strategy.DataProvider      = dataProvider;
                strategy.ExecutionProvider = executionProvider;
                strategy.AddInstrument(instrument3);
            }


            StartStrategy(sm);
        }
 /// <summary>
 /// Use a strategy <br />
 /// 使用一条策略
 /// </summary>
 /// <param name="strategy"></param>
 /// <param name="name"></param>
 /// <param name="mode"></param>
 public void ForStrategy(IValidationStrategy strategy, string name, StrategyMode mode = StrategyMode.OverallOverwrite)
 {
     Registrar.ForStrategy(strategy, name, mode).TakeEffect();
 }
Ejemplo n.º 20
0
        public IFluentValidationRegistrar AndForStrategy(IValidationStrategy strategy, string name, StrategyMode mode = StrategyMode.OverallOverwrite)
        {
            //step 1: build this register
            BuildMySelf();

            //step 2: create a new register
            return(_parentRegistrar.AndForStrategy(strategy, name, mode));
        }
Ejemplo n.º 21
0
        public void StartStrategy(Strategy strategy, StrategyMode mode)
        {
            lock (this)
            {
                this.subscriptions.Clear();
                Strategy = strategy;
                Mode = mode;
                if (this.framework.Mode == FrameworkMode.Simulation)
                {
                    this.framework.Clock.DateTime = this.framework.ProviderManager.DataSimulator.DateTime1;
                    this.framework.ExchangeClock.DateTime = DateTime.MinValue;
                }
                if (this.framework.EventManager.Status != EventManagerStatus.Running)
                    this.framework.EventManager.Start();

                SetStatusType(StrategyStatusType.Started);
                if (Persistence == StrategyPersistence.Full || Persistence == StrategyPersistence.Load)
                {
                    this.framework.PortfolioManager.Load(strategy.Name);
                    this.framework.OrderManager.Load(strategy.Name, -1);
                    this.framework.OrderServer.SeriesName = strategy.Name;
                    this.framework.OrderManager.IsPersistent = true;
                }
                else
                {
                    this.framework.OrderManager.IsPersistent = false;
                }

                strategy.Init();

                if ((Persistence == StrategyPersistence.Full || Persistence == StrategyPersistence.Save) && !strategy.Portfolio.IsLoaded)
                    this.framework.PortfolioManager.Save(strategy.Portfolio);
              
                strategy.EmitStrategyStart();

                if (!this.framework.IsExternalDataQueue)
                {
                    var dictionary = new Dictionary<IDataProvider, InstrumentList>();
                    while (this.subscriptions.Count != 0)
                    {
                        var dictionary2 = new Dictionary<IDataProvider, InstrumentList>(this.subscriptions);
                        this.subscriptions.Clear();
                        foreach (var current in dictionary2)
                        {
                            InstrumentList instrumentList = null;
                            if (!dictionary.TryGetValue(current.Key, out instrumentList))
                            {
                                instrumentList = new InstrumentList();
                                dictionary[current.Key] = instrumentList;
                            }
                            InstrumentList instrumentList2 = new InstrumentList();
                            foreach (Instrument current2 in current.Value)
                            {
                                if (!instrumentList.Contains(current2))
                                {
                                    instrumentList.Add(current2);
                                    instrumentList2.Add(current2);
                                }
                            }
                            if (current.Key is SellSideStrategy)
                            {
                                this.framework.SubscriptionManager?.Subscribe(current.Key, instrumentList2);
                            }
                        }
                    }
                    SetParametersGroup();
                    Status = StrategyStatus.Running;
                    this.subscriptions = dictionary;
                    if (this.subscriptions.Count == 0 && mode == StrategyMode.Backtest)
                    {
                        Console.WriteLine($"{DateTime.Now } StrategyManager::StartStrategy {strategy.Name} has no data requests in backtest mode, stopping...");
                        StopStrategy();
                    }
                    else
                    {
                        foreach (var current3 in this.subscriptions)
                        {
                            if (!(current3.Key is SellSideStrategy))
                                this.framework.SubscriptionManager?.Subscribe(current3.Key, current3.Value);
                        }
                        if (mode != StrategyMode.Backtest)
                            strategy.FundamentalProvider?.Connect();
                    }
                }
                else
                {
                    SetParametersGroup();
                    Status = StrategyStatus.Running;
                }
            }
        }
Ejemplo n.º 22
0
 public void Start(Strategy strategy, StrategyMode mode)
 {
     if (this.Status != StrategyStatus.Running)
     {
         this.strategy__0 = strategy;
         this.Mode = mode;
         this.method_39(StrategyStatusType.Started);
         this.method_40();
         if (this.Persistence != StrategyPersistence.Full)
         {
             if (this.Persistence != StrategyPersistence.Save)
             {
                 this.framework.orderManager_0.bool_0 = false;
                 goto IL_74;
             }
         }
         this.framework.orderServer_0.SeriesName = strategy.Name;
         this.framework.orderManager_0.bool_0 = true;
         IL_74:
         if (this.Persistence == StrategyPersistence.Full || this.Persistence == StrategyPersistence.Load)
         {
             this.framework.portfolioManager_0.Load(strategy.Name);
             this.framework.orderManager_0.Load(strategy.Name, -1);
         }
         this.Status = StrategyStatus.Running;
         if (mode == StrategyMode.Backtest && !this.framework.bool_6)
         {
             this.framework.providerManager_0.idataSimulator_0.RunOnSubscribe = false;
         }
         strategy.icojrGfcqNm();
         if ((this.Persistence == StrategyPersistence.Full || this.Persistence == StrategyPersistence.Save) && !strategy.Portfolio.iEcAijqtwI)
         {
             this.framework.portfolioManager_0.Save(strategy.Portfolio);
         }
         strategy.vmethod_0(mode);
         if (mode == StrategyMode.Backtest && !this.framework.bool_6)
         {
             this.framework.providerManager_0.idataSimulator_0.Run();
             this.framework.providerManager_0.idataSimulator_0.RunOnSubscribe = true;
         }
     }
 }
Ejemplo n.º 23
0
        public void StartStrategy(Strategy strategy, StrategyMode mode)
        {
            lock (this)
            {
                this.subscriptions.Clear();
                Strategy = strategy;
                Mode     = mode;
                if (this.framework.Mode == FrameworkMode.Simulation)
                {
                    this.framework.Clock.DateTime         = this.framework.ProviderManager.DataSimulator.DateTime1;
                    this.framework.ExchangeClock.DateTime = DateTime.MinValue;
                }
                if (this.framework.EventManager.Status != EventManagerStatus.Running)
                {
                    this.framework.EventManager.Start();
                }

                SetStatusType(StrategyStatusType.Started);
                if (Persistence == StrategyPersistence.Full || Persistence == StrategyPersistence.Load)
                {
                    this.framework.PortfolioManager.Load(strategy.Name);
                    this.framework.OrderManager.Load(strategy.Name, -1);
                    this.framework.OrderServer.SeriesName    = strategy.Name;
                    this.framework.OrderManager.IsPersistent = true;
                }
                else
                {
                    this.framework.OrderManager.IsPersistent = false;
                }

                strategy.Init();

                if ((Persistence == StrategyPersistence.Full || Persistence == StrategyPersistence.Save) && !strategy.Portfolio.IsLoaded)
                {
                    this.framework.PortfolioManager.Save(strategy.Portfolio);
                }

                strategy.EmitStrategyStart();

                if (!this.framework.IsExternalDataQueue)
                {
                    var dictionary = new Dictionary <IDataProvider, InstrumentList>();
                    while (this.subscriptions.Count != 0)
                    {
                        var dictionary2 = new Dictionary <IDataProvider, InstrumentList>(this.subscriptions);
                        this.subscriptions.Clear();
                        foreach (var current in dictionary2)
                        {
                            InstrumentList instrumentList = null;
                            if (!dictionary.TryGetValue(current.Key, out instrumentList))
                            {
                                instrumentList          = new InstrumentList();
                                dictionary[current.Key] = instrumentList;
                            }
                            InstrumentList instrumentList2 = new InstrumentList();
                            foreach (Instrument current2 in current.Value)
                            {
                                if (!instrumentList.Contains(current2))
                                {
                                    instrumentList.Add(current2);
                                    instrumentList2.Add(current2);
                                }
                            }
                            if (current.Key is SellSideStrategy)
                            {
                                this.framework.SubscriptionManager?.Subscribe(current.Key, instrumentList2);
                            }
                        }
                    }
                    SetParametersGroup();
                    Status             = StrategyStatus.Running;
                    this.subscriptions = dictionary;
                    if (this.subscriptions.Count == 0 && mode == StrategyMode.Backtest)
                    {
                        Console.WriteLine($"{DateTime.Now } StrategyManager::StartStrategy {strategy.Name} has no data requests in backtest mode, stopping...");
                        StopStrategy();
                    }
                    else
                    {
                        foreach (var current3 in this.subscriptions)
                        {
                            if (!(current3.Key is SellSideStrategy))
                            {
                                this.framework.SubscriptionManager?.Subscribe(current3.Key, current3.Value);
                            }
                        }
                        if (mode != StrategyMode.Backtest)
                        {
                            strategy.FundamentalProvider?.Connect();
                        }
                    }
                }
                else
                {
                    SetParametersGroup();
                    Status = StrategyStatus.Running;
                }
            }
        }
Ejemplo n.º 24
0
        private string GetLogPath(StrategyMode strategyMode, LogConfiguration logConfig)
        {
            var logFile = strategyMode == StrategyMode.Live ? logConfig.LiveTradingLogFile :logConfig.BacktestLogFile;

            return(Path.Combine(logConfig.Path, logFile));
        }
 /// <summary>
 /// Use a strategy <br />
 /// 使用一条策略
 /// </summary>
 /// <param name="name"></param>
 /// <param name="mode"></param>
 /// <typeparam name="TStrategy"></typeparam>
 /// <typeparam name="T"></typeparam>
 public void ForStrategy <TStrategy, T>(string name, StrategyMode mode = StrategyMode.OverallOverwrite) where TStrategy : class, IValidationStrategy <T>, new()
 {
     Registrar.ForStrategy <TStrategy, T>(name, mode).TakeEffect();
 }
 /// <summary>
 /// Use a strategy <br />
 /// 使用一条策略
 /// </summary>
 /// <param name="strategy"></param>
 /// <param name="mode"></param>
 /// <typeparam name="T"></typeparam>
 public void ForStrategy <T>(IValidationStrategy <T> strategy, StrategyMode mode = StrategyMode.OverallOverwrite)
 {
     Registrar.ForStrategy(strategy, mode).TakeEffect();
 }
Ejemplo n.º 27
0
        public void StartStrategy(Strategy strategy, StrategyMode mode)
        {
            this.strategy = strategy;
            if (mode == StrategyMode.Backtest)
            {
                this.framework.Mode = FrameworkMode.Simulation;
            }
            else
            {
                this.framework.Mode = FrameworkMode.Realtime;
            }
            if (this.framework.eventManager.status != EventManagerStatus.Running)
            {
                this.framework.eventManager.Start();
            }
            StrategyStatusInfo strategyStatusInfo = new StrategyStatusInfo(this.framework.clock.DateTime, StrategyStatusType.Started);

            strategyStatusInfo.Solution = ((strategy.Name == null) ? "Solution" : strategy.Name);
            strategyStatusInfo.Mode     = mode.ToString();
            this.framework.eventServer.OnLog(new GroupEvent(strategyStatusInfo, null));
            strategy.OnStrategyStart_();
            if (!this.framework.IsExternalDataQueue)
            {
                Dictionary <IDataProvider, InstrumentList> dictionary = new Dictionary <IDataProvider, InstrumentList>();
                while (this.requests.Count != 0)
                {
                    Dictionary <IDataProvider, InstrumentList> dictionary2 = new Dictionary <IDataProvider, InstrumentList>(this.requests);
                    this.requests.Clear();
                    foreach (KeyValuePair <IDataProvider, InstrumentList> current in new Dictionary <IDataProvider, InstrumentList>(dictionary2))
                    {
                        InstrumentList instrumentList = null;
                        if (!dictionary.TryGetValue(current.Key, out instrumentList))
                        {
                            instrumentList          = new InstrumentList();
                            dictionary[current.Key] = instrumentList;
                        }
                        InstrumentList instrumentList2 = new InstrumentList();
                        foreach (Instrument current2 in current.Value)
                        {
                            if (!instrumentList.Contains(current2))
                            {
                                instrumentList.Add(current2);
                                instrumentList2.Add(current2);
                            }
                        }
                        if (current.Key is SellSideStrategy && this.framework.SubscriptionManager != null)
                        {
                            this.framework.SubscriptionManager.Subscribe(current.Key, instrumentList2);
                        }
                    }
                }
                this.status   = StrategyStatus.Running;
                this.requests = dictionary;
                if (this.requests.Count == 0)
                {
                    Console.WriteLine(string.Concat(new object[]
                    {
                        DateTime.Now,
                        " StrategyManager::StartStrategy ",
                        strategy.Name,
                        " has no data requests, stopping..."
                    }));
                    this.StopStrategy();
                    return;
                }
                foreach (KeyValuePair <IDataProvider, InstrumentList> current3 in this.requests)
                {
                    if (!(current3.Key is SellSideStrategy) && this.framework.SubscriptionManager != null)
                    {
                        this.framework.SubscriptionManager.Subscribe(current3.Key, current3.Value);
                    }
                }
            }
        }
Ejemplo n.º 28
0
		/// <summary>
		/// Starts the solution associated with the scenario in the specific mode
		/// </summary>
		/// <param name="mode">Mode.</param>
		protected void Start(StrategyMode mode)
		{
			if (this.StartRequested == null)
				return;
			this.StartRequested((object)mode, EventArgs.Empty);
		}
Ejemplo n.º 29
0
 internal virtual void vmethod_0(StrategyMode mode)
 {
     this.Status = StrategyStatus.Running;
     this.Mode = mode;
     this.method_9();
     if (this.IsInstance)
     {
         this.OnStrategyStart();
     }
     for (int i = 0; i < this.Strategies.Count; i++)
     {
         this.Strategies[i].vmethod_0(mode);
     }
 }
 public IFluentValidationRegistrar AndForStrategy <TType>(IValidationStrategy <TType> strategy, string name, StrategyMode mode = StrategyMode.OverallOverwrite)
 {
     return(WithMessage(string.Empty).AndForStrategy(strategy, name, mode));
 }
Ejemplo n.º 31
0
 public void StartStrategy(StrategyMode mode) => StartStrategy(Strategy, mode);
Ejemplo n.º 32
0
 public void StartStrategy(StrategyMode mode)
 {
     Console.WriteLine(DateTime.Now + " Scenario::StartStrategy " + mode);
     this.framework.strategyManager.StartStrategy(this.strategy, mode);
     while (this.strategy.Status != StrategyStatus.Stopped)
     {
         Thread.Sleep(10);
     }
     Console.WriteLine(DateTime.Now + " Scenario::StartStrategy Done");
 }
 /// <summary>
 /// Use a strategy <br />
 /// 使用一条策略
 /// </summary>
 /// <param name="mode"></param>
 /// <typeparam name="TStrategy"></typeparam>
 public void ForStrategy <TStrategy>(StrategyMode mode = StrategyMode.OverallOverwrite) where TStrategy : class, IValidationStrategy, new()
 {
     Registrar.ForStrategy <TStrategy>(mode).TakeEffect();
 }
Ejemplo n.º 34
0
 public void StartStrategy(Strategy strategy, StrategyMode mode)
 {
     this.strategy = strategy;
     if (mode == StrategyMode.Backtest)
     {
         this.framework.Mode = FrameworkMode.Simulation;
     }
     else
     {
         this.framework.Mode = FrameworkMode.Realtime;
     }
     if (this.framework.eventManager.status != EventManagerStatus.Running)
     {
         this.framework.eventManager.Start();
     }
     StrategyStatusInfo strategyStatusInfo = new StrategyStatusInfo(this.framework.clock.DateTime, StrategyStatusType.Started);
     strategyStatusInfo.Solution = ((strategy.Name == null) ? "Solution" : strategy.Name);
     strategyStatusInfo.Mode = mode.ToString();
     this.framework.eventServer.OnLog(new GroupEvent(strategyStatusInfo, null));
     strategy.OnStrategyStart_();
     if (!this.framework.IsExternalDataQueue)
     {
         Dictionary<IDataProvider, InstrumentList> dictionary = new Dictionary<IDataProvider, InstrumentList>();
         while (this.requests.Count != 0)
         {
             Dictionary<IDataProvider, InstrumentList> dictionary2 = new Dictionary<IDataProvider, InstrumentList>(this.requests);
             this.requests.Clear();
             foreach (KeyValuePair<IDataProvider, InstrumentList> current in new Dictionary<IDataProvider, InstrumentList>(dictionary2))
             {
                 InstrumentList instrumentList = null;
                 if (!dictionary.TryGetValue(current.Key, out instrumentList))
                 {
                     instrumentList = new InstrumentList();
                     dictionary[current.Key] = instrumentList;
                 }
                 InstrumentList instrumentList2 = new InstrumentList();
                 foreach (Instrument current2 in current.Value)
                 {
                     if (!instrumentList.Contains(current2))
                     {
                         instrumentList.Add(current2);
                         instrumentList2.Add(current2);
                     }
                 }
                 if (current.Key is SellSideStrategy && this.framework.SubscriptionManager != null)
                 {
                     this.framework.SubscriptionManager.Subscribe(current.Key, instrumentList2);
                 }
             }
         }
         this.status = StrategyStatus.Running;
         this.requests = dictionary;
         if (this.requests.Count == 0)
         {
             Console.WriteLine(string.Concat(new object[]
             {
                 DateTime.Now,
                 " StrategyManager::StartStrategy ",
                 strategy.Name,
                 " has no data requests, stopping..."
             }));
             this.StopStrategy();
             return;
         }
         foreach (KeyValuePair<IDataProvider, InstrumentList> current3 in this.requests)
         {
             if (!(current3.Key is SellSideStrategy) && this.framework.SubscriptionManager != null)
             {
                 this.framework.SubscriptionManager.Subscribe(current3.Key, current3.Value);
             }
         }
     }
 }
Ejemplo n.º 35
0
        private void StartStrategy(Strategy strategy, StrategyMode mode)
        {
            Console.WriteLine($"{DateTime.Now} Scenario::StartStrategy {mode}");
            this.framework.StrategyManager.StartStrategy(strategy, mode);

            // Wait for completion
            while (strategy.Status != StrategyStatus.Stopped)
                Thread.Sleep(10);

            Console.WriteLine($"{DateTime.Now} Scenario::StartStrategy Done");
        }
Ejemplo n.º 36
0
        public override void Run()
        {
            // Prepare running.
            Console.WriteLine("Prepare running in {0} mode...", framework.StrategyManager.Mode);

            // Get trading instruments.
            Instrument ins1 = InstrumentManager.Instruments["IF1612"];

            // Create SMA Crossover with Loading data on start strategy.
            // and add trading instruments.
            DoubleMA_Crossover smaCrossoverLOS = new DoubleMA_Crossover(framework, "SMACrossoverLOS");

            smaCrossoverLOS.Instruments.Add(ins1);

            // Set strategy as main.
            strategy = smaCrossoverLOS;

            Console.WriteLine("Prepare running in {0} mode...", framework.StrategyManager.Mode);

            // 开始时间是前一个交易日,这个地方要按自己策略的实际情况进行调整
            DateTime startDate = DateTime.Now.DayOfWeek == DayOfWeek.Monday ? DateTime.Now.AddDays(-3).Date : DateTime.Now.AddDays(-1).Date;
            DateTime historicalData1EndTime = startDate;

            // 取本地的数据的最后时间
            DataSeries ins1DataSeries = framework.DataManager.GetDataSeries(ins1, DataObjectType.Trade);

            if (ins1DataSeries != null && ins1DataSeries.Count > 0)
            {
                historicalData1EndTime = ins1DataSeries.DateTime2;
            }

            // 以两个时间的最大值为起点
            historicalData1EndTime = new DateTime(Math.Max(historicalData1EndTime.Ticks, startDate.Ticks));


            // Load and save historical trades from QuantBase provider.
            IHistoricalDataProvider quantBase = framework.ProviderManager.GetHistoricalDataProvider(94);

            if (quantBase.Status == ProviderStatus.Disconnected)
            {
                quantBase.Connect();
            }
            // 等待连接成功,订阅太快了不行
            while (!quantBase.IsConnected)
            {
                Thread.Sleep(1000);
            }


            // Load historical trades.
            Console.WriteLine("Load historical data.");
            TickSeries ins1TickSeries = framework.DataManager.GetHistoricalTrades(quantBase, ins1, historicalData1EndTime, DateTime.Now);

            Console.WriteLine("Save historical data.");
            // Save historical trades.
            foreach (Trade trade in ins1TickSeries)
            {
                framework.DataManager.Save(ins1, trade);
            }

            // Set DataSimulator's dates.
            DataSimulator.DateTime1 = startDate;
            DataSimulator.DateTime2 = DateTime.Now;

            // Set null for event filter.
            framework.EventManager.Filter = null;

            // Set property for suspend trading during simulation.
            DoubleMA_Crossover.SuspendTrading = true;

            // Add 5 minute bars (300 seconds) for trading instruments.
            BarFactory.Add(ins1, SmartQuant.BarType.Time, barSize);

            // Run in simulation.
            Console.WriteLine("Run in Backtest mode.");

            // Save current strategy mode.
            StrategyMode mode = framework.StrategyManager.Mode;

            // Set backtest mode.
            framework.StrategyManager.Mode = StrategyMode.Backtest;

            StartStrategy(StrategyMode.Backtest);

            // Run.
            Console.WriteLine("Run in {0} mode.", framework.StrategyManager.Mode);



            // Restore strategy mode.
            framework.StrategyManager.Mode = mode;

            // Get provider for realtime.
            Provider quantRouter = framework.ProviderManager.GetProvider(99) as Provider;

            if (quantRouter.Status == ProviderStatus.Disconnected)
            {
                quantRouter.Connect();
            }
            while (!quantRouter.IsConnected)
            {
                Thread.Sleep(1000);
            }

            // Set property for trading.
            DoubleMA_Crossover.SuspendTrading = false;

            if (framework.StrategyManager.Mode == StrategyMode.Paper)
            {
                // Set QuantRouter as data provider.
                strategy.DataProvider = quantRouter as IDataProvider;
            }
            else if (framework.StrategyManager.Mode == StrategyMode.Live)
            {
                // Set QuantRouter as data and execution provider.
                strategy.DataProvider      = quantRouter as IDataProvider;
                strategy.ExecutionProvider = quantRouter as IExecutionProvider;
            }


            StartStrategy(framework.StrategyManager.Mode);
        }
Ejemplo n.º 37
0
 public LoggerFactory(StrategyMode strategyMode, LogConfiguration logConfig, RollingInterval rollingInterval)
 {
     this._logConfig       = logConfig;
     this._logPath         = GetLogPath(strategyMode, logConfig);
     this._rollingInterval = rollingInterval;
 }
 public IFluentValidationRegistrar AndForStrategy <TStrategy, TType>(string name, StrategyMode mode = StrategyMode.OverallOverwrite)
     where TStrategy : class, IValidationStrategy <TType>, new()
 {
     return(WithMessage(string.Empty).AndForStrategy <TStrategy, TType>(name, mode));
 }
Ejemplo n.º 39
0
 public void StartStrategy(StrategyMode mode) => StartStrategy(Strategy, mode);