本文整理汇总了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);
}