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


C# Strategy.AddStrategy方法代码示例

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


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

示例1: Run

        public override void Run()
        {
            // Prepare running.
            Console.WriteLine("Prepare running in {0} mode...", StrategyManager.Mode);

            // Get spread instrument.
            Instrument spreadInsturment = InstrumentManager.Get("AAPL vs MSFT");

            // Add spread instrument if needed.
            if (spreadInsturment == null)
            {
                spreadInsturment = new Instrument(InstrumentType.Stock, "AAPL vs MSFT");
                InstrumentManager.Add(spreadInsturment);
            }

            // Add legs for spread instrument if needed.
            if (spreadInsturment.Legs.Count == 0)
            {
                spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("AAPL"), 1));
                spreadInsturment.Legs.Add(new Leg(InstrumentManager.Get("MSFT"), -1));
            }

            // Main strategy.
            strategy = new Strategy(framework, "SpreadTrading");

            // Create BuySide strategy and add trading instrument.
            MyStrategy buySide = new MyStrategy(framework, "BuySide");
            buySide.Instruments.Add(spreadInsturment);

            // Create SellSide strategy.
            SpreadSellSide sellSide = new SpreadSellSide(framework, "SellSide");
            sellSide.Global[SpreadSellSide.barSizeCode] = barSize;

            // Set SellSide as data and execution provider for BuySide strategy.
            buySide.DataProvider = sellSide;
            buySide.ExecutionProvider = sellSide;

            // Add strategies to main.
            strategy.AddStrategy(buySide);
            strategy.AddStrategy(sellSide);

            // Get provider for realtime.
            Provider quantRouter = ProviderManager.Providers["QuantRouter"] as Provider;

            if (quantRouter.Status == ProviderStatus.Disconnected)
                quantRouter.Connect();

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

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

            // Add 1 minute bars (60 seconds) for spread instrument.
            BarFactory.Add(spreadInsturment, BarType.Time, barSize);

            // Run.
            Console.WriteLine("Run in {0} mode.", StrategyManager.Mode);
            StartStrategy(StrategyManager.Mode);
        }
开发者ID:fastquant,项目名称:fastquant.dll,代码行数:69,代码来源:Program.cs


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