当前位置: 首页>>代码示例>>C#>>正文


C# Strategy.EmitStrategyStart方法代码示例

本文整理汇总了C#中Strategy.EmitStrategyStart方法的典型用法代码示例。如果您正苦于以下问题:C# Strategy.EmitStrategyStart方法的具体用法?C# Strategy.EmitStrategyStart怎么用?C# Strategy.EmitStrategyStart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Strategy的用法示例。


在下文中一共展示了Strategy.EmitStrategyStart方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartStrategy

        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;
                }
            }
        }
开发者ID:,项目名称:,代码行数:91,代码来源:


注:本文中的Strategy.EmitStrategyStart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。